I have been trying to automate the deployment of firebase cloud functions using the Github actions CI/CD workflows.
The functions are developed using NodeJs, Express, and Typescript. And all environment variables are saved in a .env file that is not tracked on github (for obvious reasons)
The main.yaml file (in .github/workflows/)
name: CI/CD
on:
push:
branches: [ deploy ]
pull_request:
branches: [ deploy ]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: create env file
run: |
cd functions
touch .env
echo "${{ secrets.ENV_VARS }}" >> .env
- name: Install npm packages
run: |
cd functions
npm install
- name: Deploy to Firebase
uses: w9jds/firebase-action#master
with:
args: deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
The workflow first creates a .env file where it writes the env variables (saved in github secrets)
then installs the dependencies,
and finally deploy the cloud functions
The steps are executed without any issues, up to the deployment part where I got this error
Error: Service account object must contain a string "project_id" property.
at FirebaseAppError.FirebaseError [as constructor] (/github/workspace/functions/node_modules/firebase-admin/lib/utils/error.js:44:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/github/workspace/functions/node_modules/firebase-admin/lib/utils/error.js:90:28)
at new FirebaseAppError (/github/workspace/functions/node_modules/firebase-admin/lib/utils/error.js:125:28)
at new ServiceAccount (/github/workspace/functions/node_modules/firebase-admin/lib/credential/credential-internal.js:134:19)
at new ServiceAccountCredential (/github/workspace/functions/node_modules/firebase-admin/lib/credential/credential-internal.js:68:15)
at Object.exports.cert (/github/workspace/functions/node_modules/firebase-admin/lib/credential/credential.js:34:54)
at Object.<anonymous> (/github/workspace/functions/lib/config/firebase.js:10:34)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
Thank you in advance
I solved this problem. The answer was very simple: instead of following the different tutorials that use "w9jds/firebase-action#master" for the deployment, I simply used firebase deploy :)
The new main.yaml
name: CI/CD
on:
push:
branches: [ deploy]
pull_request:
branches: [ deploy]
workflow_dispatch:
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
# Environment variables
- name: create env file
run: |
cd functions
touch .env
echo "${{ secrets.ENV_VARS }}" >> .env
# Install npm packages and firebase
- name: Install npm packages
run: |
cd functions
npm install
npm audit fix
npm install firebase-tools
# Run tests
- name: Run tests
run: |
cd functions
npm run test
# Deploying the functions to firebase
- name: Deploy to Firebase
run: |
cd functions
npm run deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
Related
We have a monorepo that we are using Lerna to publish to a private package manager (nexus). When the action runs, it fails with same vague message:
info cli using local version of lerna
lerna notice cli v5.3.0
lerna info ci enabled
Error: Process completed with exit code 1.
This message occurs after github actions tries to run the lerna publish command.
I've tried dozens of variations of installing Lerna globally and locally as well as all sort of variations of flags on my lerna bootstrap and lerna publish commands. I am not sure what to try. Any insights would be appreciated. Below is my worklflow file.
Node: 16.15.1
Lerna: 5.3.0
release.yml
name: 'MyPackage Production Release'
on:
workflow_dispatch:
inputs:
version:
required: true
type: choice
description: Which version should be published?
options:
- patch
- minor
- major
tag:
required: true
type: choice
description: Which npm tag should this be published to?
options:
- latest
- next
- test
jobs:
build-my-package:
runs-on: [self-hosted, Linux, X64, enterprise]
steps:
- uses: actions/checkout#v3
with:
fetch-depth: 0 #indicates all history for all branches and tags.
- uses: actions/setup-node#v3
with:
node-version: 16.15.1
registry-url: 'https://registry.npmjs.org'
- name: Configure Identity
run: |
git config user.name github-actions
git config user.email github-actions#github.com
shell: bash
- name: strict SSL
run: |
npm config set cafile my-file.pem
npm config set strict-ssl false
npm config set https-proxy http://proxy.our.proxysite.net:80/
npm config set proxy http://proxy.our.proxysite.net:80/
npm config set NODE_TLS_REJECT_UNAUTHORIZED=0
npm config set registry https://registry.npmjs.org/
- name: Install Dependencies
run: |
npm ci --no-package-lock --legacy-peer-deps
lerna bootstrap --ignore-scripts -- --legacy-peer-deps
shell: bash
- name: Prepare Nexus Token
run: |
npm config set registry https://nexus.our.site.net/repository/my-package-repo/
npm config set email myemail#myemail.net
npm config set strictSSL false
npm config set alwaysAuth true
echo //nexus.our.site.net/repository/my-package-repo/:_auth=${{ secrets.NEXUS_BASE64_AUTH }} > .npmrc
npm config set _auth ${{ secrets.NEXUS_BASE64_AUTH }}
shell: bash
- name: Release
run: |
HUSKY_SKIP_HOOKS=1 lerna publish $(echo "${{ github.event.inputs.version }}") --yes --force-publish='*' --dist-tag $(echo "${{ github.event.inputs.tag }}") --conventional-commits --create-release github
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GHE_API_URL: ${{ secrets.GHE_API_URL }}
GHE_VERSION: ${{ secrets.GHE_VERSION }}
shell: bash
I'm setting up a Github action that will deploy my Python-based SAM application. However, the "sam deploy" command fails with an error that seems to indicate Python is not available to build the application, despite it having just been set up in the previous step:
Building codeuri: /github/workspace/\[...\]/source runtime: python3.7 metadata: {} architecture: x86_64 functions: \['...'\]
Build Failed
Error: PythonPipBuilder:Resolver - Path resolution for runtime: python3.7 of binary: python was not successful
I can see that the python binary path is being passed as an env variable to the "SAM deployment" step: pythonLocation: /opt/hostedtoolcache/Python/3.7.12/x64
I also see that python is available via the "Check python version" step, where I do a simple "python -V", which returns the expected output.
As commented above, following the official workflow on the SAM AWS documentation resolved the issue.
on:
push:
branches:
- main
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-python#v2
- uses: aws-actions/setup-sam#v1
- uses: aws-actions/configure-aws-credentials#v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ##region##
# sam build
- run: sam build --use-container
This is my GitHub Actions script to build a react project:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 14
- name: Install yarn
uses: borales/actions-yarn#v2.1.0
- name: Build React App
run: |
sudo rm -rf node_modules
yarn
umi build
when I run this project in GitHub actions, shows error:
warning "umi-serve > #babel/preset-typescript#7.3.3" has unmet peer dependency "#babel/core#^7.0.0-0".
warning "umi-serve > #babel/register#7.4.4" has unmet peer dependency "#babel/core#^7.0.0-0".
warning Workspaces can only be enabled in private projects.
warning Workspaces can only be enabled in private projects.
[5/5] Building fresh packages...
error An unexpected error occurred: "EACCES: permission denied, open '/home/runner/work/admin/admin/yarn.lock'".
info If you think this is a bug, please open a bug report with the information provided in "/home/runner/work/admin/admin/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: Process completed with exit code 1.
why could not access the project yarn.lock when using yarn command? why facing the permission issue in GitHub Actions? what should I do to fix this problem?
I also facing the similar issue with it, you should tried to use actions/setup-node like this to fix it:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
- run: npm install yarn -g
- name: Build React App
run: |
yarn
yarn global add umi
umi build
I am currently working on setting up a workflow for my Github Pages site. I have successfully created html files from Python and now only need to publish. I am using this Github Action for doing that. However, my builds fail with the error message:
github-pages 222 | Error: No such file or directory # rb_check_realpath_internal - /github/workspace/bin/python3
I have the file /bin/python3 in my repository and it should additionally not be used for that build shouldnt it?
Why is it getting used and how do I fix it?
Note: I am not limited to this specific action. If there is another one that works better I would be happy to use it!
This is my worker file right now:
name: Jekyll site CI
on:
push:
branches: [ gh-pages ]
pull_request:
branches: [ gh-pages ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout#v2.4.0
- name: install python
uses: actions/setup-python#v2
with:
python-version: "3.9.2"
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install jinja2
- name: run python script
run: python app.py
- name: Deploy to GitHub Pages
if: success()
uses: crazy-max/ghaction-github-pages#v2.5.0
with:
build_dir: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
I'm trying to automate upload of my NuGet package using GitHub actions. I was hoping I could match the file name which includes the version number to avoid having to hardcode it in the action YML. It works if I hardcode the file name. I guess I just need to understand the syntax to use file pattern match. See last line of that code sample:
name: .NET
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
defaults:
run:
working-directory: ./Project
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET
uses: actions/setup-dotnet#v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore SharpLibHid.sln
- name: Build debug
run: dotnet build SharpLibHid.sln --no-restore -c Debug
- name: Build release
run: dotnet build SharpLibHid.sln --no-restore -c Release
- name: Test
run: dotnet test SharpLibHid.sln --no-build --verbosity normal
- name: Publish Nuget
run: dotnet nuget push './Hid/bin/Release/SharpLibHid.*.nupkg' --skip-duplicate -k ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
How do you use file matching pattern in GitHub actions run?
Here is a successful build with hardcoded path:
https://github.com/Slion/SharpLibHid/actions/runs/998451423
Here is a failed build with my attempt at pattern matching:
https://github.com/Slion/SharpLibHid/actions/runs/998464157