cypress-io/github-action does not accept all environment variables - firebase

my purpose is simple, run cypress e2e test using Github actions upon Pull Request. I used cypress-firebase for testing and all my test should run with Firebase Emulator. And I also used cypress-io/github-action for CI.
My problem is, when using cypress-io/github-action, I need to pass some environment variables for my react app to work with Firebase emulator, and all environment variables can not be recognized by the whole entire app. See my workflow file to understand.
Here are my related part of my Github action workflow file:
- name: Cypress run
uses: cypress-io/github-action#v2
with:
browser: chrome
headless: true
record: true
start: yarn run ci:start:emulator
wait-on: "http://localhost:3000"
wait-on-timeout: 300 # wait for 5 minutes
env:
# Add debugger
# https://github.com/cypress-io/github-action#debugging
DEBUG: "#cypress/github-action"
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: ${{ secrets.REACT_APP_PROJECT_ID }}
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CI_CLOUD_FUNCTIONS_CONFIG }}
# Branch settings
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_REF: ${{ github.ref }}
# pass the Cypress Dashboard variables
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
# UID of user to login during test
CYPRESS_BASE_URL: http://localhost:3000
CYPRESS_TEST_UID: ${{ secrets.CYPRESS_TEST_UID }}
# Service Account (used for creating custom auth tokens)
SERVICE_ACCOUNT: ${{ secrets.CYPRESS_SERVICE_ACCOUNT }}
# Environment variables
REACT_APP_ANY_KEY: ${{ secrets.REACT_APP_ANY_KEY }}
And here is my ci:start:emulator command in package.json file:
"ci:start:emulator": "firebase emulators:exec 'yarn start'"
The thing is yarn start command does not recognize my above REACT_APP_ANY_KEY environment variable. It seems cypress-io/github-action did not pass them to my yarn start command.
What I tried is changing above command into
"ci:start:emulator": "cross-env REACT_APP_ANY_KEY=<SOME_HARD_CODE_VALUE> firebase emulators:exec 'yarn start'"
It works perfectly! But of course, we don't want to pass tons of environment variables via this command like this.
Any help will be highly appreciated!

According to the docs You can define environment variables for a step, job, or entire workflow, so here you defined those env variables only for this step Cypress run and not for the entire job, to solve this you should define env variables using this, an example:
jobs:
job1:
env:
# Add debugger
# https://github.com/cypress-io/github-action#debugging
DEBUG: "#cypress/github-action"
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: ${{ secrets.REACT_APP_PROJECT_ID }}
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CI_CLOUD_FUNCTIONS_CONFIG }}
# Branch settings
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_REF: ${{ github.ref }}
# pass the Cypress Dashboard variables
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
# UID of user to login during test
CYPRESS_BASE_URL: http://localhost:3000
CYPRESS_TEST_UID: ${{ secrets.CYPRESS_TEST_UID }}
# Service Account (used for creating custom auth tokens)
SERVICE_ACCOUNT: ${{ secrets.CYPRESS_SERVICE_ACCOUNT }}
# Environment variables
REACT_APP_ANY_KEY: ${{ secrets.REACT_APP_ANY_KEY }}
env variables should be accessible across this Job's steps, if you wanted to set global environment variables, You should define them before the jobs.

Related

how to use pat token to clone private repo through GitHub actions.?

name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout#v2
# Runs a single command using the runners shell
- name: terratest
run: echo Github pat token is ${{ secrets.TF_GITHUB_PAT }}
- name: checkout t2form-k8s repo
uses: actions/checkout#v2
with:
repository: harikalyank/t2form-k8s
token: ${{ secrets.TF_GITHUB_PAT }}
ref: master
The above one is my GH-workflow and it's getting failed to clone repo:t2form-k8s.
error: Warning: The save-state command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Error: Input required and not supplied: token
I created Pat/secret token as well on repository level with name:TF_GITHUB_PAT

GitHub action stalls on setup-r-dependencies#v2

This is cross posted on the RStudio Community site. I am using r-lib/setup-r-dependencies#v2 for a bookdown project on GitHub action. However, the job is stalling when pak tries to create a lock file. Here is an example run , and here is the workflow.
As you can see, eventually the job just times out.
The issue seems similar to this post. The solution there was to use the most current RSPM, but I believe that is already what I am using (I don't specify anything different in the workflow).
Any ideas on what might be causing this?
Edit: Here is the full yaml code for the workflow (linked above)
on:
push:
branches: [main, master]
workflow_dispatch:
name: bookdown
jobs:
bookdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout#v2
- uses: r-lib/actions/setup-pandoc#v2
- uses: r-lib/actions/setup-r#v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies#v2
with:
cache-version: 1
- name: Cache bookdown results
uses: actions/cache#v2
with:
path: _bookdown_files
key: bookdown-${{ hashFiles('**/*Rmd') }}
restore-keys: bookdown-
- name: Build site
run: bookdown::render_book("index.Rmd", quiet = TRUE)
shell: Rscript {0}
- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action#4.1.4
with:
branch: gh-pages
folder: _book

How to run a separate script in Github repo in Github Actions

trying to implement a workflow on Github actions that will run a test script with the functions of my package and ideally print/export out the results. I am new to the YAML syntax and would appreciate any help.
This is the workflow I currently have:
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
name: Test-Script
jobs:
build:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
steps:
- uses: actions/checkout#v2
- uses: r-lib/actions/setup-r#v1
with:
r-version: ${{ matrix.config.r }}
- uses: r-lib/actions/setup-pandoc#v1
- name: Test against test script
run: |
/R/test_script.R #file path in repo
shell: Rscript {0}
I get the erorr: Error: Error: unexpected '/' in "/". I have tried multiple adjustments but always get that error or another saying that the file cannot be found. I would also like to print out/export out the results but I do not know how to do so.
Would appreciate any help please. Thank you.

Change config values in appsettings.json GitHubActions

I am struggling to replace values in my appsettings.json file and was wondering where I'm going wrong?
I have created two secrets in GitHub entitled COSMOSDBSETTINGS_SERVICEENDPOINT and COSMOSDBSETTINGS_AUTHKEY.
- name: Publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: App Settings Variable Substitution
uses: microsoft/variable-substitution#v1
with:
files: '${{env.DOTNET_ROOT}}\myapp\appsettings.json'
env:
CosmosDbSettings:ServiceEndpoint: ${{ secrets.COSMOSDBSETTINGS_SERVICEENDPOINT }}
CosmosDbSettings:AuthKey: ${{ secrets.COSMOSDBSETTINGS_AUTHKEY }}
I get the error stating
Run microsoft/variable-substitution#v1
Applying variable substitution on JSON file: C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\myapp\appsettings.json
Skipped updating file: C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\myapp\appsettings.json
Error: Error: Failed to apply variable substitution
This is the appsettings locally:
"CosmosDbSettings": {
"ServiceEndpoint": "https://localhost:8081/",
"AuthKey": "KEY"
},
Use a dot instead of a colon:
env:
CosmosDbSettings.ServiceEndpoint: ${{ secrets.COSMOSDBSETTINGS_SERVICEENDPOINT }}
CosmosDbSettings.AuthKey: ${{ secrets.COSMOSDBSETTINGS_AUTHKEY }}

Github Actions: missing telegram token or user list

I'm trying to use Github Actions to send a Telegram message every time someone pushes to the master of repo. But using this action causes the following error and action fails:
missing telegram token or user list
Here is my yml file:
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Telegram Notify
uses: appleboy/telegram-action#0.0.3
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
An event occured in ${{ github.repository }} repository.
${{ github.event_name }}
I quite new in Github Actions. What should I do to fix this?
P.S: I've added telegram_token and telegram_chat_id to secrets section of repo.
Go to the repo settings and set the secrets for the TELEGRAM_CHAT_ID and the TELEGRAM_TOKEN. when setting the secrets for TELEGRAM_TOKEN make sure to send the queries to the Telegram Bot API using the bot token https://api.telegram.org/bot/METHOD_NAME, for example https://api.telegram.org/bot19023205:BNF-23dred1234ghIkl-dre4fdgr8nv1w4od/getMe

Resources