|
| 1 | +name: Auto Tag and Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +jobs: |
| 10 | + auto-tag-and-release: |
| 11 | + # Only run if the PR was merged and has the version-bump label |
| 12 | + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'version-bump') |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + actions: write |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + ref: main |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Get version from version.txt |
| 25 | + id: get-version |
| 26 | + run: | |
| 27 | + VERSION=$(cat version.txt | tr -d '[:space:]') |
| 28 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 29 | + echo "tag=v${VERSION}" >> $GITHUB_OUTPUT |
| 30 | + echo "Version from version.txt: ${VERSION}" |
| 31 | + echo "Will create tag: v${VERSION}" |
| 32 | +
|
| 33 | + - name: Check if tag already exists |
| 34 | + id: check-tag |
| 35 | + run: | |
| 36 | + TAG="v${{ steps.get-version.outputs.version }}" |
| 37 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 38 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 39 | + echo "⚠️ Tag $TAG already exists" |
| 40 | + else |
| 41 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 42 | + echo "✓ Tag $TAG does not exist yet" |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Create and push tag |
| 46 | + if: steps.check-tag.outputs.exists == 'false' |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{ github.token }} |
| 49 | + run: | |
| 50 | + TAG="v${{ steps.get-version.outputs.version }}" |
| 51 | +
|
| 52 | + # Configure git |
| 53 | + git config --local user.name "github-actions[bot]" |
| 54 | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 55 | +
|
| 56 | + # Create annotated tag |
| 57 | + git tag -a "$TAG" -m "Release $TAG" |
| 58 | +
|
| 59 | + # Push tag |
| 60 | + git push origin "$TAG" |
| 61 | +
|
| 62 | + echo "✅ Created and pushed tag: $TAG" |
| 63 | +
|
| 64 | + - name: Trigger release workflow |
| 65 | + if: steps.check-tag.outputs.exists == 'false' |
| 66 | + env: |
| 67 | + GH_TOKEN: ${{ secrets.FLASHINFER_BOT_TOKEN }} |
| 68 | + run: | |
| 69 | + TAG="v${{ steps.get-version.outputs.version }}" |
| 70 | +
|
| 71 | + # Trigger the release workflow |
| 72 | + gh workflow run release.yml \ |
| 73 | + -f tag="$TAG" |
| 74 | +
|
| 75 | + echo "✅ Triggered release workflow for tag: $TAG" |
| 76 | +
|
| 77 | + - name: Summary |
| 78 | + run: | |
| 79 | + echo "## Auto Tag and Release Summary" >> $GITHUB_STEP_SUMMARY |
| 80 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 81 | +
|
| 82 | + if [ "${{ steps.check-tag.outputs.exists }}" = "true" ]; then |
| 83 | + echo "⚠️ Tag v${{ steps.get-version.outputs.version }} already exists, skipped" >> $GITHUB_STEP_SUMMARY |
| 84 | + else |
| 85 | + echo "✅ Successfully created tag and triggered release workflow" >> $GITHUB_STEP_SUMMARY |
| 86 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 87 | + echo "- **Version**: ${{ steps.get-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 88 | + echo "- **Tag**: v${{ steps.get-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 89 | + echo "- **PR**: #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY |
| 90 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 91 | + echo "🔗 [View Release Workflow Runs](../../actions/workflows/release.yml)" >> $GITHUB_STEP_SUMMARY |
| 92 | + fi |
| 93 | +
|
| 94 | + - name: Tag already exists |
| 95 | + if: steps.check-tag.outputs.exists == 'true' |
| 96 | + run: | |
| 97 | + echo "Tag v${{ steps.get-version.outputs.version }} already exists, skipping tag creation and release" |
| 98 | + exit 0 |
0 commit comments