-
Notifications
You must be signed in to change notification settings - Fork 1.4k
478 lines (465 loc) · 17.5 KB
/
Copy pathpublish.yml
File metadata and controls
478 lines (465 loc) · 17.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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
name: Publish SDK packages
env:
HUSKY: 0
on:
workflow_dispatch:
inputs:
dist-tag:
description: "Tag to publish under"
type: choice
required: true
default: "prerelease"
options:
- latest
- prerelease
- unstable
version:
description: "Version override (optional, e.g., 1.0.0). If empty, auto-increments."
type: string
required: false
permissions:
contents: read
concurrency:
group: publish
cancel-in-progress: false
jobs:
# Shared job to calculate version once for all publish jobs
version:
name: Calculate Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.VERSION }}
current: ${{ steps.version.outputs.CURRENT }}
current-prerelease: ${{ steps.version.outputs.CURRENT_PRERELEASE }}
defaults:
run:
working-directory: ./nodejs
steps:
- uses: actions/checkout@v6.0.2
- uses: actions/setup-node@v6
with:
node-version: "22.x"
- run: npm ci --ignore-scripts
- name: Get version
id: version
run: |
CURRENT="$(node scripts/get-version.js current)"
echo "CURRENT=$CURRENT" >> $GITHUB_OUTPUT
echo "Current latest version: $CURRENT" >> $GITHUB_STEP_SUMMARY
CURRENT_PRERELEASE="$(node scripts/get-version.js current-prerelease)"
echo "CURRENT_PRERELEASE=$CURRENT_PRERELEASE" >> $GITHUB_OUTPUT
echo "Current prerelease version: $CURRENT_PRERELEASE" >> $GITHUB_STEP_SUMMARY
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
# Validate version format matches dist-tag
if [ "${{ github.event.inputs.dist-tag }}" = "latest" ]; then
if [[ "$VERSION" == *-* ]]; then
echo "❌ Error: Version '$VERSION' has a prerelease suffix but dist-tag is 'latest'" >> $GITHUB_STEP_SUMMARY
echo "Use a version without suffix (e.g., '1.0.0') for latest releases"
exit 1
fi
else
if [[ "$VERSION" != *-* ]]; then
echo "❌ Error: Version '$VERSION' has no prerelease suffix but dist-tag is '${{ github.event.inputs.dist-tag }}'" >> $GITHUB_STEP_SUMMARY
echo "Use a version with suffix (e.g., '1.0.0-preview.0') for prerelease/unstable"
exit 1
fi
fi
echo "Using manual version override: $VERSION" >> $GITHUB_STEP_SUMMARY
else
VERSION="$(node scripts/get-version.js ${{ github.event.inputs.dist-tag }})"
echo "Auto-incremented version: $VERSION" >> $GITHUB_STEP_SUMMARY
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Verify version is available on public npm
env:
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
node scripts/npm-release.js preflight \
@github/copilot-sdk \
"$VERSION" \
https://registry.npmjs.org
package-nodejs:
name: Package Node.js SDK
needs: version
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: ./nodejs
steps:
- uses: actions/checkout@v6.0.2
- uses: actions/setup-node@v6
with:
node-version: "22.x"
- run: npm ci --ignore-scripts
- name: Set version
run: node scripts/set-version.js
env:
VERSION: ${{ needs.version.outputs.version }}
- name: Build
run: npm run build
- name: Pack
id: pack
run: |
TARBALL="$(npm pack . --json | jq -r '.[0].filename')"
if [ -z "$TARBALL" ] || [ ! -f "$TARBALL" ]; then
echo "::error::npm pack did not produce a tarball."
exit 1
fi
echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT"
- name: Upload artifact
uses: actions/upload-artifact@v7.0.0
with:
name: nodejs-package
path: nodejs/${{ steps.pack.outputs.tarball }}
if-no-files-found: error
publish-nodejs:
name: Publish Node.js SDK
needs: package-nodejs
if: github.ref == 'refs/heads/main' || github.event.inputs.dist-tag == 'unstable'
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
id-token: write
steps:
- uses: actions/checkout@v6.0.2
- uses: actions/setup-node@v6
with:
node-version: "22.x"
- name: Update npm for OIDC support
run: npm i -g "npm@11.6.3"
- name: Download Node.js package
uses: actions/download-artifact@v8.0.0
with:
name: nodejs-package
path: ./dist
- name: Publish tarball to public npm
env:
DIST_TAG: ${{ github.event.inputs.dist-tag }}
run: |
set -euo pipefail
shopt -s nullglob
TARBALLS=(./dist/*.tgz)
if [ "${#TARBALLS[@]}" -ne 1 ]; then
echo "::error::Expected exactly one Node.js package tarball, found ${#TARBALLS[@]}."
exit 1
fi
node nodejs/scripts/npm-release.js publish \
"${TARBALLS[0]}" \
"$DIST_TAG" \
https://registry.npmjs.org \
public
publish-nodejs-internal:
name: Publish Node.js SDK to internal feed
needs: publish-nodejs
environment: cicd
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
id-token: write
env:
ADO_RESOURCE: 499b84ac-1321-427f-aa17-267ca6975798
FEED_URL: https://pkgs.dev.azure.com/devdiv/_packaging/copilot-canary/npm/registry/
steps:
- uses: actions/checkout@v6.0.2
- uses: actions/setup-node@v6
with:
node-version: "22.x"
- name: Download Node.js package
uses: actions/download-artifact@v8.0.0
with:
name: nodejs-package
path: ./dist
- name: Azure Login (OIDC -> id-cpd-ci)
uses: azure/login@532459ea530d8321f2fb9bb10d1e0bcf23869a43 # v3.0.0
with:
client-id: "${{ vars.CPD_ID_CLIENT_ID }}" # id-cpd-ci
tenant-id: "${{ vars.CPD_ID_TENANT_ID }}"
allow-no-subscriptions: true
- name: Configure feed auth
run: |
set -euo pipefail
TOKEN="$(az account get-access-token --resource "$ADO_RESOURCE" --query accessToken -o tsv)"
echo "::add-mask::$TOKEN"
FEED_AUTH_REGISTRY="${FEED_URL#https:}"
FEED_AUTH_BASE="${FEED_AUTH_REGISTRY%registry/}"
printf '%s\n' \
"${FEED_AUTH_REGISTRY}:_authToken=${TOKEN}" \
"${FEED_AUTH_BASE}:_authToken=${TOKEN}" > "$HOME/.npmrc"
- name: Publish tarball to internal feed
env:
DIST_TAG: ${{ github.event.inputs.dist-tag }}
run: |
set -euo pipefail
if [ "$FEED_URL" != "https://pkgs.dev.azure.com/devdiv/_packaging/copilot-canary/npm/registry/" ]; then
echo "::error::FEED_URL ('$FEED_URL') is not the expected internal feed. Refusing to publish."
exit 1
fi
shopt -s nullglob
TARBALLS=(./dist/*.tgz)
if [ "${#TARBALLS[@]}" -ne 1 ]; then
echo "::error::Expected exactly one Node.js package tarball, found ${#TARBALLS[@]}."
exit 1
fi
node nodejs/scripts/npm-release.js publish \
"${TARBALLS[0]}" \
"$DIST_TAG" \
"$FEED_URL" \
azure
publish-dotnet:
name: Publish .NET SDK
if: github.event.inputs.dist-tag != 'unstable'
needs: version
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: ./dotnet
steps:
- uses: actions/checkout@v6.0.2
- uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: Restore dependencies
run: dotnet restore
- name: Build and pack
run: dotnet pack src/GitHub.Copilot.SDK.csproj -c Release -p:Version=${{ needs.version.outputs.version }} -o ./artifacts
- name: Upload artifact
uses: actions/upload-artifact@v7.0.0
with:
name: dotnet-package
path: |
dotnet/artifacts/*.nupkg
dotnet/artifacts/*.snupkg
- name: NuGet login (OIDC)
if: github.ref == 'refs/heads/main'
uses: NuGet/login@v1
id: nuget-login
with:
# The following must be a username, not an organization name, and that user must have configured Trusted Publishing
# for this owner/repo/workflow combination in their NuGet.org account settings. We could set up a dedicated user for
# this purpose if needed, but then we'd have to manage that account separately. Other GitHub-owned packages on NuGet
# are associated with individual maintainers' accounts too.
user: stevesanderson
- name: Publish to NuGet
if: github.ref == 'refs/heads/main'
run: |
dotnet nuget push ./artifacts/*.nupkg --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols
dotnet nuget push ./artifacts/*.snupkg --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
publish-rust:
name: Publish Rust SDK
if: github.event.inputs.dist-tag != 'unstable'
needs: version
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./rust
steps:
- uses: actions/checkout@v6.0.2
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.94.0"
- uses: Swatinem/rust-cache@v2
with:
workspaces: "rust"
- name: Set version
run: sed -i -E 's/^version = ".*"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
- name: Snapshot CLI version + hashes for build.rs
run: |
bash scripts/snapshot-bundled-cli-version.sh
bash scripts/snapshot-bundled-in-process-version.sh
- name: Verify CLI version snapshots exist
run: |
for snapshot in cli-version.txt cli-version-in-process.txt; do
if [[ ! -f "${snapshot}" ]]; then
echo "::error::${snapshot} was not generated. The Snapshot step must run before packaging."
exit 1
fi
done
- name: Package (dry run)
run: cargo publish --dry-run --allow-dirty
- name: Upload artifact
uses: actions/upload-artifact@v7.0.0
with:
name: rust-package
path: rust/target/package/*.crate
- name: Publish to crates.io
if: github.ref == 'refs/heads/main'
run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish-python:
name: Publish Python SDK
if: github.event.inputs.dist-tag != 'unstable'
needs: version
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: ./python
steps:
- uses: actions/checkout@v6.0.2
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- uses: actions/setup-node@v6
with:
node-version: "22.x"
- name: Set up uv
uses: astral-sh/setup-uv@v7
- name: Install Node.js dependencies (for CLI version)
working-directory: ./nodejs
run: npm ci --ignore-scripts
- name: Set version
run: sed -i "s/^version = .*/version = \"${{ needs.version.outputs.version }}\"/" pyproject.toml
- name: Inject CLI version
run: node scripts/inject-cli-version.mjs
- name: Build wheel
run: uv build --wheel --out-dir dist
- name: Upload artifact
uses: actions/upload-artifact@v7.0.0
with:
name: python-package
path: python/dist/*
- name: Publish to PyPI
if: github.ref == 'refs/heads/main'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: python/dist/
publish-java:
name: Publish Java SDK
if: github.event.inputs.dist-tag != 'unstable' && github.ref == 'refs/heads/main'
needs: version
permissions:
contents: write
id-token: write
uses: ./.github/workflows/java-publish-maven.yml
with:
releaseVersion: ${{ needs.version.outputs.version }}
prerelease: ${{ github.event.inputs.dist-tag == 'prerelease' }}
secrets: inherit
github-release:
name: Create GitHub Release
needs:
[
version,
publish-nodejs,
publish-dotnet,
publish-python,
publish-rust,
publish-java,
]
if: |
always() &&
github.ref == 'refs/heads/main' &&
github.event.inputs.dist-tag != 'unstable' &&
needs.version.result == 'success' &&
needs.publish-nodejs.result == 'success' &&
needs.publish-dotnet.result == 'success' &&
needs.publish-python.result == 'success' &&
needs.publish-rust.result == 'success'
runs-on: ubuntu-latest
permissions:
actions: write
contents: write
steps:
- uses: actions/checkout@v6.0.2
- name: Create GitHub Release
if: github.event.inputs.dist-tag == 'latest'
run: |
NOTES_FLAG=""
if git rev-parse "v${{ needs.version.outputs.current }}" >/dev/null 2>&1; then
NOTES_FLAG="--notes-start-tag v${{ needs.version.outputs.current }}"
fi
gh release create "v${{ needs.version.outputs.version }}" \
--title "v${{ needs.version.outputs.version }}" \
--generate-notes $NOTES_FLAG \
--target ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Pre-Release
if: github.event.inputs.dist-tag == 'prerelease'
run: |
NOTES_FLAG=""
if git rev-parse "v${{ needs.version.outputs.current-prerelease }}" >/dev/null 2>&1; then
NOTES_FLAG="--notes-start-tag v${{ needs.version.outputs.current-prerelease }}"
fi
gh release create "v${{ needs.version.outputs.version }}" \
--prerelease \
--title "v${{ needs.version.outputs.version }}" \
--generate-notes $NOTES_FLAG \
--target ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger changelog generation
run: gh workflow run release-changelog.lock.yml -f tag="v${{ needs.version.outputs.version }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag Go SDK submodule
if: github.event.inputs.dist-tag == 'latest' || github.event.inputs.dist-tag == 'prerelease'
run: |
set -e
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch --tags
TAG_NAME="go/v${{ needs.version.outputs.version }}"
# Try to create the tag - will fail if it already exists
if git tag "$TAG_NAME" ${{ github.sha }} 2>/dev/null; then
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git "$TAG_NAME"
echo "Created and pushed tag $TAG_NAME"
else
echo "Tag $TAG_NAME already exists, skipping"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag Rust SDK and create Rust GitHub Release
# Rust gets its own version-scoped GitHub Release with notes
# derived from PR titles since the previous Rust tag. The
# cross-language `vX.Y.Z` release above still exists; this one
# is the canonical reference for Rust users.
if: github.event.inputs.dist-tag == 'latest' || github.event.inputs.dist-tag == 'prerelease'
run: |
set -e
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch --tags
VERSION="${{ needs.version.outputs.version }}"
TAG_NAME="rust/v${VERSION}"
if git tag "$TAG_NAME" ${{ github.sha }} 2>/dev/null; then
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git "$TAG_NAME"
echo "Created and pushed tag $TAG_NAME"
else
echo "Tag $TAG_NAME already exists, skipping tag push"
fi
# Find the previous Rust tag for note generation. Prefer rust/v*,
# fall back to the historical rust-v* tags from the release-plz era.
PREV_TAG=$(git tag --list 'rust/v*' --sort=-v:refname | grep -vFx "$TAG_NAME" | head -n1)
if [ -z "$PREV_TAG" ]; then
PREV_TAG=$(git tag --list 'rust-v*' --sort=-v:refname | head -n1)
fi
NOTES_FLAG=""
if [ -n "$PREV_TAG" ]; then
NOTES_FLAG="--notes-start-tag $PREV_TAG"
echo "Generating notes from $PREV_TAG..$TAG_NAME"
else
echo "No previous Rust tag found; generating notes from full history"
fi
PRERELEASE_FLAG=""
if [ "${{ github.event.inputs.dist-tag }}" = "prerelease" ]; then
PRERELEASE_FLAG="--prerelease"
fi
gh release create "$TAG_NAME" \
--title "$TAG_NAME" \
--generate-notes $NOTES_FLAG $PRERELEASE_FLAG \
--target ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}