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

npm requires npm login in github actions #1042

Closed
phun-ky opened this issue Sep 21, 2023 · 7 comments
Closed

npm requires npm login in github actions #1042

phun-ky opened this issue Sep 21, 2023 · 7 comments

Comments

@phun-ky
Copy link

phun-ky commented Sep 21, 2023

I have set NPM_TOKEN in action secrets, and I have this setup:

publish.yml:

# This is a basic workflow to help you get started with Actions

name: Publish

# Controls when the workflow will run
on:
  pull_request:
    types: [closed]
    branches: [ "main" ]
  workflow_dispatch:
jobs:
  publish:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0 # Checkout all branches and tags
      - name: Setup Node.js environment
        uses: actions/setup-node@v2.5.2
        with:
          node-version: 18
      - name: Install dependencies
        run: | # Install and link dependencies
          npm i
      - name: "Release" # Interesting step
        run: |
          git config user.name "${{ github.actor }}"
          git config user.email "${{ github.actor}}@users.noreply.github.com"
          npm run release
  notify:
    name: Notify failed build
    needs: publish
    if: failure() && github.event.pull_request == null
    runs-on: ubuntu-latest
    steps:
      - uses: jayqi/failed-build-issue-action@v1
        with:
          github-token: ${{ secrets.GH_TOKEN }}

.npmrc:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

*.release-it.json:

{
  "git": {
    "commitMessage": "chore: 🤖 release v${version}"
  },
  "github": {
    "release": true,
    "tokenRef": "GH_TOKEN"
  },
  "npm": {
    "publish": true
  },
  "plugins": {
    "@release-it/conventional-changelog": {
      "preset": {
        "name": "conventionalcommits"
      },
      "infile": "CHANGELOG.md"
    }
  }
}

What could be the issue here?

@webpro
Copy link
Collaborator

webpro commented Sep 23, 2023

What do you see? What did you try?

Are the tokens available as environment variables for release-it to pick them up?

@phun-ky
Copy link
Author

phun-ky commented Sep 26, 2023

image

I tried to use a publish workflow with github actions. I have NPM_TOKEN set as a repository secret

@JoshuaKGoldberg
Copy link

FWIW I've been manually running npm config set:

@phun-ky I'm under the impression GitHub Actions require explicitly passing environment variables to actions. Example:

      - name: "Release" # Interesting step
        run: |
          git config user.name "${{ github.actor }}"
          git config user.email "${{ github.actor}}@users.noreply.github.com"
          npm run release
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Just confirming, have you tried that? (or am I wrong?)

@AlexandreAtErgosign
Copy link

I am currently facing this issue with

- name: Release with release-it
        run: |
          git config user.name "${{ github.actor }}"
          git config user.email "${{ github.actor}}@users.noreply.github.com"
          npm run release-it-$RELEASE_LEVEL
        env:
          RELEASE_LEVEL: ${{ github.event.inputs.version_inc }}
          GITHUB_TOKEN: ${{ secrets.GTIHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.GTIHUB_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.GTIHUB_TOKEN }}

I get

 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`

Also note that I am trying to publish on the registry github packages.

@webpro
Copy link
Collaborator

webpro commented Oct 10, 2023

Did you auth against https://npm.pkg.github.com/? Didn't use this myself, but here's two things you could try:

  • Set package.json#publishConfig.registry properly
  • Use something like npm config set //npm.pkg.github.com/:_authToken $NPM_TOKEN

@AlexandreAtErgosign
Copy link

AlexandreAtErgosign commented Oct 10, 2023

I am currently facing this issue with

- name: Release with release-it
        run: |
          git config user.name "${{ github.actor }}"
          git config user.email "${{ github.actor}}@users.noreply.github.com"
          npm run release-it-$RELEASE_LEVEL
        env:
          RELEASE_LEVEL: ${{ github.event.inputs.version_inc }}
          GITHUB_TOKEN: ${{ secrets.GTIHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.GTIHUB_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.GTIHUB_TOKEN }}

I get

 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`

Also note that I am trying to publish on the registry github packages.

Dummy but it is a typo NPM_TOKEN: ${{ secrets.GTIHUB_TOKEN }}. It should be GITHUB.

Thanks for your quick support and response though!

@phun-ky
Copy link
Author

phun-ky commented Oct 19, 2023

This is fixed on my end now. Thanks!

@phun-ky phun-ky closed this as completed Oct 19, 2023
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

4 participants