Skip to content

Commit 08b2e26

Browse files
committed
feat: release workflow
1 parent 7beee25 commit 08b2e26

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: release
2+
run-name: >-
3+
release `${{ github.event.inputs.version }}` version
4+
${{ github.ref_name != 'main' && format(' on `{0}`', github.ref_name) || '' }}
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Version'
11+
required: true
12+
default: 'patch'
13+
type: choice
14+
options:
15+
- 'major'
16+
- 'minor'
17+
- 'patch'
18+
19+
permissions:
20+
id-token: write # Required for OIDC
21+
contents: read
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
id-token: write # Enable OIDC
28+
pull-requests: write
29+
contents: write
30+
31+
steps:
32+
- uses: actions/checkout@v6
33+
34+
- uses: chainguard-dev/actions/setup-gitsign@main
35+
36+
- uses: pnpm/action-setup@v4
37+
38+
- uses: actions/setup-node@v6
39+
with:
40+
node-version: 24
41+
cache: 'pnpm'
42+
registry-url: 'https://registry.npmjs.org'
43+
44+
- name: Cache node_modules
45+
id: cache-node_modules
46+
uses: actions/cache@v5
47+
with:
48+
path: node_modules
49+
key: pnpm-${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
50+
restore-keys: |
51+
pnpm-${{ runner.os }}-node_modules-
52+
pnpm-${{ runner.os }}-
53+
54+
- name: Install dependencies
55+
if: steps.cache-node_modules.outputs.cache-hit != 'true'
56+
run: |
57+
pnpm install --frozen-lockfile
58+
59+
- name: Setup git
60+
run: |
61+
git config --global tag.gpgsign true
62+
63+
- name: Bump version
64+
run: |
65+
pnpm version ${{ github.event.inputs.version }} --sign-git-tag
66+
67+
- name: Publish to npm
68+
run: |
69+
set -euo pipefail
70+
71+
BRANCH="${GITHUB_REF_NAME}"
72+
73+
if [ "$BRANCH" = "main" ]; then
74+
echo "Branch=$BRANCH, publishing with default dist-tag (latest)"
75+
pnpm publish --access public --provenance
76+
exit 0
77+
fi
78+
79+
if echo "$BRANCH" | grep -Eq '^release/[0-9]+\.[0-9]+$'; then
80+
MM="$(echo "$BRANCH" | sed -E 's|^release/([0-9]+\.[0-9]+)$|\1|')"
81+
TAG="backport-${MM}"
82+
echo "Branch=$BRANCH, publishing with dist-tag $TAG"
83+
pnpm publish --access public --provenance --tag "$TAG"
84+
exit 0
85+
fi
86+
87+
echo "Branch=$BRANCH, publishing with dist-tag next"
88+
pnpm publish --access public --provenance --tag next
89+
90+
- name: Push changes
91+
env:
92+
GH_TOKEN: ${{ github.token }}
93+
run: |
94+
VERSION=$(node -p "require('./package.json').version")
95+
git push --follow-tags
96+
gh release create "v${VERSION}" --generate-notes

0 commit comments

Comments
 (0)