Repository navigation
Create Release and Publish #11
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: Create Release and Publish | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| if: github.ref == 'refs/heads/master' | |
| environment: pypi | |
| outputs: | |
| version: ${{ steps.changelog.outputs.version }} | |
| released: ${{ steps.check_tag.outputs.exists == 'false' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| # Needed so the tag existence check below can see the tags. | |
| fetch-depth: 0 | |
| - name: Extract version and notes from CHANGELOG | |
| id: changelog | |
| run: | | |
| # Extract version from first ## [x.x.x] header | |
| VERSION=$(grep -m1 -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # Extract release notes (content between first and second ## headers) | |
| NOTES=$(awk '/^## \['"$VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md) | |
| # Handle multiline output | |
| { | |
| echo "notes<<EOF" | |
| echo "$NOTES" | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| - name: Check if tag already exists | |
| id: check_tag | |
| run: | | |
| if git rev-parse -q --verify "refs/tags/${{ steps.changelog.outputs.version }}" >/dev/null; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create Release | |
| if: steps.check_tag.outputs.exists == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.changelog.outputs.version }} | |
| name: v${{ steps.changelog.outputs.version }} | |
| body: ${{ steps.changelog.outputs.notes }} | |
| draft: false | |
| prerelease: false | |
| - name: Skip release (tag exists) | |
| if: steps.check_tag.outputs.exists == 'true' | |
| run: | | |
| echo "⚠️ Tag ${{ steps.changelog.outputs.version }} already exists. Skipping release creation." | |
| exit 1 | |
| - name: Install UV | |
| uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 | |
| with: | |
| # uv build only needs the build backend, not the project dependencies. | |
| enable-cache: false | |
| - name: Build package | |
| run: uv build | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 |