Skip to content

Commit a0941c6

Browse files
authored
setup release GHA workflow (#1922)
1 parent b95abf0 commit a0941c6

File tree

4 files changed

+244
-57
lines changed

4 files changed

+244
-57
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Create Release PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version type'
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
jobs:
16+
create-release-pr:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
24+
with:
25+
persist-credentials: false
26+
27+
- name: Configure Git
28+
run: |
29+
git config user.name "github-actions[bot]"
30+
git config user.email "github-actions[bot]@users.noreply.github.com"
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
34+
with:
35+
node-version: 'lts/*'
36+
37+
# No need to install dependencies - npm version works without them
38+
- name: Version bump
39+
id: version
40+
run: |
41+
npm version "$VERSION_TYPE" --no-git-tag-version
42+
node -p 'JSON.stringify({ ...require("./jsr.json"), version: require("./package.json").version }, undefined, "\t")' > _jsr.json && mv _jsr.json jsr.json
43+
VERSION=$(jq -r '.version' package.json)
44+
echo "version=$VERSION" >> $GITHUB_OUTPUT
45+
env:
46+
VERSION_TYPE: ${{ github.event.inputs.version }}
47+
48+
- name: Get release notes
49+
id: release-notes
50+
run: |
51+
# Get the default branch
52+
DEFAULT_BRANCH=$(gh api "repos/$GITHUB_REPOSITORY" --jq '.default_branch')
53+
54+
# Get the latest release tag using GitHub API
55+
# Use the exit code to determine if a release exists
56+
if LAST_TAG=$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq '.tag_name' 2>/dev/null); then
57+
echo "Previous release found: $LAST_TAG"
58+
else
59+
LAST_TAG=""
60+
echo "No previous releases found - this will be the first release"
61+
fi
62+
63+
# Generate release notes - only include previous_tag_name if we have a valid previous tag
64+
echo "Generating release notes for tag: v$VERSION"
65+
if [ -n "$LAST_TAG" ]; then
66+
echo "Using previous tag: $LAST_TAG"
67+
RELEASE_NOTES=$(gh api \
68+
--method POST \
69+
-H "Accept: application/vnd.github+json" \
70+
"/repos/$GITHUB_REPOSITORY/releases/generate-notes" \
71+
-f "tag_name=v$VERSION" \
72+
-f "target_commitish=$DEFAULT_BRANCH" \
73+
-f "previous_tag_name=$LAST_TAG" \
74+
--jq '.body')
75+
else
76+
echo "Generating notes from all commits"
77+
RELEASE_NOTES=$(gh api \
78+
--method POST \
79+
-H "Accept: application/vnd.github+json" \
80+
"/repos/$GITHUB_REPOSITORY/releases/generate-notes" \
81+
-f "tag_name=v$VERSION" \
82+
-f "target_commitish=$DEFAULT_BRANCH" \
83+
--jq '.body')
84+
fi
85+
86+
# Set release notes as environment variable
87+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
88+
echo "$RELEASE_NOTES" >> $GITHUB_ENV
89+
echo "EOF" >> $GITHUB_ENV
90+
env:
91+
GH_TOKEN: ${{ github.token }}
92+
VERSION: ${{ steps.version.outputs.version }}
93+
GITHUB_REPOSITORY: ${{ github.repository }}
94+
95+
- name: Create Pull Request
96+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
97+
with:
98+
branch: release/v${{ steps.version.outputs.version }}
99+
delete-branch: true
100+
title: "Release v${{ steps.version.outputs.version }}"
101+
body: |
102+
${{ env.RELEASE_NOTES }}
103+
commit-message: "chore: release v${{ steps.version.outputs.version }}"
104+
labels: |
105+
Type: Release
106+
assignees: ${{ github.actor }}
107+
draft: true

.github/workflows/publish.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- main
8+
types:
9+
- closed
10+
11+
jobs:
12+
release:
13+
if: |
14+
github.event.pull_request.merged == true &&
15+
contains(github.event.pull_request.labels.*.name, 'Type: Release')
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
id-token: write # OIDC
20+
pull-requests: write # PR comment
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
24+
with:
25+
persist-credentials: false
26+
27+
- name: Get package info
28+
id: package
29+
run: |
30+
VERSION=$(jq -r '.version' package.json)
31+
PACKAGE_NAME=$(jq -r '.name' package.json)
32+
echo "version=$VERSION" >> $GITHUB_OUTPUT
33+
echo "name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
34+
35+
- name: Check if tag exists
36+
id: tag-check
37+
run: |
38+
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
39+
echo "exists=true" >> $GITHUB_OUTPUT
40+
else
41+
echo "exists=false" >> $GITHUB_OUTPUT
42+
fi
43+
env:
44+
VERSION: ${{ steps.package.outputs.version }}
45+
46+
- name: Setup Node.js
47+
if: steps.tag-check.outputs.exists == 'false'
48+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
49+
with:
50+
node-version: 'lts/*'
51+
registry-url: 'https://registry.npmjs.org'
52+
53+
- name: Install latest npm
54+
if: steps.tag-check.outputs.exists == 'false'
55+
run: |
56+
echo "Current npm version: $(npm -v)"
57+
npm install -g npm@latest
58+
echo "Updated npm version: $(npm -v)"
59+
60+
- name: Install dependencies
61+
if: steps.tag-check.outputs.exists == 'false'
62+
run: npm ci
63+
64+
- name: Publish to npm with provenance
65+
if: steps.tag-check.outputs.exists == 'false'
66+
run: npm publish --provenance --access public
67+
68+
- name: Publish to jsr with provenance
69+
if: steps.tag-check.outputs.exists == 'false'
70+
run: npm exec --yes -- jsr publish
71+
72+
- name: Create GitHub Release with tag
73+
id: create-release
74+
if: steps.tag-check.outputs.exists == 'false'
75+
run: |
76+
RELEASE_URL=$(gh release create "v$VERSION" \
77+
--title "v$VERSION" \
78+
--target "$SHA" \
79+
--notes "$PR_BODY")
80+
echo "url=$RELEASE_URL" >> $GITHUB_OUTPUT
81+
env:
82+
GH_TOKEN: ${{ github.token }}
83+
VERSION: ${{ steps.package.outputs.version }}
84+
SHA: ${{ github.sha }}
85+
PR_BODY: ${{ github.event.pull_request.body }}
86+
87+
- name: Comment on PR - Success
88+
if: |
89+
always() &&
90+
github.event_name == 'pull_request' &&
91+
steps.tag-check.outputs.exists == 'false' &&
92+
success()
93+
run: |
94+
gh pr comment "$PR_NUMBER" \
95+
--body "✅ **Release v$VERSION completed successfully!**
96+
97+
- 📦 npm package: https://www.npmjs.com/package/$PACKAGE_NAME/v/$VERSION
98+
- 🏷️ GitHub Release: $RELEASE_URL
99+
- 🔗 Workflow run: $SERVER_URL/$REPOSITORY/actions/runs/$RUN_ID"
100+
env:
101+
GH_TOKEN: ${{ github.token }}
102+
PR_NUMBER: ${{ github.event.pull_request.number }}
103+
VERSION: ${{ steps.package.outputs.version }}
104+
PACKAGE_NAME: ${{ steps.package.outputs.name }}
105+
RELEASE_URL: ${{ steps.create-release.outputs.url }}
106+
SERVER_URL: ${{ github.server_url }}
107+
REPOSITORY: ${{ github.repository }}
108+
RUN_ID: ${{ github.run_id }}
109+
110+
- name: Comment on PR - Failure
111+
if: |
112+
always() &&
113+
github.event_name == 'pull_request' &&
114+
steps.tag-check.outputs.exists == 'false' &&
115+
failure()
116+
run: |
117+
gh pr comment "$PR_NUMBER" \
118+
--body "❌ **Release v$VERSION failed**
119+
120+
Please check the workflow logs for details.
121+
🔗 Workflow run: $SERVER_URL/$REPOSITORY/actions/runs/$RUN_ID"
122+
env:
123+
GH_TOKEN: ${{ github.token }}
124+
PR_NUMBER: ${{ github.event.pull_request.number }}
125+
VERSION: ${{ steps.package.outputs.version }}
126+
SERVER_URL: ${{ github.server_url }}
127+
REPOSITORY: ${{ github.repository }}
128+
RUN_ID: ${{ github.run_id }}

.vscode/settings.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"cSpell.words": [
3+
"backquote",
4+
"biomejs",
5+
"commitish",
6+
"coord",
37
"decos",
4-
"helpfeel",
8+
"fuga",
59
"gyazo",
6-
"coord",
7-
"progfay",
8-
"scrapbox",
9-
"backquote",
10+
"helpfeel",
1011
"hoge",
11-
"fuga",
1212
"piyo",
13-
"tsbuildinfo",
14-
"biomejs"
13+
"progfay",
14+
"scrapbox",
15+
"tsbuildinfo"
1516
],
1617
"editor.defaultFormatter": "biomejs.biome",
1718
"editor.formatOnSave": true

0 commit comments

Comments
 (0)