Skip to content

Commit 1fa3656

Browse files
VIA-598 Add action.yaml for E2E and snapshot tests
1 parent b80e618 commit 1fa3656

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: "E2E test: ${{inputs.environment}} environment"
2+
description: "Run E2E tests"
3+
inputs:
4+
environment:
5+
description: "Environment to run tests against"
6+
required: true
7+
checkout_ref:
8+
description: "Ref to checkout"
9+
required: true
10+
cross_browser:
11+
description: "Run E2E with playwright config with all devices"
12+
required: false
13+
14+
runs:
15+
using: "composite"
16+
17+
steps:
18+
- name: "Checkout target code"
19+
uses: actions/checkout@v5
20+
with:
21+
ref: ${{ inputs.checkout_ref }}
22+
path: "code-for-e2e-tests"
23+
24+
- name: "Cache node modules"
25+
id: cache-npm
26+
uses: actions/cache@v4
27+
env:
28+
cache-name: cache-node-modules
29+
with:
30+
path: ~/.npm
31+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./code-for-e2e-tests/**/package-lock.json') }}
32+
33+
- name: "Install dependencies"
34+
shell: bash
35+
working-directory: "./code-for-e2e-tests"
36+
run: |
37+
npm ci --ignore-scripts
38+
39+
- name: "Get current week number and playwright version"
40+
shell: bash
41+
working-directory: "./code-for-e2e-tests"
42+
id: cache_key_values
43+
run: |
44+
echo "week_num=$(date -u +'%Y-%V')" | tee -a $GITHUB_OUTPUT
45+
echo "playwright_version=$(npm view @playwright/test version)" | tee -a $GITHUB_OUTPUT
46+
47+
- name: "Cache Playwright browsers"
48+
uses: actions/cache@v4
49+
id: playwright-cache
50+
with:
51+
path: ~/.cache/ms-playwright
52+
key: ${{ runner.os }}-playwright-${{ steps.cache_key_values.outputs.week_num }}-${{ steps.cache_key_values.outputs.playwright_version }}-${{ hashFiles('**/playwright.config*') }}
53+
54+
- name: "Install Playwright browsers (Chromium, Firefox)"
55+
if: steps.playwright-cache.outputs.cache-hit != 'true'
56+
shell: bash
57+
working-directory: "./code-for-e2e-tests"
58+
run: |
59+
npx playwright install chromium firefox --with-deps
60+
61+
- name: "Install Playwright browsers (Webkit)"
62+
if: ${{ inputs.cross_browser == true }}
63+
shell: bash
64+
working-directory: "./code-for-e2e-tests"
65+
run: |
66+
npx playwright install webkit --with-deps
67+
68+
- name: "Run Playwright tests"
69+
if: ${{ inputs.cross_browser == false }}
70+
shell: bash
71+
working-directory: "./code-for-e2e-tests"
72+
run: |
73+
npm run e2e
74+
75+
- name: "Run Playwright tests (cross browser)"
76+
if: ${{ inputs.cross_browser == true }}
77+
shell: bash
78+
working-directory: "./code-for-e2e-tests"
79+
run: |
80+
npm run e2e -- --config=playwright.config.cross-browser.ts
81+
82+
- name: "Upload report"
83+
uses: actions/upload-artifact@v5
84+
if: ${{ !cancelled() }}
85+
with:
86+
name: playwright-report-e2e-${{ inputs.checkout_ref }}
87+
path: playwright-report/
88+
retention-days: 30
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: "Run Snapshot Tests"
2+
description: "Run snapshot tests against Preprod environment"
3+
4+
inputs:
5+
checkout_ref:
6+
description: "Ref to checkout"
7+
required: true
8+
release_name:
9+
description: "S3 folder to use for references and storing results (e.g. 'release1', 'latest-main')"
10+
required: true
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: "Checkout code"
16+
uses: actions/checkout@v5
17+
with:
18+
ref: ${{ inputs.checkout_ref }}
19+
path: "code-for-snapshot-tests"
20+
21+
- name: "Configure AWS credentials for environment"
22+
uses: aws-actions/configure-aws-credentials@v5
23+
with:
24+
role-session-name: GitHubActionsSession
25+
role-to-assume: ${{ secrets.IAM_ROLE }}
26+
aws-region: ${{ env.AWS_REGION }}
27+
28+
- name: Cache node modules
29+
id: cache-npm
30+
uses: actions/cache@v4
31+
env:
32+
cache-name: cache-node-modules
33+
with:
34+
path: ~/.npm
35+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./code-for-snapshot-tests**/package-lock.json') }}
36+
37+
- name: "Install dependencies"
38+
shell: bash
39+
working-directory: "./code-for-snapshot-tests"
40+
run: |
41+
npm ci --ignore-scripts
42+
43+
- name: "Get current week number and playwright version"
44+
id: cache_key_values
45+
shell: bash
46+
working-directory: "./code-for-snapshot-tests"
47+
run: |
48+
echo "week_num=$(date -u +'%Y-%V')" | tee -a $GITHUB_OUTPUT
49+
echo "playwright_version=$(npm view @playwright/test version)" | tee -a $GITHUB_OUTPUT
50+
51+
- name: "Get current date"
52+
id: folder_name_value
53+
shell: bash
54+
working-directory: "./code-for-snapshot-tests"
55+
run: |
56+
echo "current_datetime=$(date -u +'%Y-%m-%dT%H%M%SZ')" | tee -a $GITHUB_OUTPUT
57+
58+
- name: "Cache Playwright browsers"
59+
uses: actions/cache@v4
60+
id: playwright-cache
61+
with:
62+
path: ~/.cache/ms-playwright
63+
key: ${{ runner.os }}-playwright-${{ steps.cache_key_values.outputs.week_num }}-${{ steps.cache_key_values.outputs.playwright_version }}-${{ hashFiles('**/playwright.config*') }}
64+
65+
- name: "Install Playwright browsers (Chromium, Firefox)"
66+
if: steps.playwright-cache.outputs.cache-hit != 'true'
67+
shell: bash
68+
working-directory: "./code-for-snapshot-tests"
69+
run: |
70+
npx playwright install chromium firefox --with-deps
71+
72+
- name: "Install Playwright browsers (Webkit)"
73+
shell: bash
74+
working-directory: "./code-for-snapshot-tests"
75+
run: |
76+
npx playwright install webkit --with-deps
77+
78+
- name: "Download snapshots from ${{ inputs.release_name }} S3 bucket"
79+
shell: bash
80+
working-directory: "./code-for-snapshot-tests"
81+
run: |
82+
aws s3 sync s3://${{ env.AWS_S3_ARTEFACTS_BUCKET }}/playwright/reference/${{ inputs.release_name }}/ ./e2e/snapshot/
83+
84+
- name: "Run Playwright snapshot tests (no update)"
85+
shell: bash
86+
working-directory: "./code-for-snapshot-tests"
87+
run: |
88+
npm run e2e:snapshot -- --config=playwright.config.cross-browser.ts
89+
env:
90+
CURRENT_DATETIME: ${{ steps.folder_name_value.outputs.current_datetime }}
91+
CHECKOUT_REF: ${{ inputs.checkout_ref }}
92+
93+
- name: "Upload snapshots to ${{ inputs.release_name }} S3 bucket with tag ${{ steps.folder_name_value.outputs.current_datetime }}-${{ inputs.checkout_ref }}"
94+
if: failure()
95+
shell: bash
96+
working-directory: "./code-for-snapshot-tests"
97+
run: |
98+
aws s3 sync --delete ./e2e/snapshot/snapshot_review/ s3://${{ env.AWS_S3_ARTEFACTS_BUCKET }}/playwright/snapshots-for-review/${{ inputs.release_name }}/${{ steps.folder_name_value.outputs.current_datetime }}-${{ inputs.checkout_ref }}/
99+
100+
- name: "Upload report"
101+
uses: actions/upload-artifact@v5
102+
if: always()
103+
with:
104+
name: playwright-report-snapshot-${{ inputs.release_name }}-${{ steps.folder_name_value.outputs.current_datetime }}-${{ inputs.checkout_ref }}
105+
path: playwright-report/
106+
retention-days: 30

0 commit comments

Comments
 (0)