I am using the firebase emulator to run my tests and, I received a warning about a chance of optimization using the cache system.
How I can do this?
It appears you are running in a CI environment. You can avoid downloading the Firestore Emulator repeatedly by caching the /home/runner/.cache/firebase/emulators directory.
Define this in GitHub Actions:
steps:
- uses: actions/checkout#v2
- name: Cache firebase emulators
uses: actions/cache#v2
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('~/.cache/firebase/emulators/**') }}
...
Then, for example, when we run this command firebase emulators:exec --project example 'npm test', if the emulator is not in the cache path, it will automatically start installing.
First run
Cache is missing
Download emulator when running test
Save cache as post action of actions/cache
Second run
Cache is found and restored and download doesn't happen.
If you need to update tool when npm package updates use something like this:
- name: Get Library Versions For Binary Caching
id: cache-settings
run: |
echo "::set-output name=firebase-tools::$(yarn list -s --depth=0 --pattern firebase-tools | tail -n 1 | sed 's/.*#//g')"
echo "::set-output name=firebase-tools::$(npm list -s --depth=0 | grep firebase-tools | tail -n 1 | sed 's/.*#//g')"
- name: Cache Firebase Emulator Binaries
uses: actions/cache#v2.1.2
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-${{ steps.cache-settings.outputs.firebase-tools }}
According to documentation:
https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
inside your .github/workflows/filename.yml include cache instructions:
on: [push, pull_request]
jobs:
emulator_test:
name: Run all tests using Firebase Emulator
runs-on: ubuntu-latest
steps:
...
# other instructions
...
- name: Cache node modules
id: cache-npm
uses: actions/cache#v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: Cache firebase emulators
uses: actions/cache#v2
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-${{ steps.cache-npm.outputs.firebase-tools }}
...
# other instructions
...
Without cache instructions:
Using cache instructions.
Related
I would like to publish a Python package to pypi if merging to master OR a file named VERSION contains letter b. The VERSION file is located in the root of this repo.
I'm able to get the "merging to master" part work with the following code.
publish:
needs: [build]
runs-on: [self-hosted, generic-linux]
container: python:3
steps:
- name: Download artifacts
uses: actions/download-artifact#v2
with:
name: package
path: ./dist
- name: Install requirements
run: |
pip install --upgrade pip
pip install --upgrade --prefer-binary twine
- name: Upload to artifactory
if: ${{ github.ref == 'refs/heads/master' }}
env:
TWINE_REPOSITORY_URL: https://artifactory.example.com/artifactory/api/pypi/pypi-all
TWINE_REPOSITORY: pypi-all
TWINE_USERNAME: "${{ secrets.PUBLISH_USERNAME }}"
TWINE_PASSWORD: "${{ secrets.PUBLISH_BEARER_TOKEN }}"
run: |
twine upload --skip-existing --verbose dist/*
However, I'm not sure how to add an OR condition to check the content of a file. Could someone help?
Thanks.
you could add an extra step to read the content (manually or using some existing GH action like https://github.com/marketplace/actions/read-files-action) of the file and add a condition the the Upload step, to check if the file contains the required string (with https://docs.github.com/en/actions/learn-github-actions/expressions#contains), like:
- name: Checkout code
uses: actions/checkout#v3
- name: Read Version
id: version
uses: komorebitech/read-files-action#v1.5
with:
files: '["VERSION"]'
- name: Echo Version
run: echo "${{ steps.version.outputs.content }}"
- name: Upload to artifactory
if: ${{ github.ref == 'refs/heads/master' || contains(steps.version.outputs.content, 'b')}}
Remember to checkout the code of the repo before try to read the file
I am using the getsentry/action-release#v1 GitHub Action to inform Sentry about new releases in my GitHub application. However, since I am using tags as the version number, I would like to inform sentry about the latest tag available on the release page. I'm having issues doing that while using environment variables.
Here is my job:
inform_sentry_about_release:
runs-on: ubuntu-latest
env:
ACCESS_TOKEN: ${{ secrets.GH_PAT }}
steps:
- uses: actions/checkout#v2
- name: Set GITHUB_VERSION variable
run: |
echo 'GITHUB_LATEST_RELEASE=$(curl -H "Authorization: token ${ACCESS_TOKEN}" "https://api.github.com/repos/myusername/myreponame/releases" -s | jq -r ".[0].tag_name")' >> $GITHUB_ENV
- name: Create Sentry release
uses: getsentry/action-release#v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
version: ${{ GITHUB_LATEST_RELEASE }}
My Github workflow is failing with the following error:
The workflow is not valid. .github/workflows/production-label.yml (Line: 131, Col: 20): Unrecognized named-value: 'GITHUB_LATEST_RELEASE'. Located at position 1 within expression: GITHUB_LATEST_RELEASE
According to How do I dynamically set an environment variable in a github composite action step?, it appears that I should be able to just echo a key=val to the GITHUB_ENV and then call it in the next step, but no luck.
Line 131 specifically refers to this:
version: ${{ GITHUB_LATEST_RELEASE }}
Is there a different way I'm supposed to access this environment variable from this line? I've tried $GITHUB_LATEST_RELEASE and still no luck with that either.
The environment variable should be accessed in the following way:
version: ${{ env.GITHUB_LATEST_RELEASE }}
Please note, that the names of environment variables are case-sensitive, and you can include punctuation.
Example:
steps:
- name: Set the value
id: step_one
run: |
echo "action_state=yellow" >> $GITHUB_ENV
- name: Use the value
id: step_two
run: |
echo "${{ env.action_state }}" # This will output 'yellow'
For more information check the Setting an environment variable.
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
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 }}