ci: GH actions workflow tweaks #17
Workflow file for this run
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
name: Build sdist and wheels and publish them to PyPI when a release tag is created in master branch | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- v* | |
workflow_dispatch: | |
jobs: | |
build_dist: | |
name: Build distribution | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Set up pip cache | |
if: runner.os == 'Linux' | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }} | |
restore-keys: ${{ runner.os }}-pip- | |
- name: Install hatch | |
run: | | |
pipx install hatch | |
hatch --version | |
- name: Build the package | |
run: | | |
hatch build | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
path: dist/* | |
if-no-files-found: error | |
publish: | |
if: startsWith(github.ref, 'ref/tags/v') | |
needs: [build_dist] | |
runs-on: ubuntu-latest | |
environment: PyPI Release | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
# unpacks default artifact into dist/ | |
# if `name: artifact` is omitted, the action will create extra parent dir | |
name: artifact | |
path: dist | |
- name: Publish sdist and wheels to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
verify-metadata: false | |