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

Publish to GitHub Package Registry #11

Open
geoperez opened this issue Dec 27, 2019 · 15 comments
Open

Publish to GitHub Package Registry #11

geoperez opened this issue Dec 27, 2019 · 15 comments

Comments

@geoperez
Copy link

Hi,

I've been using this Action for Npm, and it works really great. But I'm having issues trying to publish to GPR. I'm getting the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"

According to GH Documentation (https://help.github.com/en/github/managing-packages-with-github-packages/configuring-npm-for-use-with-github-packages#authenticating-with-the-github_token), the same GITHUB_TOKEN is valid to publish.

So, I'm using the following env variables:

     - name: Publish
        uses: mikeal/merge-release@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I'm using the .npmrc file to set the registry URL:

registry=https://npm.pkg.github.com/unosquare

Thanks!

@mikeal
Copy link
Owner

mikeal commented Dec 30, 2019

Sounds like this actions/setup-node#52

@geoperez
Copy link
Author

It's failing when I added the setup-node with URL and scope:

Run mikeal/merge-release@master
  env:
    NPM_CONFIG_USERCONFIG: /home/runner/work/_temp/.npmrc
    NODE_AUTH_TOKEN: XXXXX-XXXXX-XXXXX-XXXXX
    GITHUB_TOKEN: ***
    NPM_AUTH_TOKEN: ***
/usr/bin/docker run --name ee60bbcecefc8ca49b4bec52a603582fdca_ba0c13 --label 671ee6 --workdir /github/workspace --rm -e NPM_CONFIG_USERCONFIG -e NODE_AUTH_TOKEN -e GITHUB_TOKEN -e NPM_AUTH_TOKEN -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e GITHUB_ACTIONS=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/webpart-common/webpart-common":"/github/workspace" 671ee6:0bbcecefc8ca49b4bec52a603582fdca
/entrypoint.sh: 17: /entrypoint.sh: cannot create /home/runner/work/_temp/.npmrc: Directory nonexistent
##[error]Docker run failed with exit code 2

I'm going to experiment a little bit using the GH Token in the .npmrc file.

@geoperez
Copy link
Author

Quick update, the run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > ~/.npmrc is not working neither 😭

@lughino
Copy link

lughino commented Jan 28, 2020

@geoperez have you got any luck with this issue?

@geoperez
Copy link
Author

My latest issue is the argument NPM_CONFIG_USERCONFIG. I'm getting:

Run mikeal/merge-release@master
  env:
    NPM_CONFIG_USERCONFIG: /home/runner/work/_temp/.npmrc
    NODE_AUTH_TOKEN: XXXXX-XXXXX-XXXXX-XXXXX
    GITHUB_TOKEN: ***
    NPM_AUTH_TOKEN: ***

/entrypoint.sh: 17: /entrypoint.sh: cannot create /home/runner/work/_temp/.npmrc: Directory nonexistent

If I change the NPM_CONFIG_USERCONFIG to the value ~/.npmrc. Same error.

@beatthat
Copy link
Contributor

beatthat commented Feb 13, 2020

I also want to publish my packages to GPR, so first off, thanks for making this useful action @mikeal!

I'm looking at the code to try to figure out how to set it up, and I think there may be a bug hard coding the registry to npm for when it checks the current version:

const get = bent('json', 'https://registry.npmjs.org/')

Should it be changed like this?

const get = bent('json', process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org/')

@mikeal
Copy link
Owner

mikeal commented Feb 13, 2020

ah, yes! that does need to get changed :)

PR’s welcome :)

@kf6kjg
Copy link

kf6kjg commented May 5, 2020

Looks like #17 added the NPM_REGISTRY_URL env var.

Here's my set up:

      - name: Get the publish registry
        # Remove this whenandif merge-release can read direcly from the package.json
        run: |
          echo "::set-env name=NPM_REGISTRY_URL::$(node -p "require('./package.json').publishConfig.registry")"

      - name: Publish
        uses: mikeal/merge-release@14c90d7780f48402b0797da25ee5644f85f50302 # Change to v4 or newer once he gets the build fixed.
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

However it is behaving rather strangely and dropping the following error when the action runs:

npx merge-release
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://https//npm.pkg.github.com/merge-release failed, reason: getaddrinfo ENOTFOUND https

After doing some digging it looks like entrypoint.sh is expecting different semantics than the rest of the project.

EDIT:
I say different semantics because while entrypoint.sh expects NPM_REGISTRY_URL to be a URL without a scheme or trailing slash, merge-release-run.js expects the reverse:

NPM_REGISTRY_URL="${NPM_REGISTRY_URL-registry.npmjs.org}"

vs

const get = bent('json', process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org/')

@frankdilo
Copy link

I got this error:

npm ERR! network request to https://https//npm.pkg.github.com/REDACTED failed, reason: getaddrinfo ENOTFOUND https

And traced it down to:

printf "//%s/:_authToken=%s\\nregistry=%s\\nstrict-ssl=%s" "$NPM_REGISTRY_URL" "$NPM_AUTH_TOKEN" "${NPM_REGISTRY_SCHEME}://$NPM_REGISTRY_URL" "${NPM_STRICT_SSL}" > "$NPM_CONFIG_USERCONFIG"

Removing the redundant NPM_REGISTRY_SCHEME from that line fixed my workflow when publishing to GitHub Package registry.

Here is my fork: https://github.com/frankdilo/merge-release

And my configuration for the workflow:

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_REGISTRY_URL: https://npm.pkg.github.com/

@norbinsh
Copy link

norbinsh commented Dec 6, 2020

@frankdilo i had exactly same issue as yours. using your fork, it seem to have fixed it, but now i am getting the following:

using src directory (package.json) : /github/workspace/
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"

my config:

  - name: Publish NPM Package
    uses: frankdilo/merge-release@master
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      NPM_REGISTRY_URL: https://npm.pkg.github.com/

thoughts? does it work for you?

@frankdilo
Copy link

@norbinsh consider adding an .npmrc with the following content in your repo root dir:

//npm.pkg.github.com/:_authToken=${NPM_AUTH_TOKEN}

@norbinsh
Copy link

norbinsh commented Dec 6, 2020

@norbinsh consider adding an .npmrc with the following content in your repo root dir:

//npm.pkg.github.com/:_authToken=${NPM_AUTH_TOKEN}

that did the trick, thank you.

@benwinding
Copy link
Contributor

Seems to be easily achieved using the following configuration (based on above answers).

  1. Make sure you have your .npmrc file with the following contents
//npm.pkg.github.com/:_authToken=YOUR_PERSONAL_ACCESS_TOKEN
@YOUR_ORG:registry=https://npm.pkg.github.com
  1. Make sure your workflow looks like
      - name: Deploy to GPR 🚀
        uses: mikeal/merge-release@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_REGISTRY_URL: https://npm.pkg.github.com/

Also, you need to publish the package manually first, using npm publish as merge-release trys to download previous version of the package.

This issue can probably be closed, seems to work as intended.

kf6kjg added a commit to SlideWave/gitignore-include that referenced this issue Sep 9, 2022
kf6kjg added a commit to SlideWave/gitignore-include that referenced this issue Sep 9, 2022
@kf6kjg
Copy link

kf6kjg commented Sep 9, 2022

@benwinding Yeah that's not working for me.

@activenode
Copy link

For me neither.

@benwinding Yeah that's not working for me.

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

No branches or pull requests

9 participants