| 1 | name: Release |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: [ master ] |
| 6 | |
| 7 | permissions: |
| 8 | contents: write |
| 9 | |
| 10 | jobs: |
| 11 | release: |
| 12 | runs-on: ubuntu-latest |
| 13 | |
| 14 | steps: |
| 15 | - uses: actions/checkout@v4 |
| 16 | with: |
| 17 | fetch-depth: 0 |
| 18 | |
| 19 | - name: Install uv |
| 20 | uses: astral-sh/setup-uv@v6 |
| 21 | with: |
| 22 | enable-cache: true |
| 23 | |
| 24 | - name: Read version from pyproject.toml |
| 25 | id: version |
| 26 | run: | |
| 27 | VERSION=$(grep '^version' pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/') |
| 28 | echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 29 | |
| 30 | - name: Check if tag already exists |
| 31 | id: tag_check |
| 32 | run: | |
| 33 | if git rev-parse "refs/tags/${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
| 34 | echo "exists=true" >> "$GITHUB_OUTPUT" |
| 35 | else |
| 36 | echo "exists=false" >> "$GITHUB_OUTPUT" |
| 37 | fi |
| 38 | |
| 39 | - name: Create tag and release |
| 40 | if: steps.tag_check.outputs.exists == 'false' |
| 41 | env: |
| 42 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | run: | |
| 44 | VERSION="${{ steps.version.outputs.version }}" |
| 45 | git tag "$VERSION" |
| 46 | git push origin "$VERSION" |
| 47 | gh release create "$VERSION" \ |
| 48 | --title "Release $VERSION" \ |
| 49 | --generate-notes |