Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
name: Release

on:
push:
pull_request:
types: [closed]
branches: [main]

jobs:
release:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: ${{ secrets.VERSION_BUMP_KEY }}

- name: Get version from package.json
id: version
- name: Bump patch version
id: bump
run: |
VERSION=$(jq -r '.version // empty' package.json)
if [[ -z "$VERSION" ]]; then
echo "No version in package.json, skipping release"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
TAG="v$VERSION"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists, skipping release"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "skip=false" >> "$GITHUB_OUTPUT"
CURRENT=$(jq -r '.version' package.json)
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
MINOR=$(echo "$CURRENT" | cut -d. -f2)
PATCH=$(echo "$CURRENT" | cut -d. -f3)
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "Bumping $CURRENT → $NEW_VERSION"
jq --arg v "$NEW_VERSION" '.version = $v' package.json > tmp.json && mv tmp.json package.json

- name: Generate changelog
if: steps.version.outputs.skip == 'false'
id: changelog
- name: Commit version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "bump to v${{ steps.bump.outputs.version }}"
git push

- name: Generate release notes
id: notes
run: |
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [[ -n "$PREV_TAG" ]]; then
Expand All @@ -44,19 +48,22 @@ jobs:
RANGE="HEAD"
fi
NOTES=$(git log "$RANGE" --oneline --no-merges 2>/dev/null | head -50)
if [[ -z "$NOTES" ]]; then
NOTES="Merged: ${{ github.event.pull_request.title }}"
fi
{
echo "notes<<EOF"
echo "$NOTES"
echo "EOF"
} >> "$GITHUB_OUTPUT"

- name: Create tag and release
if: steps.version.outputs.skip == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag "${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
gh release create "${{ steps.version.outputs.tag }}" \
--title "${{ steps.version.outputs.tag }}" \
--notes "${{ steps.changelog.outputs.notes }}"
TAG="v${{ steps.bump.outputs.version }}"
git tag "$TAG"
git push origin "$TAG"
gh release create "$TAG" \
--title "$TAG" \
--notes "${{ steps.notes.outputs.notes }}"
Loading