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