Skip to content
Merged
Show file tree
Hide file tree
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
104 changes: 104 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Create Release PR

on:
workflow_dispatch:
inputs:
version:
description: 'Version type'
required: true
type: choice
options:
- patch
- minor
- major

jobs:
create-release-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false

- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Setup Node.js
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: 'lts/*'

# No need to install dependencies - npm version works without them
- name: Version bump
id: version
run: |
npm version "$VERSION_TYPE" --no-git-tag-version
VERSION=$(jq -r '.version' package.json)
echo "version=$VERSION" >> $GITHUB_OUTPUT
env:
VERSION_TYPE: ${{ github.event.inputs.version }}

- name: Get release notes
id: release-notes
run: |
# Get the default branch
DEFAULT_BRANCH=$(gh api "repos/$GITHUB_REPOSITORY" --jq '.default_branch')

# Get the last release tag using GitHub API
LAST_TAG=$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq '.tag_name' 2>/dev/null || echo "")

# Log the tag status
if [ -z "$LAST_TAG" ]; then
echo "No previous releases found, generating notes from beginning"
else
echo "Previous release: $LAST_TAG"
fi

# Generate release notes with or without previous tag
if [ -n "$LAST_TAG" ]; then
NOTES=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/$GITHUB_REPOSITORY/releases/generate-notes" \
-f "tag_name=v$VERSION" \
-f "target_commitish=$DEFAULT_BRANCH" \
-f "previous_tag_name=$LAST_TAG" \
--jq '.body')
else
NOTES=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/$GITHUB_REPOSITORY/releases/generate-notes" \
-f "tag_name=v$VERSION" \
-f "target_commitish=$DEFAULT_BRANCH" \
--jq '.body')
fi

# Save to file to handle multiline content
echo "$NOTES" > release-notes.md
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
GITHUB_REPOSITORY: ${{ github.repository }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with:
branch: release/v${{ steps.version.outputs.version }}
delete-branch: true
title: "Release v${{ steps.version.outputs.version }}"
body-path: release-notes.md
commit-message: "chore: release v${{ steps.version.outputs.version }}"
add-paths: |
package.json
yarn.lock
labels: |
Type: Release
assignees: ${{ github.actor }}
draft: true
155 changes: 155 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
name: Release

on:
pull_request:
branches:
- master
- main
types:
- closed
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 1.2.3)'
required: false
type: string

jobs:
release:
if: |
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'Type: Release')) ||
github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write # OIDC
pull-requests: write # PR comment
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false

- name: Get package info
id: package
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ] && [ -n "$INPUT_VERSION" ]; then
VERSION="$INPUT_VERSION"
else
VERSION=$(jq -r '.version' package.json)
fi
PACKAGE_NAME=$(jq -r '.name' package.json)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_VERSION: ${{ github.event.inputs.version }}

- name: Check if tag exists
id: tag-check
run: |
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
VERSION: ${{ steps.package.outputs.version }}

- name: Setup Node.js
if: steps.tag-check.outputs.exists == 'false'
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'

- name: Ensure npm 11.5.1 or later is installed
if: steps.tag-check.outputs.exists == 'false'
run: |
NPM_VERSION=$(npm -v)
echo "Current npm version: $NPM_VERSION"
if ! npx semver -r ">=11.5.1" "$NPM_VERSION"; then
echo "npm version $NPM_VERSION is too old. Installing latest npm..."
npm install -g npm@latest
echo "Updated npm version: $(npm -v)"
fi

- name: Install dependencies
if: steps.tag-check.outputs.exists == 'false'
run: yarn install --frozen-lockfile

- name: Build package
if: steps.tag-check.outputs.exists == 'false'
run: yarn run build

- name: Publish to npm with provenance
if: steps.tag-check.outputs.exists == 'false'
run: npm publish --provenance --access public

- name: Create GitHub Release with tag
id: create-release
if: steps.tag-check.outputs.exists == 'false'
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
RELEASE_URL=$(gh release create "v$VERSION" \
--title "v$VERSION" \
--target "$SHA" \
--generate-notes)
else
RELEASE_URL=$(gh release create "v$VERSION" \
--title "v$VERSION" \
--target "$SHA" \
--notes "$PR_BODY")
fi
echo "url=$RELEASE_URL" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.package.outputs.version }}
SHA: ${{ github.sha }}
EVENT_NAME: ${{ github.event_name }}
PR_BODY: ${{ github.event.pull_request.body }}

- name: Comment on PR - Success
if: |
always() &&
github.event_name == 'pull_request' &&
steps.tag-check.outputs.exists == 'false' &&
success()
run: |
gh pr comment "$PR_NUMBER" \
--body "✅ **Release v$VERSION completed successfully!**

- 📦 npm package: https://www.npmjs.com/package/$PACKAGE_NAME/v/$VERSION
- 🏷️ GitHub Release: $RELEASE_URL
- 🔗 Workflow run: $SERVER_URL/$REPOSITORY/actions/runs/$RUN_ID"
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
VERSION: ${{ steps.package.outputs.version }}
PACKAGE_NAME: ${{ steps.package.outputs.name }}
RELEASE_URL: ${{ steps.create-release.outputs.url }}
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}

- name: Comment on PR - Failure
if: |
always() &&
github.event_name == 'pull_request' &&
steps.tag-check.outputs.exists == 'false' &&
failure()
run: |
gh pr comment "$PR_NUMBER" \
--body "❌ **Release v$VERSION failed**

Please check the workflow logs for details.
🔗 Workflow run: $SERVER_URL/$REPOSITORY/actions/runs/$RUN_ID"
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
VERSION: ${{ steps.package.outputs.version }}
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ jobs:
node-version: [ 16, 18 ]
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
with:
persist-credentials: false
- name: setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e # v1.4.6
with:
node-version: ${{ matrix.node-version }}
- name: Install
Expand Down