I am transitioning my CI/CD over to Github Actions and noticed that my prior scripts for deploying Firebase do not work.
When I try to switch projects via firebase use staging --debug it errors with the error:
[2020-04-14T12:51:59.154Z] > command requires scopes:
["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
If I use firebase use --debug to see what project is active, I get
Error: No active project
These scripts work without fault on CircleCI so I am confused as to why they break on Github Actions. They also work perfectly in my local environment.
I have tried various versions of node, and installing the firebase tools, however they all result in the same error. I have generated a new token generated via firebase login:ci.
Here is a sample of my Github Actions workflow:
deploy_staging:
name: Deploy to staging
needs: eslint_test_build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: "10.x"
...
- name: Deploy to Firebase
run: |
npm install -g firebase-tools
firebase -V # this will work
firebase use staging # this will fail
firebase functions:config:set sentry.dsn=$DSN
firebase deploy --only hosting:admin --token "$TOKEN" --non-interactive
env:
TOKEN: ${{ secrets.firebase_token }}
--update
When I just use deploy it works. Is the deploy Firebase CLI command the only one allowed for Github Actions?
This works:
- name: Deploy to Firebase
run: |
npm install -g firebase-tools
firebase deploy --only hosting:admin --project=staging --token "$TOKEN" --non-interactive
Related
When I try to deploy nextjs project on firebase with GitHub action, I got an error message
Error: Cannot deploy a web framework to hosting because the experiment webframeworks is not enabled. To enable webframeworks run firebase experiments:enable webframeworks
I tried
firebase experiments:enable webframeworks
from my computer but it still did not work.
Here is the yaml file for the GitHub action.
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- main
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy#v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}'
channelId: live
projectId: my-project
Could you help me to enable webframeworks with GitHub actions?
Thanks!
You can enable webframeworks by updating the yaml like so:
- uses: FirebaseExtended/action-hosting-deploy#v0
with:
# ...
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
The pull request that implemented the feature is: firebase-tools#5069
This feature was introduced at version v11.14.2.
I'm trying to run Firebase Emulator on Bitbucket Pipeline. It fails because "java is not installed".
How can I "install java" on a Bitbucket Pipeline. Or is there another way to get it to work?
My step currently looks like this:
- step: &test-rules
name: 'Test Firestore Rules (DEV)'
image: node:16.13.2
script:
- npm ci --prefix firebase-test
- npm install -g firebase-tools
- npm run test --prefix firebase-test
npm run test runs this script:
firebase emulators:exec --only firestore "mocha --exit"
I recently moved into GitHub actions, so what I'm trying to do is host my react project in firebase when a push is done. And I used GitHub actions to this CI/CD process. And this is the main.yml that I have right now.
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout#master
- name: Install Dependencies
working-directory: ./my-app
run: npm install
- name: Build
working-directory: ./my-app
run: npm run build
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout#master
- name: Deploy to Firebase
uses: w9jds/firebase-action#master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
And I somehow manage to set the working directory when npm installation and project building. But in deployment I'm keep getting this error,
So what I have understood is, this error occurs due to the working directory problem. So my current project structure looks like this.
. (root of my GitHub repository)
└── my-app
├── firebase.json <-- Git Hub action must point to this sub-dir
└── my-app-mobile
├── packages.json
So how should I do this within my firebase deployment process? If I'm wrong with the problem, What would be the problem and the answer? It seems I can't use working-directory: ./my-app with uses:
I looked at the documentation for the firebase CLI and didn't see any way to set the path to your firebase.json via a CLI parameter. There is, however, an environment variable that stores the root directory. It's in the context of predeploy and postdeploy hooks though, so I'm not sure if the CLI will respect it.
$PROJECT_DIR — The root directory containing firebase.json
https://firebase.google.com/docs/cli#environment_variables
The w9jds/firebase-action you are using is just a wrapper around the CLI. I'm not sure if this will work but you could try setting the project directory as follows. The reason the variable is set in a separate step is because you cannot evaluate expressions in env sections. See this answer for more detail. Container actions like w9jds/firebase-action will have access to the variable without passing it directly via env.
- name: Set project dir environment var
run: echo ::set-env name=PROJECT_DIR::"$GITHUB_WORKSPACE/my-app"
- name: Deploy to Firebase
uses: w9jds/firebase-action#master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
If that doesn't work, an alternative is to fork w9jds/firebase-action and add a PROJECT_PATH parameter to the entrypoint.sh script here:
https://github.com/w9jds/firebase-action/blob/master/entrypoint.sh
Update: I raised a PR to add a PROJECT_PATH parameter to w9jds/firebase-action. You can now use the action as follows.
- name: Deploy to Firebase
uses: w9jds/firebase-action#master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_PATH: ./my-app
I try to deploy my angular application on firebase using gitlab pipeline.
I followed this guide and I write a gitlab-ci file more simplified for starting.
image: node:latest
cache:
paths:
- node-modules/
stages:
- deploy
deploy:
stage: deploy
environment:
name: development
script:
- npm install -g firebase-tools
- npm install
- npm run builddev
- npm run deploy
only:
- master
Everything work until last command when I have this error
but if from terminal I run
firebase deploy --project test-1c121
everything work fine
Check your package.json file in scripts section. You probably have a typo in deploy because npm runs into problem with running firebse command and you want to run firebase.
I added .travis.yml to my project and each time I commit to master branch, it runs all tests / scripts ok but last firebase deploy fails consistently with error like below:
But certainly I am installing dependencies under functions folder and can deploy on localhost with no problem.
My .travis.yml looks like:
language: node_js
node_js:
- 6
branches:
only:
- master
install:
- yarn
- CI=false yarn build:ssr
- yarn fns:deps
after_success:
- node_modules/.bin/firebase deploy --non-interactive --token "$FIREBASE_TOKEN" --project react-joanne
deploy:
provider: firebase
skip_cleanup: true
token:
secure: "$FIREBASE_TOKEN"
project: "react-joanne"