Skip to content

[bot] New pkg version: 0.0.0-alpha.3 (#37) #33

[bot] New pkg version: 0.0.0-alpha.3 (#37)

[bot] New pkg version: 0.0.0-alpha.3 (#37) #33

name: Release and Versioning
on:
push:
branches:
- main
pull_request_review:
types: [submitted]
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
- name: Check if version was already bumped
id: version_check
if: github.event.review.state == 'approved'
run: |
# Find the commit where the branch diverged from main
git fetch origin main
MERGE_BASE=$(git merge-base origin/main HEAD)
# Check commits between merge-base and current HEAD
COMMITS=$(git log $MERGE_BASE..HEAD --format=%B)
if echo "$COMMITS" | grep -q "\[bot\] New pkg version:"; then
VERSION_COMMIT=$(echo "$COMMITS" | grep "\[bot\] New pkg version:" | head -n 1)
echo "::warning::Version was already bumped in this branch with commit message: $VERSION_COMMIT"
echo "skip_bump=true" >> $GITHUB_OUTPUT
else
echo "No version bump found in branch commits"
echo "skip_bump=false" >> $GITHUB_OUTPUT
fi
- name: Check PR labels
id: check_labels
if: |
steps.version_check.outputs.skip_bump != 'true' &&
github.event.review.state == 'approved'
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
PR_NUMBER=${{ github.event.pull_request.number }}
else
PR_NUMBER=$(gh pr list --state merged --json number --jq '.[0].number')
fi
LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
echo "::notice::PR used to check version bump: #$PR_NUMBER"
echo "::notice::PR labels: "[${LABELS//$'\n'/,}]""
RELEASE_TYPE=$(./.github/ci-scripts/pr-label-check.sh) || exit_code=$?
if [ "$exit_code" -ne 0 ]; then
echo "::error::PR #"$PR_NUMBER" has more than one release label"
exit $exit_code
fi
echo "version=$RELEASE_TYPE" >> $GITHUB_OUTPUT
echo "::group::Output version"
echo "::notice::Release type: $RELEASE_TYPE"
if [ "$RELEASE_TYPE" == "no-release" ]; then
echo "::notice::PR is not flagged for release, skipping other steps"
fi
echo "::endgroup::"
- name: Bump version
id: bump
if: |
steps.version_check.outputs.skip_bump != 'true' &&
steps.check_labels.outputs.version != 'no-release' &&
github.event.review.state == 'approved'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
if [ "${{ steps.check_labels.outputs.version }}" == "alpha" ]; then
npm version -m "[bot] New pkg version: %s" --preid=alpha prerelease
else
npm version -m "[bot] New pkg version: %s" ${{ steps.check_labels.outputs.version }}
fi
git push
- name: Create GitHub Release
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
steps.check_labels.outputs.version != 'no-release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(node -p "require('./package.json').version")
gh release create "v${VERSION}" \
--title "Release v${VERSION}" \
--generate-notes \
--prerelease \
--target "${GITHUB_SHA}"