fix: combine auto-tag and release into one workflow #3
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 Tag and Release | |
| on: | |
| push: | |
| branches: [main] | |
| jobs: | |
| auto-tag: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| tag: ${{ steps.tag.outputs.tag }} | |
| created: ${{ steps.tag.outputs.created }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Create tag if needed | |
| id: tag | |
| run: | | |
| VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') | |
| TAG="v${VERSION}" | |
| echo "Detected version: $VERSION" | |
| echo "Tag: $TAG" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "Tag $TAG already exists. Nothing to do." | |
| echo "created=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| echo "Creating and pushing tag $TAG" | |
| git tag "$TAG" | |
| git push origin "$TAG" | |
| echo "created=true" >> "$GITHUB_OUTPUT" | |
| release: | |
| needs: auto-tag | |
| if: needs.auto-tag.outputs.created == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Create GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create "${{ needs.auto-tag.outputs.tag }}" \ | |
| --title "Release ${{ needs.auto-tag.outputs.tag }}" \ | |
| --generate-notes |