|
| 1 | +name: Flask-Mailing CI/CD - 2026 Ready |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop, version-3.0.0 ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + release: |
| 9 | + types: [ published ] |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + name: Test Python ${{ matrix.python-version }} |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + python-version: ["3.10", "3.11", "3.12", "3.13"] |
| 19 | + |
| 20 | + services: |
| 21 | + redis: |
| 22 | + image: redis:7-alpine |
| 23 | + ports: |
| 24 | + - 6379:6379 |
| 25 | + options: >- |
| 26 | + --health-cmd "redis-cli ping" |
| 27 | + --health-interval 10s |
| 28 | + --health-timeout 5s |
| 29 | + --health-retries 5 |
| 30 | +
|
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Set up Python ${{ matrix.python-version }} |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: ${{ matrix.python-version }} |
| 38 | + cache: 'pip' |
| 39 | + |
| 40 | + - name: Install dependencies |
| 41 | + run: | |
| 42 | + python -m pip install --upgrade pip |
| 43 | + pip install -e ".[dev,email-checking]" |
| 44 | + pip install -r tests/requirements.testing.txt |
| 45 | + |
| 46 | + - name: Check code formatting with Black |
| 47 | + run: black --check --diff . |
| 48 | + |
| 49 | + - name: Check import sorting with isort |
| 50 | + run: isort --check-only --diff . |
| 51 | + |
| 52 | + - name: Lint with Ruff |
| 53 | + run: ruff check . |
| 54 | + |
| 55 | + - name: Type check with mypy |
| 56 | + run: mypy flask_mailing --ignore-missing-imports |
| 57 | + |
| 58 | + - name: Run tests with pytest |
| 59 | + run: | |
| 60 | + pytest tests/ \ |
| 61 | + --cov=flask_mailing \ |
| 62 | + --cov-report=xml \ |
| 63 | + --cov-report=term-missing \ |
| 64 | + -v |
| 65 | + env: |
| 66 | + REDIS_URL: redis://localhost:6379 |
| 67 | + |
| 68 | + - name: Upload coverage to Codecov |
| 69 | + uses: codecov/codecov-action@v4 |
| 70 | + with: |
| 71 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 72 | + file: ./coverage.xml |
| 73 | + fail_ci_if_error: true |
| 74 | + |
| 75 | + security-scan: |
| 76 | + name: Security Scan |
| 77 | + runs-on: ubuntu-latest |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - name: Set up Python |
| 82 | + uses: actions/setup-python@v5 |
| 83 | + with: |
| 84 | + python-version: "3.12" |
| 85 | + |
| 86 | + - name: Install dependencies |
| 87 | + run: | |
| 88 | + python -m pip install --upgrade pip |
| 89 | + pip install safety bandit[toml] |
| 90 | + pip install -e . |
| 91 | + |
| 92 | + - name: Run safety check |
| 93 | + run: | |
| 94 | + safety check --json --output safety-report.json || true |
| 95 | + |
| 96 | + - name: Run bandit security scan |
| 97 | + run: | |
| 98 | + bandit -r flask_mailing -f json -o bandit-report.json || true |
| 99 | + |
| 100 | + - name: Upload security scan results |
| 101 | + uses: actions/upload-artifact@v4 |
| 102 | + with: |
| 103 | + name: security-reports |
| 104 | + path: | |
| 105 | + safety-report.json |
| 106 | + bandit-report.json |
| 107 | +
|
| 108 | + build: |
| 109 | + name: Build Package |
| 110 | + runs-on: ubuntu-latest |
| 111 | + needs: [test, security-scan] |
| 112 | + steps: |
| 113 | + - uses: actions/checkout@v4 |
| 114 | + |
| 115 | + - name: Set up Python |
| 116 | + uses: actions/setup-python@v5 |
| 117 | + with: |
| 118 | + python-version: "3.12" |
| 119 | + |
| 120 | + - name: Install build dependencies |
| 121 | + run: | |
| 122 | + python -m pip install --upgrade pip |
| 123 | + pip install build twine |
| 124 | + |
| 125 | + - name: Build package |
| 126 | + run: python -m build |
| 127 | + |
| 128 | + - name: Check package |
| 129 | + run: twine check dist/* |
| 130 | + |
| 131 | + - name: Upload build artifacts |
| 132 | + uses: actions/upload-artifact@v4 |
| 133 | + with: |
| 134 | + name: dist |
| 135 | + path: dist/ |
| 136 | + |
| 137 | + publish: |
| 138 | + name: Publish to PyPI |
| 139 | + runs-on: ubuntu-latest |
| 140 | + needs: build |
| 141 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 142 | + environment: |
| 143 | + name: pypi |
| 144 | + url: https://pypi.org/p/flask-mailing |
| 145 | + permissions: |
| 146 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 147 | + |
| 148 | + steps: |
| 149 | + - name: Download build artifacts |
| 150 | + uses: actions/download-artifact@v4 |
| 151 | + with: |
| 152 | + name: dist |
| 153 | + path: dist/ |
| 154 | + |
| 155 | + - name: Publish to PyPI |
| 156 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 157 | + with: |
| 158 | + skip-existing: true |
| 159 | + |
| 160 | + docker: |
| 161 | + name: Build Docker Image |
| 162 | + runs-on: ubuntu-latest |
| 163 | + needs: test |
| 164 | + if: github.ref == 'refs/heads/main' || github.event_name == 'release' |
| 165 | + |
| 166 | + steps: |
| 167 | + - uses: actions/checkout@v4 |
| 168 | + |
| 169 | + - name: Set up Docker Buildx |
| 170 | + uses: docker/setup-buildx-action@v3 |
| 171 | + |
| 172 | + - name: Login to GitHub Container Registry |
| 173 | + uses: docker/login-action@v3 |
| 174 | + with: |
| 175 | + registry: ghcr.io |
| 176 | + username: ${{ github.actor }} |
| 177 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 178 | + |
| 179 | + - name: Extract metadata |
| 180 | + id: meta |
| 181 | + uses: docker/metadata-action@v5 |
| 182 | + with: |
| 183 | + images: ghcr.io/${{ github.repository }} |
| 184 | + tags: | |
| 185 | + type=ref,event=branch |
| 186 | + type=ref,event=pr |
| 187 | + type=semver,pattern={{version}} |
| 188 | + type=semver,pattern={{major}}.{{minor}} |
| 189 | + type=semver,pattern={{major}} |
| 190 | + type=raw,value=latest,enable={{is_default_branch}} |
| 191 | + |
| 192 | + - name: Build and push |
| 193 | + uses: docker/build-push-action@v5 |
| 194 | + with: |
| 195 | + context: . |
| 196 | + push: true |
| 197 | + tags: ${{ steps.meta.outputs.tags }} |
| 198 | + labels: ${{ steps.meta.outputs.labels }} |
| 199 | + cache-from: type=gha |
| 200 | + cache-to: type=gha,mode=max |
0 commit comments