ci: make tag workflow robust for non-release commits #2
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: Tag Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| tag: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Create and push tag for release commits | |
| run: | | |
| MESSAGE="${{ github.event.head_commit.message }}" | |
| if [[ "$MESSAGE" != chore\(release\):\ v* ]]; then | |
| echo "Not a release commit; skipping" | |
| exit 0 | |
| fi | |
| VERSION="v$(node -p \"require('./package.json').version\")" | |
| if git ls-remote --tags origin | grep -q "refs/tags/${VERSION}$"; then | |
| echo "Tag ${VERSION} already exists; skipping" | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "${VERSION}" -m "Release ${VERSION}" | |
| git push origin "${VERSION}" |