Skip to content

Commit 88fc033

Browse files
committed
test: Add E2E job on CI
1 parent 33409ed commit 88fc033

File tree

1 file changed

+295
-0
lines changed

1 file changed

+295
-0
lines changed

.github/workflows/e2e.yml

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
name: E2E
2+
3+
on: [push]
4+
5+
env:
6+
TZ: UTC
7+
OC_ENV: ci
8+
NODE_ENV: test
9+
WEBSITE_URL: http://localhost:3000
10+
IMAGES_URL: http://localhost:3001
11+
PDF_SERVICE_URL: http://localhost:3002
12+
API_URL: http://localhost:3060
13+
API_KEY: dvl-1510egmf4a23d80342403fb599qd
14+
CI: true
15+
16+
E2E_TEST: 1
17+
PGHOST: localhost
18+
PGUSER: postgres
19+
CYPRESS_RECORD: false
20+
CYPRESS_VIDEO: false
21+
CYPRESS_VIDEO_UPLOAD_ON_PASSES: false
22+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
23+
GITHUB_CLIENT_ID: ${{ secrets.GH_CLIENT_ID }}
24+
GITHUB_CLIENT_SECRET: ${{ secrets.GH_CLIENT_SECRET }}
25+
FRONTEND_FOLDER: /home/runner/work/opencollective-pdf/opencollective-pdf/opencollective-frontend
26+
API_FOLDER: /home/runner/work/opencollective-pdf/opencollective-pdf/opencollective-api
27+
IMAGES_FOLDER: /home/runner/work/opencollective-pdf/opencollective-pdf/opencollective-images
28+
PDF_FOLDER: /home/runner/work/opencollective-pdf/opencollective-pdf
29+
TERM: xterm
30+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
31+
STRIPE_WEBHOOK_KEY: ${{ secrets.STRIPE_WEBHOOK_KEY }}
32+
STRIPE_WEBHOOK_SIGNING_SECRET: ${{ secrets.STRIPE_WEBHOOK_SIGNING_SECRET }}
33+
AWS_KEY: ${{ secrets.AWS_KEY }}
34+
AWS_SECRET: ${{ secrets.AWS_SECRET }}
35+
36+
jobs:
37+
e2e:
38+
runs-on: ubuntu-latest
39+
40+
timeout-minutes: 30
41+
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
files: ['0*.js', '1*.js', '2*.js', '3*.js']
46+
47+
services:
48+
redis:
49+
image: redis
50+
ports:
51+
- 6379:6379
52+
options: --entrypoint redis-server
53+
postgres:
54+
image: postgres:13.13
55+
env:
56+
POSTGRES_USER: postgres
57+
POSTGRES_DB: postgres
58+
POSTGRES_HOST_AUTH_METHOD: trust
59+
ports:
60+
- 5432:5432
61+
# needed because the postgres container does not provide a healthcheck
62+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
63+
64+
steps:
65+
- name: Update apt
66+
run: sudo apt-get update || exit 0
67+
68+
- name: Install Cypress dependencies
69+
run: sudo apt-get install --no-install-recommends -y libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb fonts-arphic-bkai00mp fonts-arphic-bsmi00lp fonts-arphic-gbsn00lp fonts-arphic-gkai00mp fonts-arphic-ukai fonts-arphic-uming ttf-wqy-zenhei ttf-wqy-microhei xfonts-wqy
70+
71+
- name: Install postgresql-client
72+
run: sudo apt-get install -y postgresql-client
73+
74+
- name: Install graphicsmagick
75+
run: sudo apt-get install -y graphicsmagick
76+
77+
- name: Install stripe-cli
78+
run: |
79+
sudo apt-get install -y wget
80+
wget https://github.com/stripe/stripe-cli/releases/download/v1.13.9/stripe_1.13.9_linux_x86_64.tar.gz -O /tmp/stripe_1.13.9_linux_x86_64.tar.gz
81+
sudo tar xzvf /tmp/stripe_1.13.9_linux_x86_64.tar.gz -C /bin/
82+
83+
- name: Checkout (PDF)
84+
uses: actions/checkout@v4
85+
86+
- name: Setup node
87+
uses: actions/setup-node@v4
88+
with:
89+
node-version-file: 'package.json'
90+
cache: 'npm'
91+
92+
# Checkouts
93+
94+
- name: Set REF in env, removing the `refs/` part
95+
run: |
96+
echo "MATCHING_BRANCH_REF=${GITHUB_HEAD_REF-${GITHUB_REF##*/}}" >> $GITHUB_ENV
97+
98+
- name: Check matching branch (frontend)
99+
id: check-matching-branch-frontend
100+
uses: octokit/[email protected]
101+
with:
102+
route: GET /repos/{owner}/{repo}/git/ref/{ref}
103+
owner: opencollective
104+
repo: opencollective-frontend
105+
ref: ${{ env.MATCHING_BRANCH_REF }}
106+
env:
107+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
continue-on-error: true
109+
110+
- name: Checkout (frontend - matching branch)
111+
if: steps.check-matching-branch-frontend.outputs.status == 200
112+
uses: actions/checkout@v4
113+
with:
114+
repository: opencollective/opencollective-frontend
115+
path: opencollective-frontend
116+
ref: ${{ github.ref }}
117+
118+
- name: Checkout (frontend - main)
119+
if: steps.check-matching-branch-frontend.outputs.status != 200
120+
uses: actions/checkout@v4
121+
with:
122+
repository: opencollective/opencollective-frontend
123+
path: opencollective-frontend
124+
125+
# Checkout API
126+
127+
- name: Check matching branch
128+
id: check-matching-branch-api-api
129+
uses: octokit/[email protected]
130+
with:
131+
route: GET /repos/{owner}/{repo}/git/ref/{ref}
132+
owner: opencollective
133+
repo: opencollective-api
134+
ref: heads/${{ env.MATCHING_BRANCH_REF }}
135+
env:
136+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
137+
continue-on-error: true
138+
139+
- name: Checkout (api - matching branch)
140+
if: steps.check-matching-branch.outputs.status == 200
141+
uses: actions/checkout@v4
142+
with:
143+
repository: opencollective/opencollective-api
144+
path: opencollective-api
145+
ref: ${{ env.MATCHING_BRANCH_REF }}
146+
147+
- name: Checkout (api - main)
148+
if: steps.check-matching-branch.outputs.status != 200
149+
uses: actions/checkout@v4
150+
with:
151+
repository: opencollective/opencollective-api
152+
path: opencollective-api
153+
154+
- name: Checkout (images)
155+
uses: actions/checkout@v4
156+
with:
157+
repository: opencollective/opencollective-images
158+
path: opencollective-images
159+
160+
# Prepare API
161+
162+
- name: Restore node_modules (api)
163+
uses: actions/cache@v3
164+
id: api-node-modules
165+
with:
166+
path: opencollective-api/node_modules
167+
key: ${{ runner.os }}-api-node-modules-${{ hashFiles('opencollective-api/package-lock.json') }}
168+
169+
- name: Install dependencies (api)
170+
working-directory: opencollective-api
171+
if: steps.api-node-modules.outputs.cache-hit != 'true'
172+
run: npm ci --prefer-offline --no-audit
173+
174+
- name: Restore build (api)
175+
uses: actions/cache@v3
176+
id: api-build
177+
with:
178+
path: opencollective-api/dist
179+
key: ${{ runner.os }}-api-build-${{ github.sha }}
180+
181+
- name: Build (api)
182+
if: steps.api-build.outputs.cache-hit != 'true'
183+
working-directory: opencollective-api
184+
run: npm run build
185+
186+
# Prepare Frontend
187+
188+
- name: Restore node_modules (frontend)
189+
uses: actions/cache@v3
190+
id: frontend-node-modules
191+
with:
192+
path: opencollective-frontend/node_modules
193+
key: ${{ runner.os }}-frontend-node-modules-${{ hashFiles('opencollective-frontend/package-lock.json') }}
194+
195+
- name: Install dependencies (frontend)
196+
if: steps.frontend-node-modules.outputs.cache-hit != 'true'
197+
working-directory: opencollective-frontend
198+
run: CYPRESS_INSTALL_BINARY=0 npm ci --prefer-offline --no-audit
199+
200+
- name: Set commit hash (frontend)
201+
working-directory: opencollective-frontend
202+
run: echo "FRONTEND_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
203+
204+
- name: Restore .next build (frontend)
205+
uses: actions/cache@v3
206+
id: next-build
207+
with:
208+
path: opencollective-frontend/.next
209+
key: ${{ runner.os }}-next-build-${{ env.FRONTEND_COMMIT_HASH }}
210+
211+
- name: Restore .next cache (frontend)
212+
if: steps.next-build.outputs.cache-hit != 'true'
213+
uses: actions/cache@v3
214+
with:
215+
path: opencollective-frontend/.next/cache
216+
key: ${{ runner.os }}-next-cache-${{ env.FRONTEND_COMMIT_HASH }}
217+
restore-keys: |
218+
${{ runner.os }}-next-cache-${{ env.FRONTEND_COMMIT_HASH }}
219+
${{ runner.os }}-next-cache-
220+
221+
- name: Build (frontend)
222+
if: steps.next-build.outputs.cache-hit != 'true'
223+
working-directory: opencollective-frontend
224+
run: npm run build
225+
226+
# Prepare Images
227+
228+
- name: Restore node_modules (images)
229+
uses: actions/cache@v3
230+
id: images-node-modules
231+
with:
232+
path: opencollective-images/node_modules
233+
key: ${{ runner.os }}-images-node-modules-${{ hashFiles('opencollective-images/package-lock.json') }}
234+
235+
- name: Install dependencies (images)
236+
working-directory: opencollective-images
237+
if: steps.images-node-modules.outputs.cache-hit != 'true'
238+
run: npm ci --prefer-offline --no-audit
239+
240+
- name: Build (images)
241+
working-directory: opencollective-images
242+
run: npm run build
243+
244+
# Prepare PDF
245+
- name: Restore node_modules (pdf)
246+
uses: actions/cache@v3
247+
id: pdf-node-modules
248+
with:
249+
path: node_modules
250+
key: ${{ runner.os }}-pdf-node-modules-${{ hashFiles('opencollective-pdf/package-lock.json') }}
251+
252+
- name: Install dependencies (pdf)
253+
if: steps.pdf-node-modules.outputs.cache-hit != 'true'
254+
run: npm ci --prefer-offline --no-audit
255+
256+
- name: Build (pdf)
257+
run: npm run build
258+
259+
# Setup Cypress
260+
261+
- name: Restore Cypress
262+
uses: actions/cache@v3
263+
id: cypress
264+
with:
265+
path: ~/.cache/Cypress
266+
key: ${{ runner.os }}-cypress-${{ hashFiles('opencollective-frontend/node_modules/cypress/package.json') }}
267+
268+
- name: Install Cypress
269+
if: steps.cypress.outputs.cache-hit != 'true'
270+
working-directory: opencollective-frontend
271+
run: npx cypress install
272+
273+
# Seed DB
274+
275+
- name: Setup DB
276+
working-directory: opencollective-frontend
277+
run: ./scripts/setup_db.sh
278+
279+
# Run tests
280+
281+
- name: Archive test recordings
282+
uses: actions/upload-artifact@v3
283+
with:
284+
name: cypress-recordings
285+
path: |
286+
opencollective-frontend/test/cypress/screenshots
287+
opencollective-frontend/test/cypress/videos
288+
if: ${{ failure() }}
289+
290+
- name: Archive download folder
291+
uses: actions/upload-artifact@v3
292+
with:
293+
name: downloads
294+
path: opencollective-frontend/test/cypress/downloads
295+
if: ${{ failure() }}

0 commit comments

Comments
 (0)