|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ["v*"] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + publish: |
| 9 | + description: "Publish to PyPI" |
| 10 | + required: true |
| 11 | + default: "false" |
| 12 | + type: choice |
| 13 | + options: ["false", "true"] |
| 14 | + |
| 15 | +jobs: |
| 16 | + quality: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: "3.11" |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + python -m pip install --upgrade pip |
| 30 | + python -m pip install -e ".[dev]" |
| 31 | +
|
| 32 | + - name: Run tests |
| 33 | + run: python -m pytest -q |
| 34 | + |
| 35 | + - name: Run security checks |
| 36 | + run: python -m bandit -q -r src/predicate_secure/ |
| 37 | + |
| 38 | + - name: Run pre-commit checks |
| 39 | + run: | |
| 40 | + python -m pip install pre-commit |
| 41 | + pre-commit run --all-files |
| 42 | +
|
| 43 | + publish: |
| 44 | + runs-on: ubuntu-latest |
| 45 | + needs: [quality] |
| 46 | + if: (github.event_name == 'workflow_dispatch' && inputs.publish == 'true') || startsWith(github.ref, 'refs/tags/v') |
| 47 | + steps: |
| 48 | + - name: Checkout |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Set up Python |
| 52 | + uses: actions/setup-python@v5 |
| 53 | + with: |
| 54 | + python-version: "3.11" |
| 55 | + |
| 56 | + - name: Install build tooling |
| 57 | + run: python -m pip install --upgrade pip build twine |
| 58 | + |
| 59 | + - name: Validate version matches tag |
| 60 | + if: startsWith(github.ref, 'refs/tags/v') |
| 61 | + run: | |
| 62 | + TAG_VERSION="${GITHUB_REF_NAME#v}" |
| 63 | + PKG_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") |
| 64 | + if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then |
| 65 | + echo "Tag version ($TAG_VERSION) does not match package version ($PKG_VERSION)" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + echo "Version validated: $PKG_VERSION" |
| 69 | +
|
| 70 | + - name: Build package |
| 71 | + run: python -m build |
| 72 | + |
| 73 | + - name: Validate distribution metadata |
| 74 | + run: twine check dist/* |
| 75 | + |
| 76 | + - name: Publish to PyPI |
| 77 | + env: |
| 78 | + TWINE_USERNAME: __token__ |
| 79 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN_PREDICATE_SECURE }} |
| 80 | + run: twine upload dist/* |
0 commit comments