Skip to content

Commit 22d62e1

Browse files
committed
ci: release workflow
1 parent 3ae28d7 commit 22d62e1

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+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to release (e.g. v1.1.0)'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
id-token: write
14+
15+
concurrency:
16+
group: release
17+
18+
jobs:
19+
release:
20+
runs-on: ubuntu-latest
21+
environment: release
22+
steps:
23+
- name: Validate version
24+
id: version
25+
run: |
26+
VERSION="${{ inputs.version }}"
27+
VERSION="${VERSION#v}"
28+
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
29+
echo "::error::Invalid semver: $VERSION"
30+
exit 1
31+
fi
32+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
33+
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
with:
37+
ref: main
38+
fetch-depth: 0
39+
40+
- name: Setup Bun
41+
uses: oven-sh/setup-bun@v2
42+
43+
- name: Setup just
44+
uses: extractions/setup-just@v2
45+
46+
- name: Setup Node
47+
uses: actions/setup-node@v4
48+
with:
49+
node-version: '22'
50+
registry-url: 'https://registry.npmjs.org'
51+
52+
- name: Install dependencies
53+
run: bun install --frozen-lockfile
54+
55+
- name: Run checks
56+
run: just check
57+
58+
- name: Bump version and tag
59+
run: |
60+
ver_gt() {
61+
IFS='.' read -r maj1 min1 pat1 <<< "$1"
62+
IFS='.' read -r maj2 min2 pat2 <<< "$2"
63+
[ "$maj1" -gt "$maj2" ] && return 0
64+
[ "$maj1" -lt "$maj2" ] && return 1
65+
[ "$min1" -gt "$min2" ] && return 0
66+
[ "$min1" -lt "$min2" ] && return 1
67+
[ "$pat1" -gt "$pat2" ] && return 0
68+
return 1
69+
}
70+
CURRENT=$(jq -r .version package.json)
71+
NEW="${{ steps.version.outputs.version }}"
72+
if [ "$NEW" = "$CURRENT" ] || ! ver_gt "$NEW" "$CURRENT"; then
73+
echo "::error::New version ($NEW) must be greater than current ($CURRENT)"
74+
exit 1
75+
fi
76+
jq --arg v "$NEW" '.version = $v' package.json > package.json.tmp
77+
mv package.json.tmp package.json
78+
git config user.name 'github-actions[bot]'
79+
git config user.email 'github-actions[bot]@users.noreply.github.com'
80+
git add package.json
81+
git commit -m "release: v$NEW"
82+
git tag "v$NEW"
83+
84+
- name: Publish
85+
run: npm publish --provenance --access public
86+
87+
- name: Push and release
88+
run: |
89+
git push origin main --follow-tags
90+
gh release create "v${{ steps.version.outputs.version }}" \
91+
--repo "$GITHUB_REPOSITORY" \
92+
--target main \
93+
--generate-notes \
94+
--title "v${{ steps.version.outputs.version }}"
95+
env:
96+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)