pnpm / action-setup

Install pnpm package manager
https://github.com/marketplace/actions/setup-pnpm
MIT License
899 stars 87 forks source link

How to add personal access tokens as environment variables to a action ? #73

Open chlbri opened 1 year ago

chlbri commented 1 year ago

I have a personnel token that helps me to read packages create by my organization.

Capture d'écran 2023-01-07 à 15 07 08 PM

How can I integrate it as env variable to an action.

I try to access it by secrets:

Capture d'écran 2023-01-07 à 15 20 10 PM

But it's not working.

Run pnpm install --no-frozen-lockfile
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:8)
Lockfile is up to date, resolution step is skipped
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:9)
Progress: resolved 1, reused 0, downloaded 0, added 0
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:10)
Packages: +247
[(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:11)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:12)
Packages are hard linked from the content-addressable store to the virtual store.
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:13)
  Content-addressable store is at: /home/runner/setup-pnpm/node_modules/.bin/store/v3
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:14)
  Virtual store is at:             node_modules/.pnpm
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:15)
Progress: resolved 247, reused 0, downloaded 30, added 25
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:16)
Progress: resolved 247, reused 0, downloaded 77, added 72
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:17)
 ERR_PNPM_FETCH_401  GET https://npm.pkg.github.com/download/@chlbri/beme-news1-core/0.1.2/c3a87044cdf2a55d54161c2d3678fd3f1228b828: Unauthorized - 401
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:18)

(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:19)
An authorization header was used: ***
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:20)

(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:21)
These authorization settings were found:
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:22)
@chlbri:registry=https://npm.pkg.github.com/
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:23)
//npm.pkg.github.com/:_authToken=[hidden]
(https://github.com/chlbri/beme-news1-table/actions/runs/3862708222/jobs/6584443508#step:5:24)
Error: Process completed with exit code 1.

Can you help me ?

juanpicado commented 1 year ago

You can try this https://github.com/pnpm/pnpm/issues/3141#issuecomment-1305563972

I copy here the solution adapted

      - name: Set token config
        run: |
          echo "//npm.pkg.github.com/:_authToken=${secrets.NPM_TOKEN}" > .npmrc
          echo "@yourScope=https://npm.pkg.github.com/" >> .npmrc
          echo "_auth=${secrets.NPM_TOKEN}" >> .npmrc
          echo "always-auth=true" >> .npmrc
        env:
          secrets.NPM_TOKEN: ${{secrets.NPM_TOKEN}}
      - name: Install
        run: pnpm install

Keep on mind that pnpm is able to read from .npmrc so this should works fine. If you have troubles you can always increase the logging to see more in detail what is returning the registry.

jamesarosen commented 1 year ago

@juanpicado that looks like what you'd use to access a private NPM package, not a private GitHub repo.

KSXGitHub commented 1 year ago

Apologize for late response.

Does this work? https://pnpm.io/npmrc#url_authtoken