-
Notifications
You must be signed in to change notification settings - Fork 2
159 lines (136 loc) · 4.24 KB
/
Copy pathrelease.yml
File metadata and controls
159 lines (136 loc) · 4.24 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: "Release version (e.g. 1.2.3 or v1.2.3)"
required: true
type: string
permissions:
contents: write
id-token: write
jobs:
preflight:
name: Preflight
runs-on: ubuntu-latest
outputs:
version: ${{ steps.meta.outputs.version }}
tag: ${{ steps.meta.outputs.tag }}
is_prerelease: ${{ steps.meta.outputs.is_prerelease }}
steps:
- uses: actions/checkout@v4
- id: meta
name: Resolve release version
shell: bash
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
REF_NAME: ${{ github.ref_name }}
EVENT_NAME: ${{ github.event_name }}
run: |
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
raw="$INPUT_VERSION"
else
raw="$REF_NAME"
fi
version="${raw#v}"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
echo "Invalid release version: $raw" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=v$version" >> "$GITHUB_OUTPUT"
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
else
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
fi
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install
- run: pnpm run build
- run: pnpm test
publish:
name: Publish to npm
needs: preflight
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
cache: pnpm
- run: pnpm install
- name: Set package version
env:
RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
run: |
current="$(node -p "require('./package.json').version")"
if [[ "$current" == "$RELEASE_VERSION" ]]; then
echo "package.json already at $RELEASE_VERSION; skipping bump."
else
npm version "$RELEASE_VERSION" --no-git-tag-version
fi
- run: pnpm run build
# Ensure the latest npm is installed
- run: npm install -g npm@latest
- name: Publish to npm
env:
IS_PRERELEASE: ${{ needs.preflight.outputs.is_prerelease }}
run: |
if [[ "$IS_PRERELEASE" == "true" ]]; then
npm publish --provenance --access public --tag next
else
npm publish --provenance --access public
fi
release:
name: GitHub Release
needs: [preflight, publish]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.preflight.outputs.tag }}
name: v${{ needs.preflight.outputs.version }}
generate_release_notes: true
prerelease: ${{ needs.preflight.outputs.is_prerelease }}
update-version:
name: Update package.json version
needs: [preflight, publish]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- name: Bump version in package.json
env:
RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
RELEASE_TAG: ${{ needs.preflight.outputs.tag }}
run: |
npm version "$RELEASE_VERSION" --no-git-tag-version
if git diff --quiet -- package.json; then
echo "No version change needed."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "chore(release): bump version to $RELEASE_TAG"
git push origin HEAD:main