Conversation
- Add enablePublishingOnGitHubActions() to configure-publish.mts so the new GHA workflow can gate publish steps via GITHUB_OUTPUT - Update apply-additional-tags.mjs to fall back to NODE_AUTH_TOKEN env var when --token is not provided; avoids token-in-process-args on GHA - Add .github/workflows/microsoft-npm-publish.yml: OIDC trusted publishing on *-stable branch pushes, with npm-publish environment protection
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
| # Mirrors the trigger used by the Azure Pipelines publish.yml: | ||
| # runs on every push to a stable release branch. |
There was a problem hiding this comment.
No need for this comment
| function main({ tags, token, "dry-run": dryRun }) { | ||
| function main({ tags, token: tokenArg, "dry-run": dryRun }) { | ||
| if (!tags) { | ||
| console.log("No additional tags to apply"); | ||
| return 0; | ||
| } | ||
|
|
||
| // Prefer explicit --token arg (ADO), fall back to NODE_AUTH_TOKEN env var (GHA OIDC). | ||
| const token = tokenArg ?? process.env.NODE_AUTH_TOKEN; |
There was a problem hiding this comment.
I think we want to support dry run, and don't want to support the passed in token
There was a problem hiding this comment.
🤖 Copilot: Done — removed --token entirely. Auth now comes exclusively from NODE_AUTH_TOKEN. Updated the ADO job to pass the token via env: NODE_AUTH_TOKEN: $(npmAuthToken) instead of the --token arg.
| // When --token is explicitly provided (ADO path), pass auth inline so | ||
| // that npm picks it up without a pre-configured .npmrc. | ||
| // When NODE_AUTH_TOKEN is used instead (GHA OIDC path), actions/setup-node | ||
| // has already written .npmrc with `//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}`, | ||
| // so no inline auth argument is needed. |
There was a problem hiding this comment.
No overly verbose comments. Comments are to describe code, not the last turn of AI
| /** | ||
| * Writes `publish_react_native_macos=1` to `GITHUB_OUTPUT` to signal that we | ||
| * want to enable publishing on GitHub Actions. | ||
| */ | ||
| function enablePublishingOnGitHubActions() { |
There was a problem hiding this comment.
Function name is self explanatory
| enablePublishingOnAzurePipelines(); | ||
| enablePublishingOnGitHubActions(); |
There was a problem hiding this comment.
Should we choose one or the other with an extra Boolean in the file?
There was a problem hiding this comment.
🤖 Copilot: Added const isGitHubActions = process.env['GITHUB_ACTIONS'] === 'true' at the top of the file and used it to pick one path — enablePublishingOnGitHubActions() on GHA, enablePublishingOnAzurePipelines() otherwise.
| # which dist-tag(s) to use. Outputs: | ||
| # publish_react_native_macos – '1' when publishing should proceed | ||
| # publishTag – the primary npm dist-tag (e.g. 'latest') | ||
| # additionalTags – comma-separated extra tags (may be empty) |
There was a problem hiding this comment.
Examples of an extra tag
| # additionalTags – comma-separated extra tags (may be empty) | ||
| - name: Verify release config | ||
| id: configure-publish | ||
| run: node .ado/scripts/configure-publish.mts --verbose --skip-auth |
There was a problem hiding this comment.
Do we still need to skip auth with oidc?
There was a problem hiding this comment.
🤖 Copilot: Yes, still needed. verifyNpmAuth() runs npm whoami, which requires a pre-configured token and would fail before any OIDC exchange happens. OIDC auth is initiated by yarn at publish time (via --provenance), not upfront — so there's no token in the environment when configure-publish.mts runs.
There was a problem hiding this comment.
I think no callers actually use auth then and we can remove that flow
| # Configure yarn to target the public npm registry. | ||
| # Auth is handled by OIDC Trusted Publishing – do NOT set npmAuthToken here. |
| # Publish all non-private workspace packages. | ||
| # --provenance enables npm Trusted Publishing: yarn requests an OIDC token | ||
| # from GitHub Actions and exchanges it with npmjs.com – no stored secret needed. |
| # Apply any additional dist-tags (e.g. promoting a branch tag to 'next'). | ||
| # npm dist-tag add does not support OIDC, so a granular NPM_TOKEN secret | ||
| # is required for this step. NODE_AUTH_TOKEN is the conventional env var | ||
| # that actions/setup-node (called inside microsoft-setup-toolchain) wires | ||
| # into the project-level .npmrc it creates. |
There was a problem hiding this comment.
Useful comment, can we simplify a little?
There was a problem hiding this comment.
🤖 Copilot: Simplified to: # npm dist-tag add doesn't support OIDC, so NODE_AUTH_TOKEN (a granular NPM_TOKEN secret) is still required for this step.
- Remove verbose/obvious comments from workflow and scripts - Drop --token CLI arg from apply-additional-tags.mjs; use NODE_AUTH_TOKEN env var only; update ADO job accordingly - Remove JSDoc from self-explanatory enablePublishingOnGitHubActions() - Add isGitHubActions boolean to configure-publish.mts and use it to select between ADO and GHA signaling (instead of calling both)
|
|
||
| const npmArgs = [ | ||
| "dist-tag", | ||
| "add", | ||
| `${pkg}@${version}`, | ||
| tag, | ||
| "--registry", | ||
| registry, | ||
| ]; | ||
|
|
||
| const result = spawnSync( | ||
| "npm", | ||
| [ | ||
| "dist-tag", | ||
| "add", | ||
| `${pkg}@${version}`, | ||
| tag, | ||
| "--registry", | ||
| registry, | ||
| `--//registry.npmjs.org/:_authToken=${token}`, | ||
| ], | ||
| npmArgs, |
There was a problem hiding this comment.
No need to pull this out anymore
| } else { | ||
| enablePublishingOnAzurePipelines(); | ||
| } |
There was a problem hiding this comment.
Can we handle if neither (I.E: local run)? Just a log message may be fine
| # additionalTags – comma-separated extra tags (may be empty) | ||
| - name: Verify release config | ||
| id: configure-publish | ||
| run: node .ado/scripts/configure-publish.mts --verbose --skip-auth |
There was a problem hiding this comment.
I think no callers actually use auth then and we can remove that flow
| - name: Configure yarn for npm publishing | ||
| if: steps.configure-publish.outputs.publish_react_native_macos == '1' | ||
| run: | | ||
| yarn config set npmPublishAccess public | ||
| yarn config set npmPublishRegistry "https://registry.npmjs.org" |
There was a problem hiding this comment.
Also unset unconditionally after
Replaces the ADO-based npm publish pipeline with a GitHub Actions workflow that uses npm Trusted Publishing (OIDC) for the main publish step — no stored npm token required for
npm publish.Changes
.github/workflows/microsoft-npm-publish.yml— New workflow triggered on*-stablebranch pushes. Runs in annpm-publishGitHub environment (add protection rules there). Usesid-token: write+--provenanceso yarn exchanges a GitHub OIDC token directly with npmjs.com rather than a stored secret. Thenpm dist-tag addstep (applying additional dist-tags) still requires aNPM_TOKENsecret since OIDC doesn't cover that operation..ado/scripts/configure-publish.mts— AddedenablePublishingOnGitHubActions()that writespublish_react_native_macos=1toGITHUB_OUTPUT, so the new workflow can gate its publish steps on this output. Previously only the ADO##vso[task.setvariable...]signal was emitted..ado/scripts/apply-additional-tags.mjs— Token can now come fromNODE_AUTH_TOKENenv var as a fallback to--token. When using the env-var path (GHA), the token is not passed as a CLI argument —actions/setup-nodehas already wiredNODE_AUTH_TOKENinto.npmrc, sonpm dist-tag addpicks it up from there. The--tokenCLI arg path (ADO) is unchanged.Manual steps required before this workflow runs
react-native-macosand@react-native-macos/virtualized-lists— repomicrosoft/react-native-macos, workflowmicrosoft-npm-publish.yml, environmentnpm-publishnpm-publishenvironment with desired approval rulesNPM_TOKENto that environment (granular automation token scoped to the two packages, used only for dist-tag operations).ado/publish.yml