Repository navigation
222 lines (214 loc) · 8.81 KB
/
Copy pathrelease.yml
File metadata and controls
222 lines (214 loc) · 8.81 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
commit:
description:
"Optional 40-character version-bump commit SHA reachable from the
selected ref"
required: false
type: string
concurrency:
group: ${{ github.workflow }}
queue: max
cancel-in-progress: false
permissions: {}
env:
NODE_VERSION: "24.22.1"
jobs:
plan:
if: github.repository_owner == 'convex'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
outputs:
sha: ${{ steps.select.outputs.sha }}
name: ${{ steps.select.outputs.name }}
version: ${{ steps.select.outputs.version }}
channel: ${{ steps.select.outputs.channel }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- id: select
name: Select the latest version-bump commit
env:
RELEASE_COMMIT: ${{ inputs.commit }}
run: |
if [[ "$GITHUB_EVENT_NAME" == workflow_dispatch ]]; then
source="${RELEASE_COMMIT:-$GITHUB_SHA}"
[[ "$source" =~ ^[0-9a-f]{40}$ ]] || { echo 'Expected a 40-character commit SHA' >&2; exit 1; }
git merge-base --is-ancestor "$source" "$GITHUB_SHA"
else
before=$(jq -r .before "$GITHUB_EVENT_PATH")
source=''
candidates=$(git rev-list --first-parent "$before..$GITHUB_SHA" -- package.json)
while read -r candidate && [[ -n "$candidate" ]]; do
current=$(git show "$candidate:package.json" | jq -r .version)
previous=$(git show "$candidate^1:package.json" | jq -r .version)
if [[ "$current" != "$previous" ]]; then source="$candidate"; break; fi
done <<< "$candidates"
if [[ -z "$source" ]]; then echo 'No version bump'; exit 0; fi
fi
name=$(git show "$source:package.json" | jq -r .name)
VERSION=$(git show "$source:package.json" | jq -r .version)
PREVIOUS_VERSION=$(git show "$source^1:package.json" | jq -r .version)
export VERSION PREVIOUS_VERSION
node --input-type=module <<'NODE'
import { execFileSync } from 'node:child_process';
import { appendFileSync } from 'node:fs';
import { createRequire } from 'node:module';
// Use the standard SemVer library bundled with the pinned npm.
const npmRoot = execFileSync('npm', ['root', '-g'], { encoding: 'utf8' }).trim();
const semver = createRequire(`${npmRoot}/npm/package.json`)('semver');
const { VERSION: version, PREVIOUS_VERSION: previous, GITHUB_REF: ref } = process.env;
if (semver.valid(version) !== version || !semver.gt(version, previous)) throw new Error('Selected commit must increase the package version');
const pre = semver.prerelease(version);
const channel = pre ? String(pre[0]) : 'latest';
if (pre && (!/^[a-z][a-z0-9-]*$/.test(channel) || channel === 'latest' || semver.validRange(channel))) throw new Error('Invalid prerelease channel');
if (!pre && ref !== 'refs/heads/main') throw new Error('Stable releases require main');
appendFileSync(process.env.GITHUB_OUTPUT, `channel=${channel}\n`);
NODE
tag="v$VERSION"
if git show-ref --verify --quiet "refs/tags/$tag"; then
if [[ "$GITHUB_EVENT_NAME" != workflow_dispatch ]]; then
echo "$tag was already staged; skipping automatic release"
exit 0
fi
[[ "$(git rev-parse "$tag^{commit}")" == "$source" ]] || { echo "$tag points elsewhere" >&2; exit 1; }
fi
{
echo "sha=$source"
echo "name=$name"
echo "version=$VERSION"
} >> "$GITHUB_OUTPUT"
build:
needs: plan
if: needs.plan.outputs.sha != ''
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
outputs:
artifact_id: ${{ steps.upload.outputs.artifact-id }}
sha256: ${{ steps.digest.outputs.sha256 }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ needs.plan.outputs.sha }}
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- run: npm ci
- name: Validate release notes
run: |
# Compare against this checkout while reading all notes, including prerelease state.
git update-ref refs/heads/main HEAD
npx changeset status --output "$RUNNER_TEMP/changesets.json"
jq -e '.changesets | length == 0' "$RUNNER_TEMP/changesets.json"
version=$(jq -r .version package.json)
awk -v version="$version" '/^## / { active=($0 == "## " version); next } active && !/^#/ && /[[:alnum:]]/ { found=1 } END { exit !found }' CHANGELOG.md
- run: npm run build
- run: npm run check
- name: Run E2E tests and verify generated code
env:
CONVEX_AGENT_MODE: anonymous
CONVEX_DISABLE_TELEMETRY: "1"
run: |
npm run test:e2e
git diff --exit-code -- src/component/_generated
test -z "$(git ls-files --others --exclude-standard src/component/_generated)"
- name: Pack the tested package
run: |
mkdir -p "$RUNNER_TEMP/npm-release"
npm pack --ignore-scripts --pack-destination "$RUNNER_TEMP/npm-release"
- id: digest
run:
echo "sha256=$(sha256sum "$RUNNER_TEMP"/npm-release/*.tgz | cut -d ' '
-f 1)" >> "$GITHUB_OUTPUT"
- id: upload
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: npm-release-${{ needs.plan.outputs.sha }}
path: ${{ runner.temp }}/npm-release/*.tgz
if-no-files-found: error
stage:
needs: [plan, build]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
id-token: write
steps:
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
artifact-ids: ${{ needs.build.outputs.artifact_id }}
path: ${{ runner.temp }}/npm-release
merge-multiple: true
- name: Stage the tested artifact
env:
SOURCE_SHA: ${{ needs.plan.outputs.sha }}
PACKAGE_NAME: ${{ needs.plan.outputs.name }}
VERSION: ${{ needs.plan.outputs.version }}
CHANNEL: ${{ needs.plan.outputs.channel }}
EXPECTED_SHA256: ${{ needs.build.outputs.sha256 }}
run: |
set -o pipefail
set -- "$RUNNER_TEMP"/npm-release/*.tgz
test "$#" -eq 1
TARBALL="$1"
echo "$EXPECTED_SHA256 $TARBALL" | sha256sum -c -
{
echo "$PACKAGE_NAME@$VERSION — source $SOURCE_SHA — npm channel $CHANNEL"
echo "Review on npm's Staged Packages page, then approve with 2FA or npm stage approve <stage-id>."
} >> "$GITHUB_STEP_SUMMARY"
# npm reads GITHUB_SHA for provenance; checkout alone does not change it.
GITHUB_SHA="$SOURCE_SHA" npm stage publish "$TARBALL" \
--ignore-scripts --provenance --access public --tag "$CHANNEL" \
2>&1 | tee "$RUNNER_TEMP/npm-stage.log"
- name: Preserve staging output and stage ID
if: always()
run: |
if test -f "$RUNNER_TEMP/npm-stage.log"; then
cat "$RUNNER_TEMP/npm-stage.log" >> "$GITHUB_STEP_SUMMARY"
fi
tag:
needs: [plan, stage]
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ needs.plan.outputs.sha }}
fetch-depth: 0
persist-credentials: false
- name: Tag the staged source
env:
GH_TOKEN: ${{ github.token }}
SOURCE_SHA: ${{ needs.plan.outputs.sha }}
VERSION: ${{ needs.plan.outputs.version }}
run: |
tag="v$VERSION"
if git show-ref --verify --quiet "refs/tags/$tag"; then
test "$(git rev-parse "$tag^{commit}")" = "$SOURCE_SHA"
else
git tag "$tag" "$SOURCE_SHA"
gh auth setup-git
git push origin "refs/tags/$tag"
fi