2121 required : false
2222
2323permissions :
24- contents : write
25- id-token : write # Required for OIDC
26- actions : write # Required to trigger changelog workflow
24+ contents : read
2725
2826concurrency :
2927 group : publish
@@ -78,11 +76,21 @@ jobs:
7876 echo "Auto-incremented version: $VERSION" >> $GITHUB_STEP_SUMMARY
7977 fi
8078 echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
79+ - name : Verify version is available on public npm
80+ env :
81+ VERSION : ${{ steps.version.outputs.VERSION }}
82+ run : |
83+ node scripts/npm-release.js preflight \
84+ @github/copilot-sdk \
85+ "$VERSION" \
86+ https://registry.npmjs.org
8187
82- publish -nodejs :
83- name : Publish Node.js SDK
88+ package -nodejs :
89+ name : Package Node.js SDK
8490 needs : version
8591 runs-on : ubuntu-latest
92+ permissions :
93+ contents : read
8694 defaults :
8795 run :
8896 working-directory : ./nodejs
9199 - uses : actions/setup-node@v6
92100 with :
93101 node-version : " 22.x"
94- - name : Update npm for OIDC support
95- run : npm i -g "npm@11.6.3"
96102 - run : npm ci --ignore-scripts
97103 - name : Set version
98104 run : node scripts/set-version.js
@@ -101,21 +107,126 @@ jobs:
101107 - name : Build
102108 run : npm run build
103109 - name : Pack
104- run : npm pack
110+ id : pack
111+ run : |
112+ TARBALL="$(npm pack . --json | jq -r '.[0].filename')"
113+ if [ -z "$TARBALL" ] || [ ! -f "$TARBALL" ]; then
114+ echo "::error::npm pack did not produce a tarball."
115+ exit 1
116+ fi
117+ echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT"
105118 - name : Upload artifact
106119 uses : actions/upload-artifact@v7.0.0
107120 with :
108121 name : nodejs-package
109- path : nodejs/*.tgz
110- - name : Publish to npm
111- if : github.ref == 'refs/heads/main' || github.event.inputs.dist-tag == 'unstable'
112- run : npm publish --tag ${{ github.event.inputs.dist-tag }} --access public --registry https://registry.npmjs.org
122+ path : nodejs/${{ steps.pack.outputs.tarball }}
123+ if-no-files-found : error
124+
125+ publish-nodejs :
126+ name : Publish Node.js SDK
127+ needs : package-nodejs
128+ if : github.ref == 'refs/heads/main' || github.event.inputs.dist-tag == 'unstable'
129+ runs-on : ubuntu-latest
130+ permissions :
131+ actions : read
132+ contents : read
133+ id-token : write
134+ steps :
135+ - uses : actions/checkout@v6.0.2
136+ - uses : actions/setup-node@v6
137+ with :
138+ node-version : " 22.x"
139+ - name : Update npm for OIDC support
140+ run : npm i -g "npm@11.6.3"
141+ - name : Download Node.js package
142+ uses : actions/download-artifact@v8.0.0
143+ with :
144+ name : nodejs-package
145+ path : ./dist
146+ - name : Publish tarball to public npm
147+ env :
148+ DIST_TAG : ${{ github.event.inputs.dist-tag }}
149+ run : |
150+ set -euo pipefail
151+ shopt -s nullglob
152+ TARBALLS=(./dist/*.tgz)
153+ if [ "${#TARBALLS[@]}" -ne 1 ]; then
154+ echo "::error::Expected exactly one Node.js package tarball, found ${#TARBALLS[@]}."
155+ exit 1
156+ fi
157+ node nodejs/scripts/npm-release.js publish \
158+ "${TARBALLS[0]}" \
159+ "$DIST_TAG" \
160+ https://registry.npmjs.org \
161+ public
162+
163+ publish-nodejs-internal :
164+ name : Publish Node.js SDK to internal feed
165+ needs : publish-nodejs
166+ environment : cicd
167+ runs-on : ubuntu-latest
168+ permissions :
169+ actions : read
170+ contents : read
171+ id-token : write
172+ env :
173+ ADO_RESOURCE : 499b84ac-1321-427f-aa17-267ca6975798
174+ FEED_URL : https://pkgs.dev.azure.com/devdiv/_packaging/copilot-canary/npm/registry/
175+ steps :
176+ - uses : actions/checkout@v6.0.2
177+ - uses : actions/setup-node@v6
178+ with :
179+ node-version : " 22.x"
180+ - name : Download Node.js package
181+ uses : actions/download-artifact@v8.0.0
182+ with :
183+ name : nodejs-package
184+ path : ./dist
185+ - name : Azure Login (OIDC -> id-cpd-ci)
186+ uses : azure/login@532459ea530d8321f2fb9bb10d1e0bcf23869a43 # v3.0.0
187+ with :
188+ client-id : " ${{ vars.CPD_ID_CLIENT_ID }}" # id-cpd-ci
189+ tenant-id : " ${{ vars.CPD_ID_TENANT_ID }}"
190+ allow-no-subscriptions : true
191+ - name : Configure feed auth
192+ run : |
193+ set -euo pipefail
194+ TOKEN="$(az account get-access-token --resource "$ADO_RESOURCE" --query accessToken -o tsv)"
195+ echo "::add-mask::$TOKEN"
196+ FEED_AUTH_REGISTRY="${FEED_URL#https:}"
197+ FEED_AUTH_BASE="${FEED_AUTH_REGISTRY%registry/}"
198+ printf '%s\n' \
199+ "${FEED_AUTH_REGISTRY}:_authToken=${TOKEN}" \
200+ "${FEED_AUTH_BASE}:_authToken=${TOKEN}" > "$HOME/.npmrc"
201+ - name : Publish tarball to internal feed
202+ env :
203+ DIST_TAG : ${{ github.event.inputs.dist-tag }}
204+ run : |
205+ set -euo pipefail
206+ if [ "$FEED_URL" != "https://pkgs.dev.azure.com/devdiv/_packaging/copilot-canary/npm/registry/" ]; then
207+ echo "::error::FEED_URL ('$FEED_URL') is not the expected internal feed. Refusing to publish."
208+ exit 1
209+ fi
210+ shopt -s nullglob
211+ TARBALLS=(./dist/*.tgz)
212+ if [ "${#TARBALLS[@]}" -ne 1 ]; then
213+ echo "::error::Expected exactly one Node.js package tarball, found ${#TARBALLS[@]}."
214+ exit 1
215+ fi
216+ node nodejs/scripts/npm-release.js publish \
217+ "${TARBALLS[0]}" \
218+ "$DIST_TAG" \
219+ "$FEED_URL" \
220+ azure
113221
114222 publish-dotnet :
115223 name : Publish .NET SDK
116224 if : github.event.inputs.dist-tag != 'unstable'
117225 needs : version
118226 runs-on : ubuntu-latest
227+ permissions :
228+ contents : read
229+ id-token : write
119230 defaults :
120231 run :
121232 working-directory : ./dotnet
@@ -200,6 +311,9 @@ jobs:
200311 if : github.event.inputs.dist-tag != 'unstable'
201312 needs : version
202313 runs-on : ubuntu-latest
314+ permissions :
315+ contents : read
316+ id-token : write
203317 defaults :
204318 run :
205319 working-directory : ./python
@@ -237,6 +351,9 @@ jobs:
237351 name : Publish Java SDK
238352 if : github.event.inputs.dist-tag != 'unstable' && github.ref == 'refs/heads/main'
239353 needs : version
354+ permissions :
355+ contents : write
356+ id-token : write
240357 uses : ./.github/workflows/java-publish-maven.yml
241358 with :
242359 releaseVersion : ${{ needs.version.outputs.version }}
@@ -245,7 +362,15 @@ jobs:
245362
246363 github-release :
247364 name : Create GitHub Release
248- needs : [version, publish-nodejs, publish-dotnet, publish-python, publish-rust, publish-java]
365+ needs :
366+ [
367+ version,
368+ publish-nodejs,
369+ publish-dotnet,
370+ publish-python,
371+ publish-rust,
372+ publish-java,
373+ ]
249374 if : |
250375 always() &&
251376 github.ref == 'refs/heads/main' &&
@@ -256,6 +381,9 @@ jobs:
256381 needs.publish-python.result == 'success' &&
257382 needs.publish-rust.result == 'success'
258383 runs-on : ubuntu-latest
384+ permissions :
385+ actions : write
386+ contents : write
259387 steps :
260388 - uses : actions/checkout@v6.0.2
261389 - name : Create GitHub Release
0 commit comments