Npm publish - secrets.GITHUB_TOKEN not used because .npmrc exists #25414
-
I have the following workflow to create and publish a npm package to github packages. It was copied verbatim from another repository where it works without issue. However for this repo it says that the token (the built in
Result of the
As far as I am aware, the |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
UPDATE: Turns out the issue is that i had a .npmrc file checked in. The file has a token that granted read package access to github packages. Checking this file in was intentional and a pattern we use in our private repositories. So I will change the question to: How do I get npm to use the |
Beta Was this translation helpful? Give feedback.
-
At first, you need to understand the restrictions of the GITHUB_TOKEN:
This means the scope of the GITHUB_TOKEN is only inside of the repository where the current workflow is running. If the scope you require is beyond the current repository, you need to create a personal access token to obtain more scopes. If you have configured a .npmrc file for your npm package and want to use the GITHUB_TOKEN in the .npmrc file, you need to do the steps below:
The following is a simple example as reference.: TestGitHubPackagesRML/TestNpm/blob/080990526adbb61b0365e4b207d972de7d46dc77/.npmrc
github.com TestGitHubPackagesRML/TestNpm/blob/080990526adbb61b0365e4b207d972de7d46dc77/.github/workflows/CI.yml
This file has been truncated. show original |
Beta Was this translation helpful? Give feedback.
-
Hi @brightran, |
Beta Was this translation helpful? Give feedback.
-
You can try to use the sed command to replace the token with the GITHUB_TOKEN in the .npmrc file, before executing the publish step. Here you also may need using regular expression in the sed command.
|
Beta Was this translation helpful? Give feedback.
-
Thanks @brightran, the sed command worked for me 😃 |
Beta Was this translation helpful? Give feedback.
-
Using just wrap a |
Beta Was this translation helpful? Give feedback.
@elexisvenator,
You can try to use the sed command to replace the token with the GITHUB_TOKEN in the .npmrc file, before executing the publish step. Here you also may need using regular expression in the sed command.
A simple example as reference: