Skip to content
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

fix: Include registry URL pathname in npmrc auth token config #186

Merged
merged 4 commits into from Mar 29, 2024

Conversation

bdr99
Copy link
Contributor

@bdr99 bdr99 commented Mar 28, 2024

Thanks for creating this action! I was trying to use it to publish to a private npm registry, but ran into an issue with authentication.

My workflow looked like this:

on:
  push:
    branches: main

jobs:
  publish:
    runs-on: node-20
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - uses: JS-DevTools/npm-publish@v3
        with:
          token: ${{ secrets.MY_REGISTRY_TOKEN }}
          registry: https://git.mydomain.com/api/packages/myuser/npm/

And this is the output I was getting from the action when I tried to run the workflow:

::error::NpmCallError: Call to "npm publish" exited with non-zero exit code 1%0Anpm ERR! code ENEEDAUTH%0Anpm ERR! need auth This command requires you to be logged in to https://git.mydomain.com/api/packages/myuser/npm/%0Anpm ERR! need auth You need to authorize this machine using npm adduser%0A%0Anpm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-28T19_08_34_852Z-debug-0.log

After much troubleshooting, I realized that the problem was in the npmrc file. Authentication would only work if the auth token line included the host and path from the registry URL, not just the host. With this change, I was able to publish successfully to the private registry. I'm hoping to get this merged in case it helps anyone in a similar situation to mine.

@mcous
Copy link
Member

mcous commented Mar 29, 2024

Thanks for your contribution @bdr99! Following the example of actions/setup-node, I added some tests and a little bit of extra logic to ensure the registry always ends in a trailing slash

@mcous mcous merged commit 1e4a74d into JS-DevTools:main Mar 29, 2024
24 checks passed
@bdr99
Copy link
Contributor Author

bdr99 commented Mar 29, 2024

Thanks for merging this, and for adding those tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants