Firebase Emulator on Bitbucket Pipeline - firebase

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"

Related

Firebase emulators:exec with 'npm test' script returns immediately

I'm running some React integration tests with npm, and need the Firebase emulator for them. I've set up my npm scripts as follows:
"scripts": {
"test:integration:runner": "cross-env RTL_SKIP_AUTO_CLEANUP=true FIREBASE_DATABASE_EMULATOR_HOST=\"localhost:9000\" FIREBASE_FUNCTIONS_EMULATOR_HOST=\"localhost:5001\" FIREBASE_AUTH_EMULATOR_HOST=\"localhost:9099\" react-scripts test ./src/integrationTests/App.spec.js --watchAll=false",
"test:integration": "firebase emulators:exec 'npm run test:integration:runner'",
},
However, when I run npm run test:integration, the script returns after about 1 second, with no errors. Here is the only ouput:
PS C:\Users\{userame}\{project}> npm run test:integration
> {project_name} test:integration
> firebase emulators:exec 'npm run test:integration:runner'
PS C:\Users\{userame}\{project}>
The firebase emulator itself is working if I run it standalone, and I tested the integration test with the emulator already running, and that works as well. I tried running firebase emulators:exec with a different non-npm script (instead of npm run test:integration:runner) and it successfully spun up the emulator. Any idea what might be happening here?
Well, I figured this out soon after asking the question. It turns out you need to double quote the script.
So I changed
"test:integration": "firebase emulators:exec 'npm run test:integration:runner'",
to
"test:integration": "firebase emulators:exec \"npm run test:integration:runner\" ",
I'd like to understand why this works though. This is in Windows, and I'm not sure how single/double quote semantics in commands might differ from what I'm used to.

How to Run & Connect to Emulators with Cypress CI on GitHub Actions?

I am trying to run e2e Cypress tests on Github actions. I build functions, run an emulator and start cypress like to:
npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch
This works well on localhost, but fails on GitHub Actions, when the first part of the code tries to connect to the emulators.
cy.request(
"DELETE",
"http://localhost:9099/emulator/v1/projects/****/accounts"
);
It can't reach the emulator on port localhost:9099, as I would normally do on localhost.
1) Login
runs setup:
CypressError: `cy.request()` failed trying to load:
http://localhost:9099/emulator/v1/projects/****/accounts
We attempted to make an http request to this URL but the request failed without a response.
Is there something I need to do about connecting to localhost port on GitHub Actions?
Solved! The Firebase emulator was throwing an error, but I haven't seen it because I ran it on one line with other commands: npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch
I rewrote the job in the workflow:
- name: Cypress run
uses: cypress-io/github-action#v2
with:
browser: chrome
build: npm run integration:build
start: |
npm run integration:emulate
npm run integration:test
Calling custom scripts from package.json like so:
"integration:build": "nx build functions && nx run frontend:build",
"integration:emulate": "firebase use default && firebase emulators:start",
"integration:test": "nx e2e frontend-e2e --watch",
Then I could see the Firebase error in the log and fixed them. There were two issues:
Selecting a project before running the emulators (adding firebase use default)
Firebase login (great answer from the Firebase team)
After that, the emulators worked just as on localhost 🥂

Deploy Back end server step in Play billing sample app

I've followed all the steps in here to get the "Classy Taxi: Google Play Billing Subscriptions Android App Java Sample" running, however on the last step I'm very confused, it´s not clear to me as to how I´m supposed to deploy the back-end, here are the steps:
These are steps to build the backend server code located here
Make sure you have installed Node.js, npm, and Firebase CLI.
Run npm install to install dependencies.
Configure Cloud Functions for Firebase with your Android app and subscription products:
firebase use --add {your_firebase_project_id}
firebase functions:config:set app.package_name="your_android_application_id"
firebase functions:config:set app.basic_plan_sku="your_basic_subscription_product_sku_id"
firebase functions:config:set app.premium_plan_sku="your_premium_subscription_product_sku_id"
Run firebase deploy to deploy your backend to Cloud Functions for Firebase.
On the steps it´s not clear as to how the server will be deployed, it only mentioned the app id and the products SKU´s but not the code for the server so I need help clarifying that, please. I would like to see steps by step how to deploy the server.
This is what I´m currently doing:
1. Go to the root folder for the server
2. Open cmd from that folder
3. run the commands listed on the docs.
4. then I get this error:
=== Deploying to 'billing-project-c9f03'...
i deploying functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\frank\Desktop\Billing app\ClassyTaxiServer\server\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\frank\Desktop\Billing app\ClassyTaxiServer\server\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\frank\AppData\Roaming\npm-cache\_logs\2020-04-13T01_21_30_198Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code429496323
But I see the package.json file on the root folder.
See the Firebase CLI reference. This should be the project's root directory ClassyTaxiServer; assuming that you've ran all previous steps successfully, before attempting to firebase deploy. firebase.json knows what to do... however, that file is the actual problem; see PR #289.
Update firebase.json to this version and it should work out:
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
],
"source": "."
},
"hosting": {
"public": "webapp",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [ ]
}
}

Github Actions Firebase error "command requires scopes"

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

Error during deploy from pipeline on firebase

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.

Resources