-
Notifications
You must be signed in to change notification settings - Fork 6
129 lines (117 loc) · 4.64 KB
/
cypress.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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 }}"
}'