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
- Create an organization on Github.
- Upload your repo to your org and set it as the remote origin
- 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
I got this error on org repos too.
The solution for me was:
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
github-action-<my repository name>
2. Get that service account’s key and add it to your repository as a secret
FIREBASE_SERVICE_ACCOUNT_<PROJECT_ID>
(example:FIREBASE_SERVICE_ACCOUNT_MY_COOL_APP
)3. Add a workflow yaml file to your repository
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:
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…
@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.
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