Skip to content

Update README

Update README #43

name: Auto-tag release
on:
pull_request:
types: [closed]
branches: [main]
jobs:
tag:
name: Create release tag
runs-on: ubuntu-latest
if: >
github.event.pull_request.merged == true &&
github.event.pull_request.head.repo.full_name == github.repository &&
startsWith(github.event.pull_request.head.ref, 'release/')
permissions:
contents: write
actions: write
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: 0
fetch-tags: true
persist-credentials: false
- name: Extract and validate version
id: version
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
run: |
VERSION="${BRANCH#release/}"
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Invalid version format: $VERSION"
exit 1
fi
PKG_VERSION=$(node -p "require('./package.json').version")
if [ "$VERSION" != "$PKG_VERSION" ]; then
echo "::error::Branch version ($VERSION) does not match package.json ($PKG_VERSION)"
exit 1
fi
if git tag -l "v$VERSION" | grep -q .; then
echo "::error::Tag v$VERSION already exists"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Create and push tag
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }}
run: |
gh api --method POST "repos/${GITHUB_REPOSITORY}/git/refs" \
-f ref="refs/tags/v${VERSION}" \
-f sha="${MERGE_COMMIT_SHA}"
- name: Trigger release workflow
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
gh workflow run release.yml --ref "v${VERSION}"