-
Notifications
You must be signed in to change notification settings - Fork 235
145 lines (132 loc) · 5.71 KB
/
Copy pathe2e_tests.yml
File metadata and controls
145 lines (132 loc) · 5.71 KB
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
name: E2E Tests
on:
deployment_status:
jobs:
_e2e-tests:
# WARNING: Do not set 'environment' here to avoid infinite loop with Vercel deployment_status webhooks
# Vercel sends deployment_status events that could trigger this workflow repeatedly
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
browser: [chromium, "Mobile Safari"]
fail-fast: false
permissions:
contents: read
statuses: write
defaults:
run:
working-directory: "frontend/internal-packages/e2e"
env:
CI: true
URL: ${{ github.event.deployment_status.target_url }}
ENVIRONMENT: ${{ github.event.deployment.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
with:
ref: ${{ github.event.deployment.sha }}
persist-credentials: false
- name: Check deployment conditions
id: check
shell: ruby {0}
working-directory: ${{ github.workspace }}
run: |
event_name = "${{ github.event_name }}"
event_state = "${{ github.event.deployment_status.state }}"
environment_val = "${{ github.event.deployment.environment }}"
target_url = "${{ github.event.deployment_status.target_url }}"
result =
if event_name == "deployment_status" && event_state == "success"
# Production deployment
if (environment_val.include?("Production") && target_url.include?("liam-app-git-main"))
"should_run=true"
# Preview deployment
elsif environment_val.include?("Preview") && environment_val.include?("liam-app")
"should_run=true"
else
"should_run=false"
end
else
"should_run=false"
end
# Same as 'echo "should_run=xxxx" >> $GITHUB_OUTPUT'
output_file = ENV.fetch("GITHUB_OUTPUT")
File.open(output_file, "a") do |file|
file.puts result
end
- name: Setup pnpm
if: steps.check.outputs.should_run == 'true'
uses: ./.github/actions/pnpm-setup
- name: Cache Playwright browsers
if: steps.check.outputs.should_run == 'true'
id: playwright-cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml', '**/playwright.config.ts') }}
restore-keys: |
playwright-${{ runner.os }}-
- name: Install Playwright browsers
if: ${{ steps.check.outputs.should_run == 'true' && steps.playwright-cache.outputs.cache-hit != 'true' }}
run: pnpm exec playwright install --with-deps
- name: Install system dependencies for WebKit
# Some WebKit dependencies seem to lay outside the cache and will need to be installed separately
if: ${{ steps.check.outputs.should_run == 'true' && steps.playwright-cache.outputs.cache-hit == 'true' }}
run: pnpm exec playwright install-deps webkit
# This workflow is triggered for all deployments (liam-app, liam-erd-sample, liam-docs),
# but E2E tests are executed only for liam-app deployments now.
- name: Run e2e tests
if: steps.check.outputs.should_run == 'true'
run: pnpm exec playwright test --project="${{ matrix.browser }}"
env:
URL: ${{ env.URL }}
VERCEL_PROTECTION_BYPASS_SECRET: ${{ secrets.VERCEL_PROTECTION_BYPASS_SECRET }}
# FIXME: This step is not working well. All environments seem to be Preview.
- name: Upload test results
if: ${{ steps.check.outputs.should_run == 'true' && failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: test-results-${{ matrix.browser }}-${{ github.run_id }}-${{ github.job }}
path: frontend/internal-packages/e2e/test-results/
retention-days: 30
- name: Post E2E status manually (with gh)
if: steps.check.outputs.should_run == 'true' && always()
run: |
STATE="${{ job.status }}"
CONTEXT="E2E Tests / e2e-tests (${{ matrix.browser }})"
gh api repos/${{ github.repository }}/statuses/${{ github.sha }} \
--method POST \
--field state="${STATE}" \
--field context="${CONTEXT}" \
--field description="E2E test result for ${{ matrix.browser }}: (${STATE})" \
--field target_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Slack Notification on Failure
if: ${{ steps.check.outputs.should_run == 'true' && env.ENVIRONMENT == 'Production – liam-app' && failure() }}
uses: tokorom/action-slack-incoming-webhook@d57bf1eb618f3dae9509afefa70d5774ad3d42bf # v1.3.0
env:
INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_CLI_CI_WEBHOOK_URL }}
with:
text: "E2E Test Failure"
attachments: |
[
{
"color": "bad",
"fields": [
{
"title": "Browser",
"value": "${{ matrix.browser }}"
},
{
"title": "Result",
"value": "failure"
},
{
"title": "Job URL",
"value": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]