ci: add release and PyPI publish workflows#15
Conversation
Triggers on v*.*.* tags and creates a GitHub Release with auto-generated release notes.
Builds and publishes the Python package to PyPI using twine when a GitHub Release is published. Requires PYPI_API_TOKEN secret.
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.x" | ||
|
|
||
| - name: Install build dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install build twine | ||
|
|
||
| - name: Build package | ||
| run: python -m build | ||
|
|
||
| - name: Publish to PyPI | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
| run: twine upload dist/* |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month ago
In general, the fix is to add an explicit permissions: block that limits the GITHUB_TOKEN to the minimum access needed. For this workflow, the job only needs to read the repository contents to allow actions/checkout to function; it does not need to push commits, manage releases, or modify pull requests. Therefore, we can safely set contents: read.
The best way to fix this without changing existing functionality is to add a top-level permissions: block (between name: and on:) so that all jobs in the workflow inherit it. This keeps the change minimal and clear. Concretely, in .github/workflows/publish-pypi.yaml, insert:
permissions:
contents: readafter the first line (name: Publish to PyPI). No additional methods, imports, or definitions are required, since this is just GitHub Actions YAML configuration.
| @@ -1,5 +1,8 @@ | ||
| name: Publish to PyPI | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| release: | ||
| types: |
Summary
release.yaml: automatically creates a GitHub Release with generated release notes when av*.*.*tag is pushedpublish-pypi.yaml: builds and publishes the Python package to PyPI when a release is published (requiresPYPI_API_TOKENsecret)build-and-publish.yamlalready handles Docker tags (vX,vX.X,vX.X.X,X,X.X,X.X.X,latest) on release eventsSetup required
PYPI_API_TOKENsecret in repo settings (Settings → Secrets and variables → Actions)Test plan
v2.0.1and verify GitHub Release is createdbuild-and-publishworkflow triggers and produces correct Docker tagspublish-pypiworkflow triggers and uploads to PyPI