can GITHUB_TOKEN used to publish npm package to GitHub npm registry ? #60044
-
| Select Topic AreaQuestion BodyI was trying to publish a npm package to GitHub npm registry and here is my github action yaml: jobs:
  publish-gpr:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          registry-url: https://npm.pkg.github.com/
          # this is my org place holder , I've change the example to my real org
          scope: '@EXAMPLE'
      - name: Install pnpm
        uses: pnpm/action-setup@v2
        with:
          version: 8
          run_install: false
      - run: -|
          pnpm install
          pnpm build
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}it report error: npm notice Publishing to https://npm.pkg.github.com/ with tag latest and default access
npm ERR! code E403
# this example is also a replace for this discussion
npm ERR! 403 403 Forbidden - PUT https://npm.pkg.github.com/@example%2ftest - Permission permission_denied: write_package
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.but I've already give write package permission for this job. If I only change the GITHUB_TOKEN to my personal token , this workflow will publish success. I've read the docs Publishing and installing a package with GitHub Actions. I'm not sure if repository-scoped permissions are required when publishing a package. However, I noticed that the container registry does not support repository-scoped permissions, but can still publishing-a-package-using-an-action by GITHUB_TOKEN | 
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
| I have finally identified the issue. I published the package without specifying the repository field, which caused GitHub to disconnect this package from my source code repository. Therefore, I must link the package to the source repository manually. Additionally, when establishing this connection on my own, it is imperative to manage Action access; this entails granting action access to the source repository and enabling the option to inherit access from the source repository, which is recommended. Once I enable these two permissions, I will be able to publish the npm package to the GitHub npm registry using the GitHub Actions workflow that includes the "GITHUB_TOKEN." | 
Beta Was this translation helpful? Give feedback.
-
| For others having a similar issue, you might experience this problem as a by product of a repository organization migration, which does not address the fact that packages could still tied to the previous org. If this is your case: 
 In case the repo is a greenfield setup,  | 
Beta Was this translation helpful? Give feedback.
I have finally identified the issue. I published the package without specifying the repository field, which caused GitHub to disconnect this package from my source code repository. Therefore, I must link the package to the source repository manually. Additionally, when establishing this connection on my own, it is imperative to manage Action access; this entails granting action access to the source repository and enabling the option to inherit access from the source repository, which is recommended. Once I enable these two permissions, I will be able to publish the npm package to the GitHub npm registry using the GitHub Actions workflow that includes the "GITHUB_TOKEN."