-
Notifications
You must be signed in to change notification settings - Fork 6
209 lines (193 loc) · 6.98 KB
/
test-playwright.yml
File metadata and controls
209 lines (193 loc) · 6.98 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
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
name: Playwright test
on:
workflow_call:
inputs:
ARTIFACT_INCLUDE_HIDDEN_FILES:
description: Whether to include hidden files in the artifact.
type: boolean
default: false
required: false
ARTIFACT_NAME:
description: Name for the artifact.
type: string
default: 'artifact'
required: false
ARTIFACT_OVERWRITE:
description: Determine if an artifact with a matching name will be deleted before a new one is uploaded or not.
type: boolean
default: false
required: false
ARTIFACT_PATH:
description: A file, directory or wildcard pattern that describes what to upload.
type: string
required: true
ARTIFACT_RETENTION_DAYS:
description: Duration after which artifact will expire in day.
type: number
default: 30
required: false
COMPOSER_DEPS_INSTALL:
description: Whether to install Composer dependencies.
type: boolean
default: false
required: false
NODE_VERSION:
description: Node version with which the node script will be executed.
default: 18
required: false
type: string
NPM_REGISTRY_DOMAIN:
description: Domain of the private npm registry.
default: https://npm.pkg.github.com/
required: false
type: string
PHP_VERSION:
description: PHP version with which the dependencies are installed.
default: '8.2'
required: false
type: string
PLAYWRIGHT_BROWSER_ARGS:
description: Set of arguments passed to `npx playwright install`.
default: '--with-deps'
required: false
type: string
PLAYWRIGHT_CLI_ARGS:
description: Arguments and flags for `npx playwright test`. When set SCRIPT_NAME will be ignored.
default: ''
required: false
type: string
PRE_SCRIPT:
description: Run custom shell code before executing the test runner.
default: ''
required: false
type: string
SCRIPT_NAME:
description: The name of a custom npm script to run the tests. Ignored when PLAYWRIGHT_GREP is set.
default: ''
required: false
type: string
WORK_DIR:
description: Working directory for npm install, Playwright install, and test execution.
default: '.'
required: false
type: string
secrets:
ENV_FILE_DATA:
description: Additional environment variables for the tests.
required: false
GITHUB_USER_EMAIL:
description: Email address for the GitHub user configuration.
required: false
GITHUB_USER_NAME:
description: Username for the GitHub user configuration.
required: false
GITHUB_USER_SSH_KEY:
description: Private SSH key associated with the GitHub user passed as `GITHUB_USER_NAME`.
required: false
NPM_REGISTRY_TOKEN:
description: Authentication for the private npm registry.
required: false
COMPOSER_AUTH_JSON:
description: Authentication for privately hosted packages and repositories as a JSON formatted object.
required: false
jobs:
run-playwright-test:
timeout-minutes: 60
runs-on: ubuntu-latest
env:
PHP_CHECK: false
NODE_CACHE_MODE: ''
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up SSH
env:
GITHUB_USER_SSH_KEY: ${{ secrets.GITHUB_USER_SSH_KEY }}
if: ${{ env.GITHUB_USER_SSH_KEY != '' }}
uses: webfactory/ssh-agent@v0.9.1
with:
ssh-private-key: ${{ env.GITHUB_USER_SSH_KEY }}
- name: Set up Git
env:
GITHUB_USER_EMAIL: ${{ secrets.GITHUB_USER_EMAIL }}
GITHUB_USER_NAME: ${{ secrets.GITHUB_USER_NAME }}
if: ${{ env.GITHUB_USER_EMAIL != '' && env.GITHUB_USER_NAME != '' }}
run: |
git config --global user.email "${{ env.GITHUB_USER_EMAIL }}"
git config --global user.name "${{ env.GITHUB_USER_NAME }}"
- name: Set up node cache mode
run: |
WORK_DIR="${{ inputs.WORK_DIR }}"
if [ -f "${GITHUB_WORKSPACE}/${WORK_DIR}/package-lock.json" ] || [ -f "${GITHUB_WORKSPACE}/${WORK_DIR}/npm-shrinkwrap.json" ]; then
echo "NODE_CACHE_MODE=npm" >> $GITHUB_ENV
else
echo "No lock files found or unknown package manager"
fi
- name: Set up PHP
if: ${{ inputs.COMPOSER_DEPS_INSTALL }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.PHP_VERSION }}
tools: composer
coverage: none
- name: Install Composer dependencies
if: ${{ inputs.COMPOSER_DEPS_INSTALL }}
uses: ramsey/composer-install@v3
env:
COMPOSER_AUTH: '${{ secrets.COMPOSER_AUTH_JSON }}'
with:
composer-options: '--prefer-dist'
- name: Set up node
uses: actions/setup-node@v4
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
with:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}
cache: ${{ env.NODE_CACHE_MODE }}
- name: Install dependencies
working-directory: ${{ inputs.WORK_DIR }}
run: npm ${{ env.NODE_CACHE_MODE == 'npm' && 'ci' || 'install' }}
- name: Install Playwright dependencies
working-directory: ${{ inputs.WORK_DIR }}
run: |
npx playwright install ${{ inputs.PLAYWRIGHT_BROWSER_ARGS }}
- name: Create environment file
working-directory: ${{ inputs.WORK_DIR }}
run: |
touch .env.ci
echo "${{ secrets.ENV_FILE_DATA }}" >> .env.ci
- name: Execute custom code before executing the test script
working-directory: ${{ inputs.WORK_DIR }}
env:
GH_TOKEN: ${{ github.token }}
run: |
set -a && source .env.ci && set +a
${{ inputs.PRE_SCRIPT }}
- name: Run script for test
id: run-script
continue-on-error: true
working-directory: ${{ inputs.WORK_DIR }}
run: |
# Ensure .env.ci is deleted on exit
trap 'rm -f .env.ci' EXIT
if [ -n "${{ inputs.PLAYWRIGHT_CLI_ARGS }}" ]; then
npx playwright test ${{ inputs.PLAYWRIGHT_CLI_ARGS }}
else
npm run ${{ inputs.SCRIPT_NAME }}
fi
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.ARTIFACT_NAME }}
path: |
${{ inputs.ARTIFACT_PATH }}
overwrite: ${{ inputs.ARTIFACT_OVERWRITE }}
include-hidden-files: ${{ inputs.ARTIFACT_INCLUDE_HIDDEN_FILES }}
retention-days: ${{ inputs.ARTIFACT_RETENTION_DAYS }}
- name: Check test results
if: steps.run-script.outcome == 'failure'
run: |
echo "Tests failed! Check the artifacts for details."
exit 1