FirebaseExtended / action-hosting-deploy

Automatically deploy shareable previews for your Firebase Hosting sites
https://firebase.google.com/docs/hosting/github-integration
Apache License 2.0
670 stars 195 forks source link

[BUG] The action fails to authenticate to private npm registry #379

Open serpro69 opened 3 weeks ago

serpro69 commented 3 weeks ago

Action config

This is a slightly modified (from default generated) workflow that I have:

# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
on:
  push:
    branches:
      - develop
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 18
          registry-url: "https://npm.pkg.github.com"
          scope: "@org-name"
          always-auth: true
      - run: npm ci && npm run build
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_FIREBASE_SANDBOX_425310 }}
          channelId: live
          projectId: firebase-sandbox-425310
        env:
          FIREBASE_CLI_EXPERIMENTS: webframeworks,pintags
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Error message

Firebase deployment fails with nnpm ERR! 401 Unauthorized - GET https://npm.pkg.github.com/download/@org-name/app-components-frontend/0.18.33/233b5141a9f47e0a5863ebb4cd714b82c4c87100 - authentication token not provided

Expected behavior

While npm ci works fine because it uses an .npmrc file generated by the setup-node action, firebase hosting deploy action doesn't seem to be picking that up.

I've tried to find something in the docs of either firebase tools or the action, but didn't find anything that would help me resolve this.

Actual behavior

Auth to npm registry fails and hence deployment fails

serpro69 commented 3 weeks ago

Found https://github.com/firebase/firebase-tools/issues/5936 , could be related? I guess this needs to be fixed in firebase-tools Still, maybe there's something that the action can do to help here? Like, temporary copy an .npmrc file with an embedded token? (I think I'll try to do this "manually" now and see how that goes)

jasonmit commented 1 week ago

@serpro69 I am running into this same issue, did you ever discover a workaround?

serpro69 commented 1 week ago

Hi @jasonmit , As far as I understood, this is a firebase(-tooling) issue, not an issue with this action (but I kept this one open just to have the maintainers confirm that; or maybe add some support from the action side, if possible) The only current workaround I know of is to hardcode the token in the .npmrc file. Regular firebase hosting doesn't seem to support environment variables (The new apphosting seems to , but we're not using that)