1

Update2: I spent way to many hours trying to make this work, it has been tiring and frustrating, I am now doing everything manually. I do the release manually and I publish the package locally with my terminal, as it works fine with no problem. I tried all the possible fixes, but there is no way to make this thing work, any help would be greatly appreciated. Update: Does the fact that the package is private from our org makes any difference? I looked at all the tutorials, and I used github action template for publishing github actions and still no results, this is very frustrating, how come looks so easy in the tutorial? Everything I try is failing, although it publishes the packages, which is even weird. Here is the code from github:

  publish-gpr:
    needs: release
    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/
      - run: yarn
      - run: yarn publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

I am trying to publish a private package to Github using semantic-release This is my workflow file

name: Release
on:
  push:
    branches:
      - main

permissions:
  contents: read # for checkout

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    permissions: write-all
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 'lts/*'
          registry-url: 'https://npm.pkg.github.com'
          scope: '@scope' // private scope 

      - name: Get yarn cache
        uses: actions/cache@v2
        id: yarn-cache
        with:
          path: node_modules
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/**.yml') }}

      - name: Install Node.js dependencies
        if: steps.yarn-cache.outputs.cache-hit != 'true'
        run: yarn install --frozen-lockfile

      - name: Run linting
        run: yarn lint

      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: yarn semantic-release

      - name: Publish to Github
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
        run: yarn publish

But when I run it, the release is created correctly but the package is not published, I get an error:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://npm.pkg.github.com/
npm ERR! need auth You need to authorize this machine using `npm adduser`

Is getting quite frustrating as I don't get why, I literally took the code from github and semantic-release tutorials. I do not want to publish to npm, but only to github for my team (@scope is replaced with our org name) What am I doing wrong?

Kaiser Soze
  • 1,362
  • 3
  • 14
  • 31
  • It is actually publishing the package, but still the CI workflow fails, I am kinda of desperate, I understand I need to create a .npmrc file in the workflow but how? – Kaiser Soze Jun 19 '23 at 09:18
  • Could you add to permissions `packages: write`? – Krzysztof Madej Jun 19 '23 at 10:53
  • I added but nothing. Here is an update version, taken straight from github action templates ... ``` publish-gpr: needs: release 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/ - run: yarn - run: yarn publish env: NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} ``` – Kaiser Soze Jun 19 '23 at 11:03
  • See: https://github.com/actions/setup-node/issues/49#issuecomment-1293249466 – jessehouwing Jun 19 '23 at 11:24
  • I am using @semantic-release/github should this publish the package without me publishing it manually? – Kaiser Soze Jun 19 '23 at 11:30

0 Answers0