-
Notifications
You must be signed in to change notification settings - Fork 0
360 lines (313 loc) · 12.3 KB
/
Copy pathpublish-npm.yml
File metadata and controls
360 lines (313 loc) · 12.3 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
name: Publish NPM Packages
on:
workflow_dispatch:
inputs:
package:
description: "Package to publish"
required: true
type: choice
options:
- all
- types
- server
- sdk-typescript
- cli
- mcp
- react
- openclaw
default: "all"
version:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
- prepatch
- preminor
- premajor
- prerelease
custom_version:
description: "Custom version (optional, overrides version type)"
required: false
type: string
dry_run:
description: "Dry run (do not actually publish)"
required: false
type: boolean
default: false
tag:
description: "NPM dist-tag"
required: false
type: choice
options:
- latest
- next
- beta
- alpha
default: "latest"
# Prevent concurrent publishes
concurrency:
group: publish-package
cancel-in-progress: false
permissions:
contents: write
id-token: write
env:
NPM_CONFIG_FUND: false
jobs:
# Build all packages, version them, run tests
build:
name: Build & Version
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump.outputs.new_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22.14.0"
cache: "npm"
cache-dependency-path: package-lock.json
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- name: Version all packages
id: bump
run: |
CUSTOM_VERSION="${{ github.event.inputs.custom_version }}"
VERSION_TYPE="${{ github.event.inputs.version }}"
# Read current version from types (canonical source)
CURRENT_VERSION=$(node -p "require('./packages/types/package.json').version")
echo "Current version: $CURRENT_VERSION"
if [ -n "$CUSTOM_VERSION" ]; then
NEW_VERSION="$CUSTOM_VERSION"
echo "Setting version to custom value: $NEW_VERSION"
else
# Use npm version on types to compute the new version
cd packages/types
npm version "$VERSION_TYPE" --no-git-tag-version --preid=beta
NEW_VERSION=$(node -p "require('./package.json').version")
cd ../..
echo "Bumped version: $VERSION_TYPE -> $NEW_VERSION"
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
# Sync all package versions and internal dependencies
node -e "
const fs = require('fs');
const path = require('path');
const version = '$NEW_VERSION';
const packagesDir = 'packages';
for (const dir of fs.readdirSync(packagesDir)) {
const pkgPath = path.join(packagesDir, dir, 'package.json');
if (fs.existsSync(pkgPath)) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
pkg.version = version;
// Update @relaycast/* dependencies to exact version
for (const depType of ['dependencies', 'devDependencies', 'peerDependencies']) {
for (const dep of Object.keys(pkg[depType] || {})) {
if (dep.startsWith('@relaycast/')) {
pkg[depType][dep] = version;
}
}
}
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
console.log(pkg.name + '@' + version);
}
}
// Sync package version constants
const sdkVersionPath = path.join(packagesDir, 'sdk-typescript', 'src', 'version.ts');
fs.writeFileSync(sdkVersionPath, 'export const SDK_VERSION = ' + JSON.stringify(version) + ' as const;\\n');
console.log('SDK_VERSION -> ' + version);
const cliVersionPath = path.join(packagesDir, 'cli', 'src', 'version.ts');
if (fs.existsSync(cliVersionPath)) {
fs.writeFileSync(cliVersionPath, 'export const CLI_VERSION = ' + JSON.stringify(version) + ' as const;\\n');
console.log('CLI_VERSION -> ' + version);
}
"
- name: Clean reinstall after version bump
run: |
rm -rf node_modules packages/*/node_modules package-lock.json
npm install
- name: Build all packages
run: npx turbo build
- name: Run tests
run: npx turbo test
env:
DO_NOT_TRACK: '1'
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-output
path: |
package.json
package-lock.json
packages/*/package.json
packages/*/dist/
retention-days: 1
# Publish all packages in parallel
publish-packages:
name: Publish ${{ matrix.package }}
needs: build
runs-on: ubuntu-latest
if: github.event.inputs.package == 'all'
strategy:
fail-fast: false
max-parallel: 5
matrix:
package:
- types
- server
- sdk-typescript
- cli
- mcp
- react
- openclaw
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22.14.0"
registry-url: "https://registry.npmjs.org"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output
path: .
- name: Update npm for OIDC support
run: npm install -g npm@latest
- name: Dry run check
if: github.event.inputs.dry_run == 'true'
working-directory: packages/${{ matrix.package }}
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
echo "Dry run - would publish ${PACKAGE_NAME}@${{ needs.build.outputs.new_version }}"
npm publish --dry-run --access public --tag ${{ github.event.inputs.tag }} --ignore-scripts
- name: Publish to NPM
if: github.event.inputs.dry_run != 'true'
working-directory: packages/${{ matrix.package }}
run: npm publish --access public --provenance --tag ${{ github.event.inputs.tag }} --ignore-scripts
# Publish a single package (when not "all")
publish-single:
name: Publish Single Package
needs: build
runs-on: ubuntu-latest
if: github.event.inputs.package != 'all'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22.14.0"
registry-url: "https://registry.npmjs.org"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output
path: .
- name: Update npm for OIDC support
run: npm install -g npm@latest
- name: Dry run check
if: github.event.inputs.dry_run == 'true'
working-directory: packages/${{ github.event.inputs.package }}
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
echo "Dry run - would publish ${PACKAGE_NAME}@${{ needs.build.outputs.new_version }}"
npm publish --dry-run --access public --tag ${{ github.event.inputs.tag }} --ignore-scripts
- name: Publish to NPM
if: github.event.inputs.dry_run != 'true'
working-directory: packages/${{ github.event.inputs.package }}
run: npm publish --access public --provenance --tag ${{ github.event.inputs.tag }} --ignore-scripts
# Create git tag and release
create-release:
name: Create Release
needs: [build, publish-packages, publish-single]
runs-on: ubuntu-latest
if: |
always() &&
github.event.inputs.dry_run != 'true' &&
needs.build.result == 'success' &&
(needs.publish-packages.result == 'success' || needs.publish-single.result == 'success')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output
path: .
- name: Commit and tag
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
NEW_VERSION="${{ needs.build.outputs.new_version }}"
git add package.json package-lock.json packages/*/package.json
if ! git diff --staged --quiet; then
git commit -m "chore(release): v${NEW_VERSION}"
git push origin HEAD:main
fi
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
git push origin "v${NEW_VERSION}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.build.outputs.new_version }}
name: v${{ needs.build.outputs.new_version }}
body: |
## Relaycast v${{ needs.build.outputs.new_version }}
### Install
```bash
npm install @relaycast/sdk@${{ needs.build.outputs.new_version }}
npm install @relaycast/cli@${{ needs.build.outputs.new_version }}
npm install @relaycast/react@${{ needs.build.outputs.new_version }}
npm install @relaycast/mcp@${{ needs.build.outputs.new_version }}
npm install @relaycast/openclaw@${{ needs.build.outputs.new_version }}
```
### Packages
| Package | Version |
|---------|---------|
| @relaycast/types | ${{ needs.build.outputs.new_version }} |
| @relaycast/server | ${{ needs.build.outputs.new_version }} |
| @relaycast/sdk | ${{ needs.build.outputs.new_version }} |
| @relaycast/cli | ${{ needs.build.outputs.new_version }} |
| @relaycast/mcp | ${{ needs.build.outputs.new_version }} |
| @relaycast/react | ${{ needs.build.outputs.new_version }} |
| @relaycast/openclaw | ${{ needs.build.outputs.new_version }} |
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Summary
summary:
name: Summary
needs: [build, publish-packages, publish-single, create-release]
runs-on: ubuntu-latest
if: always()
steps:
- name: Summary
run: |
echo "## Publish Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version**: \`${{ needs.build.outputs.new_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Package**: \`${{ github.event.inputs.package }}\`" >> $GITHUB_STEP_SUMMARY
echo "**NPM Tag**: \`${{ github.event.inputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Dry Run**: \`${{ github.event.inputs.dry_run }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Results" >> $GITHUB_STEP_SUMMARY
echo "| Stage | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Build & Version | ${{ needs.build.result == 'success' && '✅' || '❌' }} ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Publish NPM Packages | ${{ needs.publish-packages.result == 'success' && '✅' || (needs.publish-packages.result == 'skipped' && '⏭️' || '❌') }} ${{ needs.publish-packages.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Publish Single | ${{ needs.publish-single.result == 'success' && '✅' || (needs.publish-single.result == 'skipped' && '⏭️' || '❌') }} ${{ needs.publish-single.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Create Release | ${{ needs.create-release.result == 'success' && '✅' || (needs.create-release.result == 'skipped' && '⏭️' || '❌') }} ${{ needs.create-release.result }} |" >> $GITHUB_STEP_SUMMARY