Cypress not able to read password from GitHub secrets but it is able to get record key - continuous-integration

Here is my .yml file
name: smoke tests`enter code here`
on:
workflow_dispatch:
jobs:
cypress-test:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Install cypress and verify
run: npm install
- name: Run smoke tests
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_PASSWORD: ${{ secrets.CYPRESS_PASSWORD }}
run: npx cypress-ntlm run -e TAGS='#smoke',configFile=test --spec 'cypress/integration/cucumber-tests/**/*.feature'

I was able to get password from GitHub secrets using npx cypress-ntlm run -e TAGS='#smoke',configFile=test CYPRESS_PASSWORD=$CYPRESS_PASSWORD --spec 'cypress/integration/cucumber-tests/**/*.feature'

Related

How to store previous report to gh-pages branch

I have following workflow in github action. I am using newman to run my postman collection.
Here what I want to do
Run newman and then store into gh-pages branch. but at the same time I want to store previous report too.
For now it's storing only one report with the name index.html.
name: User workflow
on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v1
- name: Get Previous Report history
uses: actions/checkout#v2
if: always()
continue-on-error: true
with:
ref: gh-pages
path: gh-pages
- name: Install HTML extra reporter
run: |
npm install -g newman
npm install -g newman-reporter-htmlextra
- name: Run Pets Profile API automated test on Dev or Stage
run: |
newman run users/user_pet_postman_collection.json \
-e users/user_env_postman_collection.json \
-g users/user_postman_globals.json \
-r cli,htmlextra
- name: Archive test report
uses: actions/upload-artifact#v3
with:
name: Newman-Report-${{ github.run_id }}-${{ github.run_attempt }}
path: newman/**/*.html
retention-days: 30
- name: Rename report
if: always()
run: |
ls
pwd
cd newman
mv *.html index.html
- name: Host Report on GH pages
if: always()
uses: crazy-max/ghaction-github-pages#v3
with:
target_branch: gh-pages
build_dir: newman
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy report to Github Pages newman directory
if: always()
uses: peaceiris/actions-gh-pages#v2
env:
PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: newman

How to set an env secret in Github action?

I want to access env variables in my .env. But of course, we can't commit the .env file.
So I've added an action secret to my Github called MONGODB_PASSWORD. But when I tried to access that secret, it's not working as expected.
Any thought on how I can do this?
This is what I have in my .yml
name: Node.js CI
on:
push:
branches: ['master']
pull_request:
branches: ['master']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
env:
MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }} // Setting the secret here
- run: npm ci
- run: npm run build --if-present
- run: npm run lint
- run: npm run test
- run: npm run test:e2e
Try setting env on job level instead of step level:
name: Node.js CI
on:
push:
branches: ['master']
pull_request:
branches: ['master']
jobs:
build:
runs-on: ubuntu-latest
env:
MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }} // Setting the secret here
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm run lint
- run: npm run test
- run: npm run test:e2e

"The cypress npm package is installed, but the Cypress binary is missing." in GitHub Actions

I'm receiving the following error when running a Cypress e2e test runner on GitHub Actions:
The cypress npm package is installed, but the Cypress binary is missing.
We expected the binary to be installed here: /home/runner/.cache/Cypress/8.5.0/Cypress/Cypress
Reasons it may be missing:
- You're caching 'node_modules' but are not caching this path: /home/runner/.cache/Cypress
- You ran 'npm install' at an earlier build step but did not persist: /home/runner/.cache/Cypress
My .github/workflow/tests.yml is set up as follows:
name: celestia/tests
on:
pull_request:
branches:
- main
- master
jobs:
unit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout ๐Ÿ›Ž
uses: actions/checkout#master
# Setup .npmrc file to publish to GitHub Packages
- name: Setup node env ๐Ÿ— and .npmrc file to publish to GitHub Packages
uses: actions/setup-node#v2.1.2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://npm.pkg.github.com'
# Defaults to the user or organization that owns the workflow file:
scope: '#observerly'
- name: Cache node_modules ๐Ÿ“ฆ
uses: actions/cache#v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install project dependencies ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป
run: npm ci --ignore-scripts
- name: Run jest unit tests ๐Ÿงช
run: npm run test:unit
e2e:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout ๐Ÿ›Ž
uses: actions/checkout#master
# Setup .npmrc file to publish to GitHub Packages
- name: Setup node env ๐Ÿ— and .npmrc file to publish to GitHub Packages
uses: actions/setup-node#v2.1.2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://npm.pkg.github.com'
# Defaults to the user or organization that owns the workflow file:
scope: '#observerly'
- name: Install project dependencies ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป
run: npm ci --ignore-scripts
- name: Run e2e cypress tests ๐Ÿงช
run: npm run test:e2e:headless
How can I side-step this particular issue?

Set up github actions to run cypress tests on localhost from 2 different repositories

I have my front-end (repUI) and cypress tests (repTest) in separate repositories., I am trying to run the tests by checkout both from repTest. Once the repUI is set up (install and build), the localhost:8000 is ready for tests to run.
So far the following workflow is designed:
name: Cypress E2E Tests on Dev
on:
workflow_dispatch:
push:
branches-ignore: [ main ]
schedule:
- cron: '0 0 * * 1-5'
jobs:
setup:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [14.x]
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
# Checkout UI repo
- name: Checkout voy-frontend repo
uses: actions/checkout#v2
with:
repository: orgName/xyz-frontend
path: xyz-frontend
ssh-key: ${{ secrets.GIT_SSH_KEY }}
# Install voy-f dependancies
- name: Install dependancies for application
run: |
cd voy-frontend
pwd
npm install
- name: Get npm cache directory
id: npm-cache-dir
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache#v2
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Run application
- name: Run application
run: |
pwd
cd voy-frontend
npm run serve
cypress-test:
name: Test
needs: setup
runs-on: ubuntu-latest
steps:
# Checkout test automation repo
- name: git checkout
uses: actions/checkout#v2
with:
ref: main
# Install cypress dependancies
- name: Cypress install
uses: cypress-io/github-action#v2
# Run cypress tests
- name: Cypress run - localhost
run: npm run cy:r -- --env TENANT=${{ secrets.TENANT }},CLIENT_ID=${{ secrets.CLIENT_ID }},CLIENT_SECRET=${{ secrets.CLIENT_SECRET }},ORG_SCOPE=${{ secrets.ORG_SCOPE }},G_SCOPE=${{ secrets.G_SCOPE }} --spec "cypress/integration/specs/Search.feature" --headless --browser chrome
- uses: actions/upload-artifact#v2
if: failure()
with:
name: cypress-videos
path: |
cypress/reports
cypress/videos
cypress/screenshots
retention-days: 1
The problem is if I run the build command npm run serve for repUI, the applications successfully getting started but it is not proceeding further instead it just waits. If I comment out the npm run serve, all other jobs are running as it should.
Here is the screenshot:
For building, it only took ~60 seconds, and then it waits until I cancel it. Same case if I trigger the job again and always.
What needs to be done in order to proceed to the cypress-test job once the build is ready.?

Migrating to GitHub Actions from Travis keeps failing

I am currently completing a migration from travis CI to Github Actions CI however my build keeps failing when the container tries to connect to my test DB.
Its a very generic error
UNKNOWN_CODE_PLEASE_REPORT: An internal error has occurred. Please retry or report your issues.
at Handshake.Object.<anonymous>.Sequence._packetToError (node_modules/***/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.Object.<anonymous>.Handshake.ErrorPacket (node_modules/***/lib/protocol/sequences/Handshake.js:123:18)
at Protocol.Object.<anonymous>.Protocol._parsePacket (node_modules/***/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (node_modules/***/lib/protocol/Parser.js:433:10)
at Parser.write (node_modules/***/lib/protocol/Parser.js:43:10)
at Protocol.Object.<anonymous>.Protocol.write (node_modules/***/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (node_modules/***/lib/Connection.js:88:28)
at Socket.<anonymous> (node_modules/***/lib/Connection.js:526:10)
Additional Notes: My test DB is hosted on Azure (mysql server) and my tests execute fine on local and previously on travis. Project details: NodeJs project running TypeOrm for MySql.
This is what the current base version of my yml looks like:
on:
pull_request:
branches: [master, develop]
defaults:
run:
working-directory: ./Server
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Use Node.js
with:
node_version: 14.x
uses: actions/setup-node#v1
- name: Run tests
run: |
npm install
npx jest --coverage --config ./jest.config.js
env:
TEST_DB_NAME: ${{ secrets.TEST_DB_NAME }}
TEST_DB_PORT: ${{ secrets.TEST_DB_PORT }}
TEST_DB_TYPE: ${{ secrets.TEST_DB_TYPE }}
TEST_HOST: ${{ secrets.TEST_HOST }}
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
TEST_PORT: ${{ secrets.TEST_PORT }}
ACCESS_SECRET_KEY: ${{ secrets.ACCESS_SECRET_KEY }} ```
Answering my own question:
I was missing an extra env key/variable related to an external AP. This was causing the failure.

Resources