Skip to content

Commit baf4687

Browse files
committed
test: Add E2E job on CI
1 parent 2111f21 commit baf4687

File tree

1 file changed

+281
-0
lines changed

1 file changed

+281
-0
lines changed

.github/workflows/e2e.yml

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

0 commit comments

Comments
 (0)