-
Notifications
You must be signed in to change notification settings - Fork 2.2k
chore: add a new workflow for npm publish with trusted publishing #14661
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
Open
sarayev
wants to merge
1
commit into
aws-amplify:main
Choose a base branch
from
sarayev:onboard-npm-trusted-publishing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−42
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Trusted npm publisher with OIDC authentication | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| github_user: | ||
| description: The git user to make commits with | ||
| required: true | ||
| type: string | ||
| github_email: | ||
| description: The git email to make commits with | ||
| required: true | ||
| type: string | ||
| target: | ||
| description: The release process target (either release or preid) | ||
| required: true | ||
| type: string | ||
| preid: | ||
| description: The preid to release to when the target is preid | ||
| required: false | ||
| type: string | ||
|
|
||
| jobs: | ||
| publish: | ||
| name: Publish to npm with trusted authentication | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write # Required for npm trusted publishers | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
| with: | ||
| path: amplify-js | ||
| token: ${{ secrets.GH_TOKEN_AMPLIFY_JS_WRITE }} | ||
| # Minimal depth 0 so we can fetch all git tags. | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup node and build the repository | ||
| uses: ./amplify-js/.github/actions/node-and-build | ||
|
|
||
| - name: Authenticate with npm (trusted publishers) | ||
| id: npm-auth | ||
| run: | | ||
| if [ -n "$NPM_TOKEN" ]; then | ||
| echo "Using npm trusted publishers authentication" | ||
| echo "auth_token=$NPM_TOKEN" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "Error: NPM_TOKEN not provided by trusted publishers" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Run npm publish | ||
| uses: ./amplify-js/.github/actions/npm-publish | ||
| with: | ||
| target: ${{ inputs.target }} | ||
| preid: ${{ inputs.preid }} | ||
| npm_token: ${{ steps.npm-auth.outputs.auth_token }} | ||
| github_user: ${{ inputs.github_user }} | ||
| github_email: ${{ inputs.github_email }} | ||
Oops, something went wrong.
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.
Maybe I am misunderstanding something. Why are we still manually handling tokens via NPM_TOKEN? I thought that trusted publishers would allow us to register
callable-npm-publish-trusted.ymlwith NPM and GitHub would automatically verify our call via an oidc token. This is done by settingid-token: writepermissions.Also I am not able to tell where the NPM_TOKEN is supposed to be coming from here. I fear that we would always run in the else branch, resulting in an error. If I am understanding this correctly, we would therefore need to remove the
npm-authstep and also update./amplify-js/.github/actions/npm-publishto not requirenpm_tokenanymore.