action-hosting-deploy: firebase init hosting:github, 404 error if the repo belongs to an organization

First off, I’m brand new to firebase hosting and github actions, so it’s entirely possible that I’m approaching this the wrong way, but I haven’t found any mention of this being incorrect in the docs.

To reproduce

  1. Create an organization on Github.
  2. Upload your repo to your org and set it as the remote origin
  3. Locally, use the command firebase init hosting:github

I authenticate successfully, then I’m prompted to enter the name of the repo, and it even suggests the correct repo in the format my-org-name/my-repo-name. So, I enter that but get the error FirebaseError: HTTP Error: 404, Not Found

Analysis

Looking at the firebase-debug.log, it looks like the cli makes the assumption that the repo belongs to a user, which isn’t correct in this case i.e. from what I entered, it’s forming the request: HTTP REQUEST GET https://api.github.com/repos/my-org-name/my-repo-name/actions/secrets/public-key?type=owner but the API is expecting: ...api.github.com/repos/my-github-username/my-repo-name/...

However, if I enter my-github-username/my-repo-name at the prompt, I get the same error but that’s because the repo doesn’t exist under my account, it belongs to the org.

Maybe it’s a limitation of Github’s API? Or maybe your intention is that developers always fork the repo, so this is more of a documentation issue (or lack of knowledge on my behalf)?

To work around this, I’m going to transfer the repo to my account, but I thought I’d mention it here.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 52
  • Comments: 19

Most upvoted comments

I got this error on org repos too.

The solution for me was:

  1. Open https://github.com/settings/connections/applications
  2. Select the Firebase CLI application
  3. Look for the section Organisation Access
  4. Click the “Grant” button next to the organisation you want to grant Firebase CLI access to

After that, I was able to run firebase init hosting:github

I report this during a hackhaton 😄 : ALL you have to do is first grant Firebase CLI 3rd party github app in https://github.com/settings/applications and THEN do firebase init hosting:github. and enter it as organization/repo-name

If it’s not already among your integrated apps you can run firebase init hosting:github on a repo that YOUR username owns, because that will prompt you with the website to authorize Firabse CLI.

EDIT June 17, 2021: Take a look at @alkiko’s comment below. You may not need to follow these manual service account creation steps!

Thanks for the report, @JohnFitz and @TheBestMoshe! And sorry for the delay in getting back to you. This is a CLI bug, so I’ve filed it here: https://github.com/firebase/firebase-tools/issues/2763

The workaround is to manually set up this GitHub action yourself until that’s fixed. To do that:

1. Create a service account that the action will use to deploy to Hosting

  1. Visit the GCP Service Accounts page and make sure the correct project (same name as your Firebase project) is selected in the top blue bar
  2. Click the “+ CREATE SERVICE ACCOUNT” button
  3. Give the service account a name, id, description. We recommend something like github-action-<my repository name>
  4. At the “Grant this service account access to project” step, choose the following roles that the service account will need to deploy on your behalf:
    • Firebase Authentication Admin
    • Firebase Hosting Admin
    • Cloud Run Viewer
    • API Keys Viewer
  5. Finish the service account creation flow

2. Get that service account’s key and add it to your repository as a secret

  1. Create and download the new service account’s JSON key
  2. Add that JSON key as a secret in your GitHub repository. We recommend a name like FIREBASE_SERVICE_ACCOUNT_<PROJECT_ID> (example: FIREBASE_SERVICE_ACCOUNT_MY_COOL_APP)

3. Add a workflow yaml file to your repository

  1. Add a yml file as described here. Be sure to reference your new secret for the firebaseServiceAccount option.

Please let me know if you get stuck in any part of the process. Happy to clarify any of the steps in this workaround.

(UPDATE Dec 23, 2020: this process is now documented here)

I am having the same issue

@jhuleatt you should edit your post with the “workaround” and just point people towards this post further down:

I got this error on org repos too.

The solution for me was:

  1. Open https://github.com/settings/connections/applications
  2. Select the Firebase CLI application
  3. Look for the section Organisation Access
  4. Click the “Grant” button next to the organisation you want to grant Firebase CLI access to

After that, I was able to run firebase init hosting:github

None of the complicated manual workaround is required when just following this post, it’s way easier!

However, since your “workaround” is the first post appearing, I’m afraid many devs come here and first try this manual difficult method…

  1. Go to your Account Settings
  2. Select Applications
  3. Switch to the Authorized OAuth Apps tab
  4. Select Firebase CLI
  5. Under Organization access, grant it access to the Organisation

@alkiko Thank you, this worked for me. My organization was listed there but it was granted access (with a red x). You just have to press the Grant button and you can continue going through the Firebase CLI, with no extra steps. Easy Peezy, thank you.

I report this during a hackhaton 😄 : ALL you have to do is first grant Firebase CLI 3rd party github app in https://github.com/settings/applications and THEN do firebase init hosting:github. and enter it as organization/repo-name

If it’s not already among your integrated apps you can run firebase init hosting:github on a repo that YOUR username owns, because that will prompt you with the website to authorize Firabse CLI.

This works. Just grant Friebase CLI access to your organisation account.

@alkiko Worked like a charm

@alkiko Thank you. It worked after granting Firebase CLI access to my GitHub organization

@alkiko 's answer worked me as well.

@najibghadri, thanks for the reply. I reran the test today and it didn’t give me the same error. Perhaps it takes some time to propagate the secrets? I received a new error stating that the Firebase Hosting API needed to be enabled, so I enabled that, waited about 20 minutes (since the error mentioned it would take a few minutes to propagate), and then it worked ✅

Much appreciated