-
Notifications
You must be signed in to change notification settings - Fork 1
305 lines (269 loc) · 10.5 KB
/
Copy pathpublish-cli.yml
File metadata and controls
305 lines (269 loc) · 10.5 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: Publish CLI
on:
push:
branches:
- main
workflow_dispatch:
inputs:
dry_run:
description: Validate the next official beta release without publishing or tagging
required: false
type: boolean
default: false
concurrency:
group: publish-cli-${{ github.event_name }}
cancel-in-progress: false
jobs:
publish-dev:
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
persist-credentials: false
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Enable pnpm
run: |
corepack enable
PNPM_VERSION="$(node -p 'const pm = require("./package.json").packageManager; const match = pm && pm.match(/^pnpm@(.+)$/); if (!match) throw new Error("packageManager must be pnpm@<version>"); match[1]')"
corepack prepare "pnpm@${PNPM_VERSION}" --activate
echo "PNPM_STORE_PATH=$(pnpm store path)" >> "$GITHUB_ENV"
- name: Cache pnpm store
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
with:
path: ${{ env.PNPM_STORE_PATH }}
key: pnpm-store-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
pnpm-store-${{ runner.os }}-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Resolve dev version
id: cli_version
run: |
node scripts/resolve-cli-version.mjs dev \
--run-number "${GITHUB_RUN_NUMBER}" \
--run-attempt "${GITHUB_RUN_ATTEMPT}" >> "$GITHUB_OUTPUT"
- name: Fail if version already exists on npm
run: |
PACKAGE='@prisma/cli'
VERSION='${{ steps.cli_version.outputs.version }}'
if npm view "${PACKAGE}@${VERSION}" version >/dev/null 2>&1; then
echo "${PACKAGE}@${VERSION} already exists on npm."
exit 1
fi
- name: Run focused CLI tests
run: pnpm --filter @prisma/cli test
- name: Build CLI package
run: pnpm --filter @prisma/cli build
- name: Prepare staged publish package
run: node scripts/prepare-cli-publish.mjs .publish/cli --version '${{ steps.cli_version.outputs.version }}'
- name: Audit staged package contents
working-directory: .publish/cli
run: |
PACK_JSON="$(npm pack --dry-run --json)"
PACK_JSON="${PACK_JSON}" node -e "
const pack = JSON.parse(process.env.PACK_JSON)[0]
const files = pack.files.map((file) => file.path).sort()
const forbidden = files.filter((file) =>
file.startsWith('src/') ||
file.startsWith('tests/') ||
file.startsWith('fixtures/') ||
file.startsWith('docs/') ||
file.startsWith('.prisma/') ||
file.startsWith('.publish/')
)
if (forbidden.length) {
console.error('Forbidden files in npm package:', forbidden.join(', '))
process.exit(1)
}
for (const required of ['dist/cli.js', 'README.md', 'LICENSE', 'package.json']) {
if (!files.includes(required)) {
console.error('Missing required package file:', required)
process.exit(1)
}
}
"
- name: Smoke test staged tarball install
run: |
TARBALL="$(cd .publish/cli && npm pack --silent)"
TMPDIR="$(mktemp -d)"
cat > "${TMPDIR}/package.json" <<'EOF'
{
"name": "cli-publish-smoke",
"private": true
}
EOF
pnpm add -D "${PWD}/.publish/cli/${TARBALL}" --dir "${TMPDIR}"
(
cd "${TMPDIR}"
pnpm prisma-cli --help
pnpm prisma-cli auth whoami --json
)
- name: Publish dev package to npm
working-directory: .publish/cli
run: npm publish --access public --tag dev --provenance
- name: Summarize dev publish
run: |
VERSION='${{ steps.cli_version.outputs.version }}'
{
echo "## Publish CLI Dev"
echo
echo "- npm package: \`@prisma/cli@${VERSION}\`"
echo "- npm dist-tag: \`dev\`"
} >> "$GITHUB_STEP_SUMMARY"
publish-official:
if: ${{ github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Ensure workflow runs from main
run: |
if [ "${GITHUB_REF}" != "refs/heads/main" ]; then
echo "This workflow only publishes official releases from main."
exit 1
fi
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Enable pnpm
run: |
corepack enable
PNPM_VERSION="$(node -p 'const pm = require("./package.json").packageManager; const match = pm && pm.match(/^pnpm@(.+)$/); if (!match) throw new Error("packageManager must be pnpm@<version>"); match[1]')"
corepack prepare "pnpm@${PNPM_VERSION}" --activate
echo "PNPM_STORE_PATH=$(pnpm store path)" >> "$GITHUB_ENV"
- name: Cache pnpm store
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
with:
path: ${{ env.PNPM_STORE_PATH }}
key: pnpm-store-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
pnpm-store-${{ runner.os }}-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Resolve next beta version
id: cli_version
run: |
PACKAGE='@prisma/cli'
LATEST="$(npm view "${PACKAGE}" dist-tags.latest --silent 2>/dev/null || true)"
node scripts/resolve-cli-version.mjs next-beta --latest "${LATEST}" >> "$GITHUB_OUTPUT"
- name: Fail if version already exists on npm
run: |
PACKAGE='@prisma/cli'
VERSION='${{ steps.cli_version.outputs.version }}'
if npm view "${PACKAGE}@${VERSION}" version >/dev/null 2>&1; then
echo "${PACKAGE}@${VERSION} already exists on npm."
exit 1
fi
- name: Fail if release tag already exists
run: |
VERSION='${{ steps.cli_version.outputs.version }}'
TAG="cli-v${VERSION}"
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
echo "Release tag ${TAG} already exists."
exit 1
fi
- name: Run focused CLI tests
run: pnpm --filter @prisma/cli test
- name: Build CLI package
run: pnpm --filter @prisma/cli build
- name: Prepare staged publish package
run: node scripts/prepare-cli-publish.mjs .publish/cli --version '${{ steps.cli_version.outputs.version }}'
- name: Audit staged package contents
working-directory: .publish/cli
run: |
PACK_JSON="$(npm pack --dry-run --json)"
PACK_JSON="${PACK_JSON}" node -e "
const pack = JSON.parse(process.env.PACK_JSON)[0]
const files = pack.files.map((file) => file.path).sort()
const forbidden = files.filter((file) =>
file.startsWith('src/') ||
file.startsWith('tests/') ||
file.startsWith('fixtures/') ||
file.startsWith('docs/') ||
file.startsWith('.prisma/') ||
file.startsWith('.publish/')
)
if (forbidden.length) {
console.error('Forbidden files in npm package:', forbidden.join(', '))
process.exit(1)
}
for (const required of ['dist/cli.js', 'README.md', 'LICENSE', 'package.json']) {
if (!files.includes(required)) {
console.error('Missing required package file:', required)
process.exit(1)
}
}
"
- name: Smoke test staged tarball install
run: |
TARBALL="$(cd .publish/cli && npm pack --silent)"
TMPDIR="$(mktemp -d)"
cat > "${TMPDIR}/package.json" <<'EOF'
{
"name": "cli-publish-smoke",
"private": true
}
EOF
pnpm add -D "${PWD}/.publish/cli/${TARBALL}" --dir "${TMPDIR}"
(
cd "${TMPDIR}"
pnpm prisma-cli --help
pnpm prisma-cli auth whoami --json
)
- name: Ensure release still targets the latest main
if: ${{ !inputs.dry_run }}
run: |
git fetch origin main
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
echo "main moved while the release was running. Rerun the workflow from the latest main."
exit 1
fi
- name: Publish official package to npm
if: ${{ !inputs.dry_run }}
working-directory: .publish/cli
run: npm publish --access public --tag latest --provenance
- name: Create release tag
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION='${{ steps.cli_version.outputs.version }}'
TAG="cli-v${VERSION}"
SHA="$(git rev-parse HEAD)"
gh api \
--method POST \
"repos/${GITHUB_REPOSITORY}/git/refs" \
-f ref="refs/tags/${TAG}" \
-f sha="${SHA}"
- name: Summarize release
run: |
VERSION='${{ steps.cli_version.outputs.version }}'
LATEST='${{ steps.cli_version.outputs.latest }}'
{
echo "## Publish CLI Official"
echo
echo "- Previous npm latest: \`${LATEST:-none}\`"
echo "- Version: \`${VERSION}\`"
echo "- Dry run: \`${{ inputs.dry_run }}\`"
if [ '${{ inputs.dry_run }}' = 'true' ]; then
echo "- Publish: skipped"
echo "- Tag creation: skipped"
else
echo "- npm package: \`@prisma/cli@${VERSION}\`"
echo "- npm dist-tag: \`latest\`"
echo "- git tag: \`cli-v${VERSION}\`"
fi
} >> "$GITHUB_STEP_SUMMARY"