-
Notifications
You must be signed in to change notification settings - Fork 10
setup release GHA workflow #1922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
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 | ||
node -p 'JSON.stringify({ ...require("./jsr.json"), version: require("./package.json").version }, undefined, "\t")' > _jsr.json && mv _jsr.json jsr.json | ||
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 latest release tag using GitHub API | ||
# Use the exit code to determine if a release exists | ||
if LAST_TAG=$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq '.tag_name' 2>/dev/null); then | ||
echo "Previous release found: $LAST_TAG" | ||
else | ||
LAST_TAG="" | ||
echo "No previous releases found - this will be the first release" | ||
fi | ||
|
||
# Generate release notes - only include previous_tag_name if we have a valid previous tag | ||
echo "Generating release notes for tag: v$VERSION" | ||
if [ -n "$LAST_TAG" ]; then | ||
echo "Using previous tag: $LAST_TAG" | ||
RELEASE_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 | ||
echo "Generating notes from all commits" | ||
RELEASE_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 | ||
|
||
# Set release notes as environment variable | ||
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV | ||
echo "$RELEASE_NOTES" >> $GITHUB_ENV | ||
echo "EOF" >> $GITHUB_ENV | ||
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: | | ||
${{ env.RELEASE_NOTES }} | ||
commit-message: "chore: release v${{ steps.version.outputs.version }}" | ||
labels: | | ||
Type: Release | ||
assignees: ${{ github.actor }} | ||
draft: true |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
name: Release | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
- main | ||
types: | ||
- closed | ||
|
||
jobs: | ||
release: | ||
if: | | ||
github.event.pull_request.merged == true && | ||
contains(github.event.pull_request.labels.*.name, 'Type: Release') | ||
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: | | ||
VERSION=$(jq -r '.version' package.json) | ||
PACKAGE_NAME=$(jq -r '.name' package.json) | ||
echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
echo "name=$PACKAGE_NAME" >> $GITHUB_OUTPUT | ||
|
||
- 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: Install latest npm | ||
if: steps.tag-check.outputs.exists == 'false' | ||
run: | | ||
echo "Current npm version: $(npm -v)" | ||
npm install -g npm@latest | ||
echo "Updated npm version: $(npm -v)" | ||
|
||
- name: Install dependencies | ||
if: steps.tag-check.outputs.exists == 'false' | ||
run: npm ci | ||
|
||
- name: Publish to npm with provenance | ||
if: steps.tag-check.outputs.exists == 'false' | ||
run: npm publish --provenance --access public | ||
|
||
- name: Publish to jsr with provenance | ||
if: steps.tag-check.outputs.exists == 'false' | ||
run: npm exec --yes -- jsr publish | ||
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Publish to jsr |
||
|
||
- name: Create GitHub Release with tag | ||
id: create-release | ||
if: steps.tag-check.outputs.exists == 'false' | ||
run: | | ||
RELEASE_URL=$(gh release create "v$VERSION" \ | ||
--title "v$VERSION" \ | ||
--target "$SHA" \ | ||
--notes "$PR_BODY") | ||
echo "url=$RELEASE_URL" >> $GITHUB_OUTPUT | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
VERSION: ${{ steps.package.outputs.version }} | ||
SHA: ${{ github.sha }} | ||
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 }} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update
jsr.json