-
Notifications
You must be signed in to change notification settings - Fork 1
159 lines (155 loc) · 5.49 KB
/
playwright.yml
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
name: Playwright Tests
on:
push:
paths-ignore:
- 'README.md'
branches: main
pull_request:
paths-ignore:
- 'README.md'
branches: main
permissions:
contents: write
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
run: |
folders=()
for dir in test*; do
if [ -d "$dir" ]; then
# check if the folder contains a playwright.config.ts file
if [ -f "$dir/playwright.config.ts" ]; then
echo "Adding $dir to matrix (contains Playwright)"
folders+=("$dir")
else
echo "Skipping $dir (playwright.config.ts not found)"
fi
fi
done
if [ ${#folders[@]} -eq 0 ]; then
echo "No valid folders found."
folders_json='[]'
else
folders_json=$(printf '%s\n' "${folders[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))')
fi
echo "Folders JSON: $folders_json"
echo "matrix={\"folder\": $folders_json}" >> $GITHUB_OUTPUT
test:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
fail-fast: false
max-parallel: 4
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
working-directory: ${{ matrix.folder }}
- name: Install Playwright Browsers
run: npx playwright install --with-deps
working-directory: ${{ matrix.folder }}
- name: Run Playwright tests
run: npx playwright test
working-directory: ${{ matrix.folder }}
- name: List test-results directory
run: |
echo "Listing contents of ${{ matrix.folder }}/test-results/"
ls -R ${{ matrix.folder }}/test-results/
- name: Collect trace.zip files
run: |
mkdir -p zip-files/${{ matrix.folder }}
find ${{ matrix.folder }}/test-results/ -name 'trace.zip' -type f -exec cp --parents {} zip-files/${{ matrix.folder }}/ \;
- name: List collected trace.zip files
run: |
echo "Listing collected trace.zip files in zip-files/${{ matrix.folder }}/"
ls -R zip-files/${{ matrix.folder }}/
- uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ matrix.folder }}
path: zip-files/${{ matrix.folder }}
retention-days: 30
# - uses: actions/upload-artifact@v4
# if: always()
# with:
# name: playwright-report-${{ matrix.folder }}
# path: ${{ matrix.folder }}/playwright-report/
# retention-days: 30
deploy:
needs: test
runs-on: ubuntu-latest
if: needs.test.result == 'success'
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: all-trace-files/
- name: List downloaded artifacts
run: |
echo "Listing contents of all-trace-files/"
ls -R all-trace-files/
- name: Collect all trace.zip files
run: |
mkdir -p deploy-zip-files
find all-trace-files/ -name 'trace.zip' -type f -print0 | while IFS= read -r -d '' file; do
relpath=${file#all-trace-files/}
mkdir -p "deploy-zip-files/$(dirname "$relpath")"
cp "$file" "deploy-zip-files/$relpath"
done
- name: List deploy-zip-files directory
run: |
echo "Listing contents of deploy-zip-files/"
ls -R deploy-zip-files/
- name: Generate index.html
run: |
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>Playwright Traces</title><style>
body {
background-color: #2B313F;
color: #EAF4FC;
font-family: Arial, sans-serif;
}
h1 {
text-align: center;
margin-top: 50px;
}
ul {
list-style-type: none;
padding: 0;
}
li {
text-align: center;
font-size: 1.2em;
margin: 20px 0;
}
a {
color: #EAF4FC;
text-decoration: none;
padding: 10px 20px;
display: inline-block;
transition: all 0.3s ease;
}
a:hover {
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.3);
}
</style></head><body><h1>Playwright Traces</h1><ul>" > deploy-zip-files/index.html
find deploy-zip-files/ -name 'trace.zip' -type f | while read file; do
relpath=${file#deploy-zip-files/}
url="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/$relpath"
trace_url="https://trace.playwright.dev/?trace=$url"
echo "<li><a href='$trace_url'>$relpath</a></li>" >> deploy-zip-files/index.html
done
echo "</ul></body></html>" >> deploy-zip-files/index.html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: deploy-zip-files/