Create Tag on merge #74
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 Tag on merge | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - develop | |
| paths: | |
| - src/** | |
| - dist/** | |
| - package*.json | |
| jobs: | |
| create-tag: | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 15 | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-node@v5 | |
| with: | |
| node-version-file: .nvmrc | |
| - name: Create and push new tag | |
| run: npm run create-tag | |
| - name: Get latest commit | |
| id: get-commit | |
| run: echo "LAST_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
| - name: Check for associated pull request and auto-deploy label | |
| id: should-deploy | |
| uses: actions/github-script@v8 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const commit_sha = '${{ env.LAST_SHA }}'; | |
| const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ commit_sha, owner, repo }); | |
| if (prs?.length > 0) { | |
| const pull_number = prs[0].number; | |
| const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number }); | |
| // Extract content from PR description - prioritize CHANGELOG if present | |
| let releaseNote = pr.title; | |
| if (pr.body) { | |
| // First, check for __CHANGELOG__ section | |
| const changelogMatch = pr.body.match(/__CHANGELOG__\s*(.*?)\s*_Generated by LinearB AI/s); | |
| if (changelogMatch) { | |
| releaseNote = changelogMatch[1].trim(); | |
| } else { | |
| // Fallback to original gitstream placeholder extraction | |
| const contentMatch = pr.body.match(/<!--start_gitstream_placeholder-->.*?### ✨ PR Description\s*(.*?)\s*_Generated by LinearB AI.*?<!--end_gitstream_placeholder-->/s); | |
| if (contentMatch) { | |
| releaseNote = contentMatch[1].trim(); | |
| } else { | |
| // New format without gitstream placeholders | |
| const newFormatMatch = pr.body.match(/## ✨ PR Description\s*(.*?)\s*(?:__CHANGELOG__|_Generated by LinearB AI)/s); | |
| if (newFormatMatch) { | |
| releaseNote = newFormatMatch[1].trim(); | |
| } | |
| } | |
| } | |
| } | |
| core.setOutput('pr-title', pr.title); | |
| core.setOutput('release-notes', releaseNote); | |
| core.setOutput('pr-number', pr.number); | |
| return pr.labels.some(label => label.name.includes('auto-deploy')); | |
| } | |
| return false; | |
| - name: Create GitHub Release & Deploy | |
| if: steps.should-deploy.outputs.result == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Create release notes using printf to handle special characters safely | |
| printf "## What's Changed\n\n%s in [#%s](https://github.com/${{ github.repository }}/pull/%s)\n\n%s\n" \ | |
| "${{ steps.should-deploy.outputs.pr-title }}" \ | |
| "${{ steps.should-deploy.outputs.pr-number }}" \ | |
| "${{ steps.should-deploy.outputs.pr-number }}" \ | |
| "${{ steps.should-deploy.outputs.release-notes }}" > release_notes.md | |
| gh release create $NEW_TAG --notes-file release_notes.md | |
| git checkout $NEW_TAG | |
| npm run update-v2-tag | |
| - name: Update v2-lite | |
| if: steps.should-deploy.outputs.result == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config --global user.name 'GitHub Actions Bot' | |
| git config --global user.email 'actions@github.com' | |
| git checkout v2-lite | |
| git checkout $NEW_TAG package.json package-lock.json dist/ | |
| git add package.json package-lock.json dist/ | |
| git commit -m "Update v2-lite to $NEW_TAG" | |
| git push origin v2-lite |