-
Notifications
You must be signed in to change notification settings - Fork 2
99 lines (83 loc) · 3.29 KB
/
Copy pathrelease.yml
File metadata and controls
99 lines (83 loc) · 3.29 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:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- run: bun install
- run: bun run typecheck
- run: bun run build
- name: Run tests
run: bun run test
- name: Check release state
id: release_state
env:
GH_TOKEN: ${{ github.token }}
run: |
package_name="$(node -p "require('./package.json').name")"
package_version="$(node -p "require('./package.json').version")"
echo "package_name=${package_name}" >> "$GITHUB_OUTPUT"
echo "package_version=${package_version}" >> "$GITHUB_OUTPUT"
if npm view "${package_name}@${package_version}" version >/dev/null 2>&1; then
echo "npm_published=true" >> "$GITHUB_OUTPUT"
else
echo "npm_published=false" >> "$GITHUB_OUTPUT"
fi
if gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1; then
echo "github_release_exists=true" >> "$GITHUB_OUTPUT"
else
echo "github_release_exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup Node.js for npm publish
if: steps.release_state.outputs.npm_published == 'false'
uses: actions/setup-node@v5
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- name: Publish to npm
if: steps.release_state.outputs.npm_published == 'false'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Skip npm publish
if: steps.release_state.outputs.npm_published == 'true'
run: |
echo "${{ steps.release_state.outputs.package_name }}@${{ steps.release_state.outputs.package_version }} is already published; skipping npm publish."
- name: Extract changelog for release
if: steps.release_state.outputs.github_release_exists == 'false'
id: changelog
run: |
version="${GITHUB_REF_NAME#v}"
# Extract the changelog section for this version.
# Use index() string match, not a regex: the version contains a literal "["
# that a regex would interpret as a character class, matching wrong sections.
body=$(awk -v needle="## [${version}]" '
index($0, needle) == 1 && (length($0) == length(needle) || substr($0, length(needle)+1, 1) ~ /[ -]/) { found=1; next }
/^## \[/ && found { exit }
found { print }
' docs/CHANGELOG.md)
echo "body<<EOF" >> "$GITHUB_OUTPUT"
echo "$body" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
if: steps.release_state.outputs.github_release_exists == 'false'
uses: softprops/action-gh-release@v3
with:
body: ${{ steps.changelog.outputs.body }}
generate_release_notes: true
- name: Skip GitHub Release
if: steps.release_state.outputs.github_release_exists == 'true'
run: |
echo "GitHub release ${GITHUB_REF_NAME} already exists; skipping release creation."