|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Fires when a tag matching v*.*.* is pushed (e.g. v0.4.0). |
| 4 | +# Builds the sdist + wheel, uploads them to the workflow run for audit, |
| 5 | +# publishes to PyPI via trusted publishing (no long-lived token needed), |
| 6 | +# and creates a GitHub release with the built artifacts attached. |
| 7 | +# |
| 8 | +# One-time setup on pypi.org before this workflow can succeed: |
| 9 | +# https://pypi.org/manage/project/sql-sop/settings/publishing/ |
| 10 | +# Add a trusted publisher with: |
| 11 | +# Owner: Pawansingh3889 |
| 12 | +# Repository: sql-guard |
| 13 | +# Workflow: release.yml |
| 14 | +# Environment: release |
| 15 | +# Until that publisher exists, the `publish` job will fail with an OIDC |
| 16 | +# error — the `build` job still runs so you get the artifacts. |
| 17 | + |
| 18 | +on: |
| 19 | + push: |
| 20 | + tags: |
| 21 | + - "v*.*.*" |
| 22 | + workflow_dispatch: |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: read |
| 26 | + |
| 27 | +jobs: |
| 28 | + build: |
| 29 | + name: Build sdist and wheel |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Set up Python |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: "3.12" |
| 38 | + |
| 39 | + - name: Install build backend |
| 40 | + run: | |
| 41 | + python -m pip install --upgrade pip |
| 42 | + python -m pip install build |
| 43 | +
|
| 44 | + - name: Build distributions |
| 45 | + run: python -m build |
| 46 | + |
| 47 | + - name: Show built files |
| 48 | + run: ls -lh dist/ |
| 49 | + |
| 50 | + - name: Upload build artifacts |
| 51 | + uses: actions/upload-artifact@v4 |
| 52 | + with: |
| 53 | + name: dist |
| 54 | + path: dist/ |
| 55 | + if-no-files-found: error |
| 56 | + |
| 57 | + publish-pypi: |
| 58 | + name: Publish to PyPI |
| 59 | + needs: build |
| 60 | + runs-on: ubuntu-latest |
| 61 | + environment: |
| 62 | + name: release |
| 63 | + url: https://pypi.org/project/sql-sop/ |
| 64 | + permissions: |
| 65 | + id-token: write # required for PyPI trusted publishing (OIDC) |
| 66 | + steps: |
| 67 | + - name: Download build artifacts |
| 68 | + uses: actions/download-artifact@v4 |
| 69 | + with: |
| 70 | + name: dist |
| 71 | + path: dist/ |
| 72 | + |
| 73 | + - name: Publish to PyPI |
| 74 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 75 | + with: |
| 76 | + skip-existing: true |
| 77 | + |
| 78 | + github-release: |
| 79 | + name: Attach artifacts to GitHub Release |
| 80 | + needs: publish-pypi |
| 81 | + runs-on: ubuntu-latest |
| 82 | + permissions: |
| 83 | + contents: write # required for creating a GitHub release |
| 84 | + steps: |
| 85 | + - uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - name: Download build artifacts |
| 88 | + uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + name: dist |
| 91 | + path: dist/ |
| 92 | + |
| 93 | + - name: Create GitHub release |
| 94 | + env: |
| 95 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + run: | |
| 97 | + tag="${GITHUB_REF##*/}" |
| 98 | + gh release create "$tag" \ |
| 99 | + --title "$tag" \ |
| 100 | + --generate-notes \ |
| 101 | + dist/* |
0 commit comments