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

Unable to publish Github package #269

Closed
Zenoo opened this issue Jun 16, 2021 · 4 comments
Closed

Unable to publish Github package #269

Zenoo opened this issue Jun 16, 2021 · 4 comments

Comments

@Zenoo
Copy link

Zenoo commented Jun 16, 2021

I am trying to setup a workflow that publishes a Github package, but I can't seem to make it work.

Here is a simplified workflow I created to try it:

https://github.com/Zenoo/slick-loader/blob/master/.github/workflows/npm-publish.yml

name: Node.js Package

on:
  workflow_dispatch:

jobs:
  publish-gpr:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

But the process always fails:

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/slick-loader - Not found
npm ERR! 404 
npm ERR! 404  'slick-loader@1.1.35' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-06-16T08_47_48_768Z-debug.log
Error: Process completed with exit code 1.
@anantoghosh
Copy link

anantoghosh commented Jun 26, 2021

Publishing to github requires some configurations:
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#publishing-a-package-using-a-local-npmrc-file

  1. Your package name should have the scope with your github username @<username>/<packagename>.
  2. Change the publish command for github to npm publish --@<username>:registry=https://npm.pkg.github.com/.
  3. If you are releasing to npm registry too, change that npm publish to npm publish --access public. This will publish a scoped packaged to npm.

All this confusion arises from the expectation that the node publish workflow will just work right out of the box 😕 .

@Zenoo
Copy link
Author

Zenoo commented Jun 26, 2021

@anantoghosh What can I do if my package doesn't have the scope with my username?
The package has already been published on NPM for a long time, I can't just rename it.
Same for your second and third point: My package name doesn't contain a scope ^^'

@anantoghosh
Copy link

anantoghosh commented Jun 27, 2021

Even though there are some comments saying that this should be possible #73 (comment) #243 (comment), all possible combinations of configurations I tried did not solve the issue.

As a hack I though I could rename the package name to add the scope in the gpr action but then I start getting this problem #215, using npm config (because I was installing a global package for editing the json and needed to set npm prefix) causes the / after scope to get encoded into %2f which I was unable to fix with multiple different configurations.
I searched briefly through github to find other packages which tried this and all but two failed in publishing to gpr.
https://github.com/bats-core/bats-core/blob/eac1e9d047b2b8137d85307fc94439c90bdc25ae/.github/workflows/release.yml#L51
They are using npm init --scope username to rename the package and this works for me too, gpr publish works, but using npm init in my project adds dependencies into the package.json file which I don't need so this was a no go too.

https://github.com/hujiulong/vue-3d-model/blob/master/scripts/gpr-setup.js
They are using a node script to rename, this is what I went with too (modified for type: "module"):

// gpr-hack.js
import { writeFileSync, readFileSync } from "fs";

const file = readFileSync("./package.json", {
  encoding: "utf-8",
});

const json = JSON.parse(file);

json.name = "@name/pkgname";

writeFileSync("./package.json", JSON.stringify(json, undefined, 2));

Final solution looks like this:

publish-gpr:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 14
          registry-url: https://npm.pkg.github.com/
          scope: "@name"
      - run: node gpr-hack.js
      - run: npm ci
      - run: npm run build
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

It took me quite some time to get this to work mainly due to #215, this may also cause trouble if npm config were to be used eg: for installing global packages.

note: yarn may behave differently

@Zenoo
Copy link
Author

Zenoo commented Jun 27, 2021

Thanks a lot ! It works with the GPR hack.
I will probably create a plug & play action that handles both npm and Github packages, it's too much of a hassle to expect anyone to use this.

@Zenoo Zenoo closed this as completed Jun 27, 2021
tehw0lf added a commit to tehw0lf/tehwol.fi that referenced this issue Dec 15, 2021
Even though we don't publish to gpr but npm, the problem looks similar.

actions/setup-node#269
bafu added a commit to numbersprotocol/nit that referenced this issue Feb 13, 2023
actions/setup-node#269 (comment)

Signed-off-by: Bofu Chen (bafu) <bofu@numbersprotocol.io>
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

2 participants