Publish Python distributions to PyPI #782
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on | |
# https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ | |
name: Publish Python distributions to PyPI | |
on: | |
push: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * 0" | |
permissions: | |
contents: read | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
build-n-publish: | |
name: Build and publish Python distributions to PyPI | |
runs-on: ubuntu-latest | |
permissions: | |
# needed for PyPI trusted publishing | |
id-token: write | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Install uv | |
uses: astral-sh/setup-uv@v1 | |
with: | |
version: "latest" | |
- run: uv pip install build --system | |
- run: uv pip freeze | |
- if: ${{ github.event_name != 'push' }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: | | |
DATE=$(date '+%y.%-m.%-d') | |
echo $DATE | |
git config --global user.name releasebot | |
git config --global user.email "" | |
git tag -a $DATE -m "" | |
git push --tags | |
gh release create $DATE --notes "Automated weekly release" | |
- name: Build a binary wheel and a source tarball | |
run: python -m build --outdir dist/ . | |
- name: Publish distribution to PyPI | |
if: ${{ github.event_name != 'push' || startsWith(github.ref, 'refs/tags') }} | |
uses: pypa/gh-action-pypi-publish@release/v1 |