mikeal / merge-release

Automatically release all merges to master on npm.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Publish to GitHub Package Registry

geoperez opened this issue · comments

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!

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.

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

@geoperez have you got any luck with this issue?

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.

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/')

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

PR’s welcome :)

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/')

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/

@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?

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

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

@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.

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.

@benwinding Yeah that's not working for me.

For me neither.

@benwinding Yeah that's not working for me.