Skip to content

Commit 7a588f7

Browse files
authored
add GitHub actions for release workflow (#18)
1 parent 7fddc65 commit 7a588f7

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

.github/actions/setup/action.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Based on https://github.com/directus/eslint-config/blob/main/.github/actions/setup/action.yml
2+
3+
name: Setup
4+
description: Configure Node.js + pnpm and install dependencies
5+
6+
inputs:
7+
registry:
8+
description: NPM registry to set up for auth
9+
required: false
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version-file: package.json
18+
registry-url: ${{ inputs.registry }}
19+
20+
- name: Setup pnpm
21+
uses: pnpm/action-setup@v4
22+
23+
- name: Get pnpm cache dir
24+
id: pnpm-cache-dir
25+
shell: bash
26+
run: echo "pnpm-cache-dir=$(pnpm store path)" >> $GITHUB_OUTPUT
27+
28+
- name: Setup pnpm cache
29+
uses: actions/cache@v4
30+
with:
31+
path: ${{ steps.pnpm-cache-dir.outputs.pnpm-cache-dir }}
32+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
33+
restore-keys: |
34+
${{ runner.os }}-pnpm-store-
35+
36+
- name: Install dependencies
37+
shell: bash
38+
run: pnpm install

.github/workflows/release.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Based on https://github.com/directus/eslint-config/blob/main/.github/workflows/release.yml
2+
3+
name: Release
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: SemVer for the release, for example "1.0.0"
10+
required: true
11+
type: string
12+
13+
jobs:
14+
check-version:
15+
name: Check Version
16+
runs-on: ubuntu-latest
17+
outputs:
18+
version: ${{ steps.version.outputs.release }}
19+
is-prerelease: ${{ steps.version.outputs.prerelease && true || false }}
20+
steps:
21+
- name: Check version
22+
uses: madhead/semver-utils@v4
23+
id: version
24+
with:
25+
version: ${{ inputs.version }}
26+
lenient: false
27+
28+
create-version:
29+
name: Create Version
30+
needs: check-version
31+
runs-on: ubuntu-latest
32+
permissions:
33+
contents: write
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
38+
- name: Setup env
39+
uses: ./.github/actions/setup
40+
41+
- name: Bump version
42+
run: pnpm version --no-git-tag-version '${{ needs.check-version.outputs.version }}'
43+
44+
- name: Create version commit & tag
45+
run: |
46+
author='${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>'
47+
version='v${{ needs.check-version.outputs.version }}'
48+
branch='${{ github.ref }}'
49+
50+
git config user.name 'github-actions[bot]'
51+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
52+
53+
git commit --all --author "$author" --message "$version"
54+
55+
git tag --annotate "$version" --message "$version"
56+
57+
git push --atomic origin "$branch" "refs/tags/${version}"
58+
59+
create-release:
60+
name: Create Release
61+
needs:
62+
- check-version
63+
- create-version
64+
runs-on: ubuntu-latest
65+
permissions:
66+
contents: write
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v4
70+
71+
- name: Create release
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
run: |
75+
gh release create \
76+
'v${{ needs.check-version.outputs.version }}' \
77+
--verify-tag \
78+
--generate-notes \
79+
${{ needs.check-version.outputs.is-prerelease == 'true' && '--prerelease' || '' }}
80+
81+
publish-npm:
82+
name: Publish to NPM
83+
needs:
84+
- check-version
85+
- create-version
86+
runs-on: ubuntu-latest
87+
permissions:
88+
id-token: write
89+
steps:
90+
- name: Checkout repository
91+
uses: actions/checkout@v4
92+
with:
93+
ref: refs/tags/v${{ needs.check-version.outputs.version }}
94+
95+
- name: Setup env
96+
uses: ./.github/actions/setup
97+
with:
98+
registry: https://registry.npmjs.org
99+
100+
- name: Build
101+
run: pnpm run build
102+
103+
- name: Publish
104+
env:
105+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
106+
NPM_CONFIG_PROVENANCE: true
107+
run: |
108+
pnpm publish \
109+
--access=public \
110+
--no-git-checks \
111+
--tag ${{ needs.check-version.outputs.is-prerelease == 'true' && 'canary' || 'latest' }}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"engines": {
6868
"node": ">=22"
6969
},
70+
"packageManager": "[email protected]",
7071
"pnpm": {
7172
"onlyBuiltDependencies": [
7273
"esbuild"

0 commit comments

Comments
 (0)