fix: combine release and PyPI publish into single workflow #8
This file contains hidden or 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: Auto Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write # Required for trusted publishing to PyPI | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get version from pyproject.toml | |
| id: version | |
| run: | | |
| VERSION=$(grep -m1 'version = ' pyproject.toml | cut -d'"' -f2) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Version from pyproject.toml: $VERSION" | |
| - name: Check if version already released | |
| id: check | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| if git tag | grep -q "^v$VERSION$"; then | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| echo "Version v$VERSION already exists, skipping" | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| echo "Version v$VERSION not released yet" | |
| fi | |
| - name: Create tag and release | |
| if: steps.check.outputs.skip == 'false' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| COMMIT_MSG=$(git log -1 --pretty=%B | head -1) | |
| git config user.name "GitHub Actions" | |
| git config user.email "[email protected]" | |
| git tag -a "v$VERSION" -m "Release v$VERSION" | |
| git push origin "v$VERSION" | |
| cat <<EOF | gh release create "v$VERSION" --title "v$VERSION" --notes-file - | |
| ## Changes | |
| $COMMIT_MSG | |
| --- | |
| *Auto-generated release* | |
| EOF | |
| # Publish to PyPI after release is created | |
| - name: Install uv | |
| if: steps.check.outputs.skip == 'false' | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| version: "latest" | |
| - name: Set up Python | |
| if: steps.check.outputs.skip == 'false' | |
| run: uv python install 3.11 | |
| - name: Build package | |
| if: steps.check.outputs.skip == 'false' | |
| run: uv build | |
| - name: Publish to PyPI | |
| if: steps.check.outputs.skip == 'false' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| skip-existing: true |