|
| 1 | +name: NumPyMasterPro CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + test: |
| 12 | + name: Test on Python ${{ matrix.python-version }} |
| 13 | + runs-on: ${{ matrix.os }} |
| 14 | + |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 19 | + python-version: ['3.10', '3.11', '3.12'] |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Set up Python ${{ matrix.python-version }} |
| 26 | + uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: ${{ matrix.python-version }} |
| 29 | + cache: 'pip' |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: | |
| 33 | + python -m pip install --upgrade pip |
| 34 | + pip install -r requirements.txt |
| 35 | + pip install pytest pytest-cov pytest-xdist |
| 36 | + |
| 37 | + - name: Run tests with coverage |
| 38 | + run: | |
| 39 | + pytest tests/ -v --cov=scripts --cov-report=xml --cov-report=term-missing |
| 40 | + |
| 41 | + - name: Upload coverage to Codecov |
| 42 | + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' |
| 43 | + uses: codecov/codecov-action@v4 |
| 44 | + with: |
| 45 | + file: ./coverage.xml |
| 46 | + flags: unittests |
| 47 | + name: codecov-umbrella |
| 48 | + fail_ci_if_error: false |
| 49 | + |
| 50 | + lint: |
| 51 | + name: Lint and Code Quality |
| 52 | + runs-on: ubuntu-latest |
| 53 | + |
| 54 | + steps: |
| 55 | + - name: Checkout code |
| 56 | + uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Set up Python |
| 59 | + uses: actions/setup-python@v5 |
| 60 | + with: |
| 61 | + python-version: '3.10' |
| 62 | + |
| 63 | + - name: Install linting tools |
| 64 | + run: | |
| 65 | + python -m pip install --upgrade pip |
| 66 | + pip install flake8 black isort mypy |
| 67 | + |
| 68 | + - name: Check code formatting with Black |
| 69 | + run: | |
| 70 | + black --check scripts/ tests/ || echo "Black formatting check completed with warnings" |
| 71 | + |
| 72 | + - name: Check import sorting with isort |
| 73 | + run: | |
| 74 | + isort --check-only scripts/ tests/ || echo "isort check completed with warnings" |
| 75 | + |
| 76 | + - name: Lint with flake8 |
| 77 | + run: | |
| 78 | + flake8 scripts/ tests/ --count --select=E9,F63,F7,F82 --show-source --statistics |
| 79 | + flake8 scripts/ tests/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 80 | +
|
| 81 | + notebook-check: |
| 82 | + name: Validate Notebooks |
| 83 | + runs-on: ubuntu-latest |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Checkout code |
| 87 | + uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Set up Python |
| 90 | + uses: actions/setup-python@v5 |
| 91 | + with: |
| 92 | + python-version: '3.10' |
| 93 | + |
| 94 | + - name: Install dependencies |
| 95 | + run: | |
| 96 | + python -m pip install --upgrade pip |
| 97 | + pip install -r requirements.txt |
| 98 | + pip install nbconvert nbformat |
| 99 | + |
| 100 | + - name: Check notebook execution |
| 101 | + run: | |
| 102 | + find notebooks -name "*.ipynb" -print0 | while IFS= read -r -d '' notebook; do |
| 103 | + echo "Validating $notebook" |
| 104 | + jupyter nbconvert --to notebook --execute "$notebook" --output /tmp/test.ipynb || echo "Notebook validation completed" |
| 105 | + done |
| 106 | +
|
| 107 | + docker-build: |
| 108 | + name: Docker Build Test |
| 109 | + runs-on: ubuntu-latest |
| 110 | + |
| 111 | + steps: |
| 112 | + - name: Checkout code |
| 113 | + uses: actions/checkout@v4 |
| 114 | + |
| 115 | + - name: Set up Docker Buildx |
| 116 | + uses: docker/setup-buildx-action@v3 |
| 117 | + |
| 118 | + - name: Build Docker image |
| 119 | + run: | |
| 120 | + docker build -t numpymasterpro:test . |
| 121 | + |
| 122 | + - name: Test Docker image |
| 123 | + run: | |
| 124 | + docker run --rm numpymasterpro:test python -c "import numpy; print(numpy.__version__)" |
| 125 | +
|
| 126 | + security-scan: |
| 127 | + name: Security Scan |
| 128 | + runs-on: ubuntu-latest |
| 129 | + |
| 130 | + steps: |
| 131 | + - name: Checkout code |
| 132 | + uses: actions/checkout@v4 |
| 133 | + |
| 134 | + - name: Set up Python |
| 135 | + uses: actions/setup-python@v5 |
| 136 | + with: |
| 137 | + python-version: '3.10' |
| 138 | + |
| 139 | + - name: Install dependencies |
| 140 | + run: | |
| 141 | + python -m pip install --upgrade pip |
| 142 | + pip install safety bandit |
| 143 | + |
| 144 | + - name: Run safety check on dependencies |
| 145 | + run: | |
| 146 | + pip install -r requirements.txt |
| 147 | + safety check || echo "Safety check completed with warnings" |
| 148 | + |
| 149 | + - name: Run bandit security scan |
| 150 | + run: | |
| 151 | + bandit -r scripts/ -ll || echo "Bandit scan completed" |
| 152 | +
|
| 153 | + build-status: |
| 154 | + name: Build Status |
| 155 | + needs: [test, lint, notebook-check, docker-build] |
| 156 | + runs-on: ubuntu-latest |
| 157 | + if: always() |
| 158 | + |
| 159 | + steps: |
| 160 | + - name: Check build status |
| 161 | + run: | |
| 162 | + if [ "${{ needs.test.result }}" = "success" ] && [ "${{ needs.lint.result }}" = "success" ]; then |
| 163 | + echo "✅ All critical checks passed!" |
| 164 | + exit 0 |
| 165 | + else |
| 166 | + echo "❌ Some checks failed" |
| 167 | + exit 1 |
| 168 | + fi |
0 commit comments