-
Notifications
You must be signed in to change notification settings - Fork 6
216 lines (191 loc) · 7.02 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Iaso Cypress manual testing
# This workflow allows to launch cypress tests manually
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
ref:
type: string
description: 'Branch to test'
required: true
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-image:
if: ((github.event_name == 'workflow_dispatch') || (contains(github.event.comment.body, '@cypress')))
permissions:
issues: write
contents: read
packages: write
pull-requests: write
runs-on: ubuntu-20.04
steps:
- name: Checkout repository (dispatch)
uses: actions/checkout@v3
if: github.event_name == 'workflow_dispatch'
with:
ref: ${{ github.event.inputs.ref }}
- id: 'get-branch'
name: Get branch name from PR when triggered by comment
if: github.event_name != 'workflow_dispatch'
run: echo ::set-output name=branch::$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName')
env:
REPO: ${{ github.repository }}
PR_NO: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository (comment)
uses: actions/checkout@v3
if: github.event_name != 'workflow_dispatch'
with:
ref: ${{ steps.get-branch.outputs.branch }}
- name: Mark comment as seen
if: github.event_name != 'workflow_dispatch'
uses: dkershner6/reaction-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
reaction: 'eyes'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
push: true
tags: ghcr.io/blsq/iaso:${{ github.event.inputs.ref || github.sha }}
target: dev
file: docker/bundle/Dockerfile
cache-from: type=registry,ref=ghcr.io/blsq/iaso:buildcache
cache-to: type=registry,ref=ghcr.io/blsq/iaso:buildcache,mode=max
- name: Comment PR with failure
uses: actions/github-script@v6
if: ((failure()) && (github.event_name != 'workflow_dispatch'))
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
github.rest.issues.createComment({
issue_number,
owner,
repo,
body: 'Test failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
});
test_cypress:
if: ((github.event_name == 'workflow_dispatch') || (contains(github.event.comment.body, '@cypress')))
timeout-minutes: 60
runs-on: ubuntu-20.04
needs: build-image
permissions:
contents: read
packages: write
pull-requests: write
issues: write
services:
postgres:
image: postgis/postgis:12-3.3
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: github_actions
ports:
- 5432:5432
# needed because the postgres container does not provide a health check
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
iaso:
image: ghcr.io/blsq/iaso:${{ github.event.inputs.ref || github.sha }}
env:
TEST_PROD: true
IASO_ENVIRONMENT: development
RDS_DB_NAME: github_actions
SECRET_KEY: secret
DEBUG: true
DJANGO_SETTINGS_MODULE: hat.settings
RDS_PASSWORD: postgres
RDS_HOSTNAME: postgres
RDS_PORT: 5432
RDS_USERNAME: postgres
CACHE: false
DEV_SERVER: true
PLUGINS: polio
ports:
- 8081:8081
steps:
- name: Checkout repository (dispatch)
uses: actions/checkout@v3
if: github.event_name == 'workflow_dispatch'
with:
ref: ${{ github.event.inputs.ref }}
- id: 'get-branch'
name: Get branch name from PR when triggered by comment
if: github.event_name != 'workflow_dispatch'
run: echo ::set-output name=branch::$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName')
env:
REPO: ${{ github.repository }}
PR_NO: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository (comment)
uses: actions/checkout@v3
if: github.event_name != 'workflow_dispatch'
with:
ref: ${{ steps.get-branch.outputs.branch }}
- name: Use node.js 20.13.1
uses: actions/setup-node@v2
with:
node-version: '20.13.1'
cache: npm
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: node_modules-20221121-${{ hashFiles('package-lock.json') }}
- name: upgrade npm
run: |
npm install --global [email protected]
- run: npm ci
if: steps.cache.outputs.cache-hit != 'true'
- name: Run Cypress tests
run: npx cypress run --browser chrome --config baseUrl=http://localhost:8081 --spec 'hat/assets/js/cypress/integration/**/*.spec.js'
env:
CYPRESS_USERNAME: "test"
CYPRESS_PASSWORD: "test"
CYPRESS_BASE_URL: "http://localhost:8081"
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: /home/runner/work/iaso/iaso/hat/assets/js/cypress/screenshots/
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-videos
path: /home/runner/work/iaso/iaso/hat/assets/js/cypress/videos/
- name: Mark comment as success
uses: dkershner6/reaction-action@v1
if: ((success()) && (github.event_name != 'workflow_dispatch'))
with:
token: ${{ secrets.GITHUB_TOKEN }}
reaction: 'hooray'
- name: Comment PR with failure
uses: actions/github-script@v6
if: ((failure()) && (github.event_name != 'workflow_dispatch'))
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
github.rest.issues.createComment({
issue_number,
owner,
repo,
body: 'Test failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
});