Skip to content

.github/workflows/cypress.yml #2265

.github/workflows/cypress.yml

.github/workflows/cypress.yml #2265

Workflow file for this run

name: Cypress Tests (Chrome, Firefox, Safari) x5
on: [deployment_status]
# we have to supply something, but don't want to supply the
# real token to install the real package here, so we just
# provide a dummy
env:
GH_PACKAGE_AUTH_TOKEN: ${{ secrets.GH_PACKAGE_AUTH_TOKEN }}
jobs:
install:
name: Install cypress
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success' && github.event.deployment_status.environment == 'Preview'
container:
image: cypress/browsers:node16.5.0-chrome97-ff96
options: --user 1001 # https://github.com/cypress-io/github-action#firefox
steps:
- name: Checkout
uses: actions/checkout@v2
# cache NPM modules and Cypress binary folder
# we can use "package-lock.json" as the key file
# to make sure we use the precise Cypress version
# (which is important when using ^ version in package.json)
# see https://github.com/actions/cache
- name: Cache NPM and Cypress 📦
uses: actions/cache@v2
with:
path: |
~/.cache/Cypress
node_modules
key: my-cache-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install Cypress 📥
# don't install every node_module however
run: npm ci --no-optional
chrome:
name: Run Chrome Tests
runs-on: ubuntu-latest
needs: install
container:
image: cypress/browsers:node16.5.0-chrome97-ff96
options: --user 1001 # https://github.com/cypress-io/github-action#firefox
strategy:
fail-fast: false
matrix:
# run copies of the current job in parallel
containers: [1, 2, 3, 4, 5, 6]
steps:
- name: Checkout
uses: actions/checkout@v2
# this should always get a cache hit because we isntall above.
# but we need to make sure cypress is installed on all of the
# containers.
- name: Cache NPM and Cypress 📦
uses: actions/cache@v2
with:
path: |
~/.cache/Cypress
node_modules
key: my-cache-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install Cypress 📥
run: npm i --omit=optional
- name: Run Chrome
uses: cypress-io/[email protected]
env:
CYPRESS_BASE_URL: ${{ github.event.deployment_status.target_url }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# Recommended: pass the GitHub token lets this action correctly
# determine the unique run id necessary to re-run the checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
install: false
browser: chrome
headed: true
record: true
parallel: true
group: "UI - Chrome"
- name: Upload failure screenshots
uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: cypress-screenshots
path: cypress/screenshots
- name: Upload failure videos
uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: cypress-videos
path: cypress/videos
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#job-status-check-functions
- name: Set successful workflow status ✅
if: ${{ success() }}
# set the merge commit status check
# using GitHub REST API
# see https://docs.github.com/en/rest/reference/repos#create-a-commit-status
run: |
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'Accept: application/vnd.github.v3+json' \
--data '{
"context": "Cypress Tests - Web Reader",
"state": "success",
"description": "Cypress tests passed",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'
- name: Set failure workflow status 🚨
if: ${{ failure() }}
run: |
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'Accept: application/vnd.github.v3+json' \
--data '{
"context": "Cypress Tests - Web Reader",
"state": "failure",
"description": "Cypress tests failed",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'