Deploying firebase cloud functions using github actions - firebase

I'm trying to deploy my firebase cloud functions app using github actions:
name: Deploy
'on':
push:
branches:
- main
jobs:
deploy_to_production:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: install dependencies
run: cd functions/ && npm install
- name: deploy to production
uses: w9jds/firebase-action#master
with:
args: deploy --only functions
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
The step "deploy to production" is not successful. I activate debug mode and I don't actually receive any useful information:
##[debug]Evaluating: secrets.FIREBASE_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'FIREBASE_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating condition for step: 'deploy to production'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: deploy to production
##[debug]Loading inputs
##[debug]Loading env
Run w9jds/firebase-action#master
with:
args: deploy --only functions
env:
FIREBASE_TOKEN: ***
/usr/bin/docker run --name w9jdsfirebaseactionv212_2c5197 --label 08450d --workdir /github/workspace --rm -e FIREBASE_TOKEN -e INPUT_ARGS -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_DEBUG -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/personalsite-backend/personalsite-backend":"/github/workspace" w9jds/firebase-action:v2.1.2 deploy --only functions
##[debug]Docker Action run completed with exit code 2
##[debug]Finishing: deploy to production
Am I missing something?
Note: Locally I can deploy without any problem.

By using w9jds/firebase-action, there's a known issue wherein if you use uses: w9jds/firebase-action#master, it tries to store what the CLI spits out and if it errors out and ends the action before it can echo it this might stop it from printing out the response. More information from the repository owner here.
Starting with version v2.1.2, you must replace this line:
uses: w9jds/firebase-action#master
to this:
uses: docker://w9jds/firebase-action:master
More information here.
Moreover, there is also an alternate solution to this by using actions/checkout instead. See yaml configuration below:
name: Deploy to Firebase Functions via github action
"on":
push:
branches:
- main
env:
CI: false
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download deps
working-directory: functions
run: npm install
- name: Deploy
run: npx firebase-tools deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
Note: I've used actions/checkout#v2 on the sample yaml above, but v3 is now available.

Related

ASP.NET Core publish actions, how to access NPM build files from previous step in .NET Core build step

I am working on configuring a deployment pipeline for my team. We are using Github Actions and I have most of it sorted, but ran into an issue when trying to run certain steps in a sequential order.
The app is ASP.NET Core MVC with some Blazor support. We are using webpack, webpack-cli css-loader & style-loader to bundle and minify our CSS and JS files.
The issue: I need to be able to run the npm build task before the .net core publish task in github actions. I am able to get the steps to run sequentially HOWEVER, the files generated in step 1 (the npm build) don't seem to be available to the .net core publish actions which happens after.
Question: what do I need to do in order to have the newly generated npm build files be used by the .net core publish action? I assume its a matter of moving them around to the correct location, however I am having trouble finding any good info on this. I have done Much trial and error, and research has been unfruitful.
Below is the yaml file and webpack file being used, and the command run is just npm run build
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: .net Publish
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
job1:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [15.x]
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
- name: build webpack
uses: actions/checkout#v1
- run: ls -a
- run: npm i
working-directory: ./ClientApp
- run: npm run build
working-directory: ./ClientApp
- run: pwd
- run: ls -a
- name: Persist npm build output
uses: actions/upload-artifact#v3
with:
name: npm-post-build
path: |
./wwwroot/dist/**
job2:
needs: job1
runs-on: ubuntu-latest
steps:
- name: Install Octopus Deploy CLI
uses: OctopusDeploy/install-octopus-cli-action#v1
with:
version: '*'
- uses: actions/checkout#v3
- name: Setup .NET
uses: actions/setup-dotnet#v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: replace dist with npm build artifact
uses: actions/download-artifact#v3
with:
name: npm-post-build
path: npm-post-build
- shell: bash
run: |
ls -a
rm -r wwwroot/dist
ls wwwroot
mv npm-post-build wwwroot/dist
ls wwwroot/dist
- name: Build
run: dotnet build --no-restore
- name: Publish
run: dotnet publish -p:PublishProfile=FolderProfile -o website
- name: package
run: |
shopt -s globstar
paths=()
for i in website/**; do
dir=${i%/*}
echo ${dir}
paths=(${paths[#]} ${dir})
done
eval uniquepaths=($(printf "%s\n" "${paths[#]}" | sort -u))
for i in "${uniquepaths[#]}"; do
echo $i
done
packages=()
versions=()
for path in "${uniquepaths[#]}"; do
dir=${path}/../../../..
parentdir=$(builtin cd $dir; pwd)
projectname=${parentdir##*/}
octo pack \
--basePath ${path} \
--id ${projectname} \
--version 1.0.0 \
--format zip \
--overwrite
packages=(${packages[#]} "${projectname}.1.0.0.zip")
versions=(${versions[#]} "${projectname}:1.0.0")
done
printf -v joined "%s," "${packages[#]}"
echo "::set-output name=artifacts::${joined%,}"
printf -v versionsjoinednewline "%s\n" "${versions[#]}"
versionsjoinednewline="${versionsjoinednewline//'%'/'%25'}"
versionsjoinednewline="${versionsjoinednewline//$'\n'/'%0A'}"
versionsjoinednewline="${versionsjoinednewline//$'\r'/'%0D'}"
echo "::set-output name=versions_new_line::${versionsjoinednewline%\n}"
echo "prepackage complete ${packages}"
- name: Push a package to Octopus Deploy
uses: OctopusDeploy/push-package-action#v3
env:
OCTOPUS_URL: https://****.octopus.app/
OCTOPUS_API_KEY: *****
OCTOPUS_SPACE: 'Default'
with:
overwrite_mode: OverwriteExisting
packages: runner.1.0.0.zip
const path = require('path');
module.exports = {
entry: {
site: '../wwwroot/js/site.js'
},
output: {
filename: '[name].entry.js',
path: path.resolve(__dirname, '..', 'wwwroot', 'dist')
},
devtool: 'source-map',
mode: 'development',
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(eot|woff(2)?|ttf|otf|svg)$/i,
type: 'asset'
},
]
}
};

Error using GitHub actions with R markdown

I'm new to using GitHub actions, so please be gentle with me! I'm trying to automate a script that I'm currently running using Windows Task Scheduler. I've written the yml code below and its stored (privately) on GitHub at jeremy-horne/Client/.github/workflows/
The RMD code is 900 lines long and works when run in R studio. It is stored on GitHub at jeremy-horne/Client
`
name: my_project
on:
schedule:
- cron: "18 17 */1 * *" # Every day at 18:17
jobs:
render-rmarkdown:
runs-on: ubuntu-latest
# optionally use a convenient Ubuntu LTS + DVC + CML image
#container: docker://dvcorg/cml:latest
steps:
- uses: actions/checkout#v3
- name: Setup R
uses: r-lib/actions/setup-r#v2
#- name: Setup Pandoc
# uses: r-lib/actions/setup-pandoc#v2
- name: Setup dependencies
run: |
R -e 'install.packages("renv")'
R -e 'renv::restore()'
- name: Identify and email articles
#env:
# repo_token: ${{ secrets.GITHUB_TOKEN }}
run: |
Rscript -e 'rmarkdown::render(input = "My_Markdown_Code.Rmd")'
if [[ "$(git status --porcelain)" != "" ]]; then
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR#users.noreply.github.com"
git add *
git commit -m "Auto update Report"
git push origin
fi
`
The error I get says "render-rmarkdown
there is no package called ‘rmarkdown’"
Any help much appreciated!

How to change GitHub Actions OS from MacOs to Windows or Ubuntu?

I'm currently using the macOs os version for my Github Actions but it's very consuming on my minutes thresholds as it has a 10x cost on the monthly limit
I would like to switch to Ubuntu or Windows but I'm not quite sure about how to change my YML file.
Here is my actual YML file of one of my workflow:
# Hourly scraping
name: amazonR Polite Price Checker
# Controls when the action will run.
on:
schedule:
- cron: '0 0 * * 1,4'
jobs:
autoscrape:
# The type of runner that the job will run on
runs-on: macos-latest
# Load repo and install R
steps:
- uses: actions/checkout#master
- uses: r-lib/actions/setup-r#master
# Set-up R
- name: Install packages
run: |
R -e 'install.packages("tidyverse")'
R -e 'install.packages("tibble")'
R -e 'install.packages("openxlsx")'
R -e 'install.packages("gdata")'
R -e 'install.packages("lubridate")'
R -e 'install.packages("rvest")'
R -e 'install.packages("stringr")'
R -e 'install.packages("dplyr")'
R -e 'install.packages("purrr")'
R -e 'install.packages("plyr")'
R -e 'install.packages("polite")'
R -e 'install.packages("xml2")'
R -e 'install.packages("gt")'
R -e 'install.packages("blastula")'
# Run R script
- name: Scrape with the polite package
env:
EMAIL_SENDER: ${{ secrets.EMAIL_SENDER }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
EMAIL_RECIPIENT: ${{ secrets.EMAIL_RECIPIENT }}
EMAIL_CC_1: ${{ secrets.EMAIL_CC_1 }}
EMAIL_CC_2: ${{ secrets.EMAIL_CC_2 }}
EMAIL_CC_3: ${{ secrets.EMAIL_CC_3 }}
run: Rscript polite_price_checker.R
# Add new files in data folder, commit along with other modified files, push
- name: Commit files
run: |
git config --local user.name github-actions
git config --local user.email "actions#github.com"
git add polite_price/*
git commit -am "GH ACTION Autorun POLITE PRICE $(date)"
git push origin main --force
env:
REPO_KEY: ${{secrets.GITHUB_TOKEN}}
username: github-actions
The runner is configured by the runs-on for each job.
It can be a GitHub hosted runner or a self-hosted runner according to your context.
Examples with GitHub hosted runner:
jobs:
job1:
runs-on: ubuntu-latest
steps:
[ ... ]
job2:
runs-on: macos-latest
steps:
[ ... ]
job3:
runs-on: windows-latest
steps:
[ ... ]
The available GitHub runner images (with the pre-installed tools) can be found here for more details.
Be aware that each runner use a specific shell by default, for example ubuntu and macos use bash, where windows use powershell.
Therefore, in your case, you just need to update the runs-on: macos-latest to runs-on: ubuntu-latest or runs-on: windows-latest (supposing you want to use the latest, and not a specific version).
Note that you can also use matrix to run the same job on different runners if necessary (without duplicating code).

Access output of sbt print in Github Actions workflow

I'm trying to save the output of running sbt print version | tail -n 1 to an environment variable in a Github Actions workflow, and it doesn't seem to work.
This is what I think should work, but it's just an empty string, when I try to access the variable later on in the job:
echo "TAG_VERSION=$(sbt 'print version' | tail -n 1)" >> $GITHUB_ENV
It works great in my own shell, but not in Github Actions.
I'm using version 1.5.3for sbt.
This is the logs for the step that doesn't seem to work, test version step, it just seems to not load up correctly.:
Run echo "TAG_VERSION=$(sbt 'print version' | tail -n 1)" >> $GITHUB_ENV
echo "TAG_VERSION=$(sbt 'print version' | tail -n 1)" >> $GITHUB_ENV
shell: /usr/bin/bash -e {0}
env:
CI: true
JAVA_HOME: /home/runner/.jabba/jdk/adopt#1.8.0-292
Downloading sbt launcher for 1.5.3:
From https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.5.3/sbt-launch-1.5.3.jar
To /home/runner/.sbt/launchers/1.5.3/sbt-launch.jar
Downloading sbt launcher 1.5.3 md5 hash:
From https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.5.3/sbt-launch-1.5.3.jar.md5
To /home/runner/.sbt/launchers/1.5.3/sbt-launch.jar.md5
[info] [launcher] getting org.scala-sbt sbt 1.5.3 (this may take some time)...
[info] [launcher] getting Scala 2.12.14 (for sbt)...
This is the full workflow:
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: olafurpg/setup-scala#v11
#- name: run tests
# run: |
# sbt test
- name: docker login
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
#- name: build image and publish
# run: sbt 'Docker / publish'
- name: test version
run: echo "TAG_VERSION=$(sbt 'print version' | tail -n 1)" >> $GITHUB_ENV
- name: print test version
run: echo ${{ env.TAG_VERSION }}
- name: get version
run: echo "TAG_VERSION=$(echo $(sbt -Dsbt.supershell=false 'print version' | tail -n 1))" >> $GITHUB_ENV
- name: checkout helm repo
uses: actions/checkout#v2
with:
repository: peterstorm/dialer-integration-argo
token: ${{ secrets.ACCESS_TOKEN }}
path: './dialer-integration-argo'
- name: change image tag in helm repo
uses: mikefarah/yq#master
with:
cmd: yq eval -i '.image.tag = "${{ env.TAG_VERSION }}"' './dialer-integration-argo/values.yaml'
- name: push helm repo changes
run: |
cd dialer-integration-argo &&
git config --global user.name 'Peter Storm' &&
git config --global user.email 'peter.storm#peterstorm.io' &&
git add . &&
git commit -m "commit from github actions" &&
git push origin master
Thank you!
Hopefully, someone else finds this to be helpful (I know the question is over a year-old, but you never know). I had very similar issue, and was attempting to output the result of $(sbt 'print version' | tail -n 1) to a gha step output or the $GITHUB_ENV. After many different permutations I found success by setting the -no-colors flag on the sbt command so:
- name: Get Version
id: version
run: echo ::set-output name=snapshot::$(sbt -no-colors 'print version' | tail -n 1)
- name: Show Version
run: echo $(sbt -no-colors 'print version' | tail -n 1)
- name: Output Version
run: echo "${{ steps.version.outputs.snapshot }} :rocket:" >> $GITHUB_STEP_SUMMARY
I would guess this would work if you used the $GITHUB_ENV mechanism

Run firebase emulators on github actions

I'm trying to run my test on Github Actinos but after several attempts I was not able to do so.
Receiving
Error: firestore: Firestore Emulator has exited because java is not installed, you can install it from https://openjdk.java.net/install/
- name: Test
uses: w9jds/firebase-action#v1.3.1
env:
JAVA_HOME: ${{ env.JAVA_HOME }}
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
GCLOUD_PROJECT: ${{ secrets.nextGCLOUD_PROJECT }}
PROJECT_ID: ${{ secrets.nextFIREBASE_PROJECTID }}
with:
args: |
setup:emulators:firestore --debug
firebase emulators:exec --debug --only functions,firestore \"npm run test --exit -- --forceExit --detectOpenHandles\"
- name: Print debug logs
if: failure()
run: |
java --version
ls -la
find . -type f -name "fire*-debug.log" | xargs cat
That's the output from action name: Test
/usr/bin/docker run --name d38e5ad93a422d456db01475acdae41155_521526 --label 3888d3 --workdir /github/workspace --rm -e JAVA_HOME -e FIREBASE_TOKEN -e GCLOUD_PROJECT -e PROJECT_ID -e INPUT_ARGS -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true --network github_network_2107949b3a2c43d499d641b1c2f0fd12 -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/pwa/pwa":"/github/workspace" 3888d3:8e5ad93a422d456db01475acdae41155 setup:emulators:firestore --debug
firebase emulators:exec --debug --only functions,firestore \"npm run test --exit -- --forceExit --detectOpenHandles\"
setting firebase project to ***
Now using project ***
i firestore: downloading cloud-firestore-emulator-v1.11.4.jar... {"metadata":{"emulator":{"name":"firestore"},"message":"downloading cloud-firestore-emulator-v1.11.4.jar..."}}
[2020-06-06T12:59:30.184Z] > 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"]
[2020-06-06T12:59:30.186Z] > authorizing via FIREBASE_TOKEN environment variable
i emulators: Starting emulators: functions, firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: functions, firestore"}}
[2020-06-06T12:59:30.217Z] [hub] writing locator at /tmp/hub-***.json
✔ functions: Using node#10 from host. {"metadata":{"emulator":{"name":"functions"},"message":"Using node#10 from host."}}
[2020-06-06T12:59:30.249Z] Ignoring unsupported arg: projectId {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: projectId"}}
[2020-06-06T12:59:30.249Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: auto_download"}}
[2020-06-06T12:59:30.249Z] Starting Firestore Emulator with command {"binary":"java","args":["-Duser.language=en","-jar","/github/home/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar","--host","localhost","--port",8080,"--rules","/github/workspace/firestore.rules","--functions_emulator","localhost:5001"],"optionalArgs":["port","webchannel_port","host","rules","functions_emulator","seed_from_export"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {\"binary\":\"java\",\"args\":[\"-Duser.language=en\",\"-jar\",\"/github/home/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar\",\"--host\",\"localhost\",\"--port\",8080,\"--rules\",\"/github/workspace/firestore.rules\",\"--functions_emulator\",\"localhost:5001\"],\"optionalArgs\":[\"port\",\"webchannel_port\",\"host\",\"rules\",\"functions_emulator\",\"seed_from_export\"],\"joinArgs\":false}"}}
i firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \u001b[1mfirestore-debug.log\u001b[22m"}}
Error: firestore: Firestore Emulator has exited because java is not installed, you can install it from https://openjdk.java.net/install/
That's the output from action name: Print debug logs
[debug] [2020-06-06T12:59:27.289Z] ----------------------------------------------------------------------
[debug] [2020-06-06T12:59:27.291Z] Command: /usr/local/bin/node /usr/local/bin/firebase setup:emulators:firestore --debug
[debug] [2020-06-06T12:59:27.292Z] CLI Version: 8.4.2
[debug] [2020-06-06T12:59:27.292Z] Platform: linux
[debug] [2020-06-06T12:59:27.292Z] Node Version: v10.21.0
[debug] [2020-06-06T12:59:27.292Z] Time: Sat Jun 06 2020 12:59:27 GMT+0000 (Coordinated Universal Time)
[debug] [2020-06-06T12:59:27.293Z] ----------------------------------------------------------------------
[debug] [2020-06-06T12:59:27.293Z]
[info] i firestore: downloading cloud-firestore-emulator-v1.11.4.jar... {"metadata":{"emulator":{"name":"firestore"},"message":"downloading cloud-firestore-emulator-v1.11.4.jar..."}}
[debug] [2020-06-06T12:59:30.168Z] ----------------------------------------------------------------------
[debug] [2020-06-06T12:59:30.170Z] Command: /usr/local/bin/node /usr/local/bin/firebase emulators:exec --debug --only functions,firestore npm run test --exit -- --forceExit --detectOpenHandles
[debug] [2020-06-06T12:59:30.171Z] CLI Version: 8.4.2
[debug] [2020-06-06T12:59:30.171Z] Platform: linux
[debug] [2020-06-06T12:59:30.171Z] Node Version: v10.21.0
[debug] [2020-06-06T12:59:30.171Z] Time: Sat Jun 06 2020 12:59:30 GMT+0000 (Coordinated Universal Time)
[debug] [2020-06-06T12:59:30.171Z] ----------------------------------------------------------------------
[debug] [2020-06-06T12:59:30.171Z]
[debug] [2020-06-06T12:59:30.184Z] > 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"]
[debug] [2020-06-06T12:59:30.186Z] > authorizing via FIREBASE_TOKEN environment variable
[info] i emulators: Starting emulators: functions, firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: functions, firestore"}}
[debug] [2020-06-06T12:59:30.217Z] [hub] writing locator at /tmp/hub-***.json
[info] ✔ functions: Using node#10 from host. {"metadata":{"emulator":{"name":"functions"},"message":"Using node#10 from host."}}
[debug] [2020-06-06T12:59:30.249Z] Ignoring unsupported arg: projectId {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: projectId"}}
[debug] [2020-06-06T12:59:30.249Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: auto_download"}}
[debug] [2020-06-06T12:59:30.249Z] Starting Firestore Emulator with command {"binary":"java","args":["-Duser.language=en","-jar","/github/home/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar","--host","localhost","--port",8080,"--rules","/github/workspace/firestore.rules","--functions_emulator","localhost:5001"],"optionalArgs":["port","webchannel_port","host","rules","functions_emulator","seed_from_export"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {\"binary\":\"java\",\"args\":[\"-Duser.language=en\",\"-jar\",\"/github/home/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar\",\"--host\",\"localhost\",\"--port\",8080,\"--rules\",\"/github/workspace/firestore.rules\",\"--functions_emulator\",\"localhost:5001\"],\"optionalArgs\":[\"port\",\"webchannel_port\",\"host\",\"rules\",\"functions_emulator\",\"seed_from_export\"],\"joinArgs\":false}"}}
[info] i firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \u001b[1mfirestore-debug.log\u001b[22m"}}
[error]
[error] Error: firestore: Firestore Emulator has exited because java is not installed, you can install it from https://openjdk.java.net/install/
How can I run my tests on Github Actions?
At the time of writing, the unofficial firebase-action has recently added Java support. Unfortunately this is Java 7, and the emulator requires Java 8. (I have opened an issue in the repo to get this fixed).
Alternatively, for anyone that is interested, I have found the following to work well:
name: Test Firebase rules on PR
'on': pull_request
jobs:
test_rules:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: '12'
- run: npm install -g firebase-tools
- run: npm ci
- run: firebase emulators:exec --only firestore \"npm run test --exit\"
There are two important notes about the above workflow file:
ubuntu-latest is required as this contains both node and java.
actions/setup-node#v1 is required to setup node to allow the install of global npm packages.
Also, if you would like to add a deploy step to the above you would only need to add this above the setup-node step, for authentication:
- uses: google-github-actions/setup-gcloud#master
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
(This is because the export_default_credentials will export the GOOGLE_APPLICATION_CREDENTIALS environment variable which firebase-tools will use for authentication).
Try this -
name: next
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Setting-up Node.js
uses: actions/setup-node#v2-beta
with:
node-version: '10'
- name: Installing npm dependencies
run: npm ci --prefer-offline --no-audit --progress=false
- name: Checking-out
uses: actions/checkout#v2
- name: Setting-up JAVA
uses: actions/setup-java#v1.3.0
with:
java-version: "12.x"
- name: Setup and Test Emulator
uses: w9jds/firebase-action#v1.3.1
env:
JAVA_HOME: ${{ env.JAVA_HOME }}
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
GCLOUD_PROJECT: ${{ secrets.nextGCLOUD_PROJECT }}
PROJECT_ID: ${{ secrets.nextFIREBASE_PROJECTID }}
with:
args: |
setup:emulators:firestore
emulators:exec --only firestore \"npm run test --exit\"
This worked for me
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: '12'
- name: Install Dependacies
run: cd functions && npm install
- name: Test to Firebase
uses: w9jds/firebase-action#master
with:
args: emulators:exec --only firestore \"cd functions && npm run test --exit\"
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
If you don't need node environment, try this
name: Test and coverage
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
fetch-depth: 2
- uses: actions/setup-go#v2
with:
go-version: '1.19'
- name: Install firebase
run: curl -sL https://firebase.tools | bash
- name: Run firebase emulators
run: firebase emulators:start --only auth &
- name: Run coverage
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action#v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

Resources