-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore(NODE-7563): migrate 6.x release workflows to npm trusted publishers #4943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // @ts-check | ||
| // TODO(NODE-7570): replace with workflow_call once GitHub/npm resolve the OIDC | ||
| // workflow_ref mismatch (https://github.com/npm/documentation/issues/1755). | ||
| // | ||
| // Dispatch a workflow_dispatch-triggered GitHub Actions workflow and wait for | ||
| // the resulting run to complete (propagating its exit status). | ||
| // | ||
| // `gh workflow run` prints the created workflow run URL on stdout when the | ||
| // server returns it (current github.com API version does); we parse the run | ||
| // id out of the URL and pass it to `gh run watch`. | ||
| // | ||
| // Usage: | ||
| // node dispatch-and-wait.mjs <workflow.yml> [key=value ...] | ||
| // | ||
| // For npm-publish.yml specifically: | ||
| // node dispatch-and-wait.mjs npm-publish.yml tag=<tag> version=<v> ref=<sha> | ||
| // | ||
| // Arguments: | ||
| // <workflow.yml> Filename of the target workflow under .github/workflows/ | ||
| // in the same repo. Must declare `on: workflow_dispatch:`. | ||
| // key=value ... Inputs forwarded to the dispatched workflow. Valid keys | ||
| // and which of them are required are determined by the | ||
| // target workflow's `on.workflow_dispatch.inputs`; the | ||
| // dispatch fails if any required input is missing or any | ||
| // unknown input is passed. For `npm-publish.yml`, all of | ||
| // `tag`, `version`, and `ref` are required. | ||
| // Example: tag=nightly version=1.2.3 ref=abc1234 | ||
| // | ||
| // Environment: | ||
| // GH_TOKEN (required) used by the gh CLI; in a workflow set | ||
| // this to ${{ github.token }}. | ||
| // DISPATCH_WORKFLOW_REF (optional, default `main`) git ref the target | ||
| // workflow file is loaded from. Hardcoded to main by | ||
| // default so callers on backport branches don't have | ||
| // to keep a copy of the target workflow on their | ||
| // branch. | ||
| import * as child_process from 'node:child_process'; | ||
| import * as process from 'node:process'; | ||
|
|
||
| const [, , workflow, ...inputArgs] = process.argv; | ||
| if (!workflow) { | ||
| console.error('usage: dispatch-and-wait.mjs <workflow.yml> [key=value ...]'); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| const dispatchRef = process.env.DISPATCH_WORKFLOW_REF || 'main'; | ||
|
|
||
| const ghArgs = [ | ||
| 'workflow', 'run', workflow, | ||
| '--ref', dispatchRef, | ||
| ...inputArgs.flatMap(kv => ['-f', kv]) | ||
| ]; | ||
| console.log(`Dispatching ${workflow} from ref ${dispatchRef}`); | ||
|
|
||
| const dispatch = child_process.spawnSync('gh', ghArgs, { | ||
| encoding: 'utf8', | ||
| stdio: ['inherit', 'pipe', 'inherit'] | ||
| }); | ||
| if (dispatch.status !== 0) process.exit(dispatch.status ?? 1); | ||
|
|
||
| // gh prints e.g. "https://github.com/owner/repo/actions/runs/<id>" | ||
| const match = dispatch.stdout.match(/\/actions\/runs\/(\d+)/); | ||
| if (!match) { | ||
| console.error('Could not extract run id from gh workflow run output:', dispatch.stdout); | ||
| process.exit(1); | ||
| } | ||
| const runId = match[1]; | ||
| console.log(`Dispatched run ${runId}`); | ||
|
|
||
| const watch = child_process.spawnSync('gh', ['run', 'watch', runId, '--exit-status'], { | ||
| stdio: 'inherit' | ||
| }); | ||
| process.exit(watch.status ?? 1); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using variable interpolation${{...}}withgithubcontext data in arun:step could allow an attacker to inject their own code into the runner. This would allow them to steal secrets and code.githubcontext data can have arbitrary user input and should be treated as untrusted. Instead, use an intermediate environment variable withenv:to store the data and use the environment variable in therun:script. Be sure to use double-quotes the environment variable, like this: "$ENVVAR".🎈 Fixed in commit 15ab807 🎈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth to mention - this was pre-existing pattern.