-
Notifications
You must be signed in to change notification settings - Fork 1
183 lines (157 loc) · 5.36 KB
/
vrt.yml
File metadata and controls
183 lines (157 loc) · 5.36 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
name: Visual Regression Testing
on:
pull_request:
types: [opened, synchronize, reopened]
paths-ignore:
- '**.md'
- 'docs/**'
- '.gitignore'
jobs:
vrt:
name: Visual Regression Tests
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'gradle'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: |
npm ci
npx playwright install --with-deps chromium
- name: Build application
run: ./gradlew build -x test -x detekt
- name: Start application
run: |
./gradlew bootRun &
sleep 30
curl --retry 10 --retry-delay 5 --retry-connrefused http://localhost:8080
- name: Run Visual Regression Tests
id: vrt
run: npm run test:vrt
env:
BASE_URL: http://localhost:8080
- name: Upload test report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
retention-days: 7
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: test-results/
retention-days: 7
- name: Upload snapshots on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: failed-snapshots
path: |
tests/vrt/**/*-actual.png
tests/vrt/**/*-diff.png
retention-days: 30
- name: Comment PR with results
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let message = '## 🎨 Visual Regression Test Results\n\n';
// Check if tests passed
const testOutcome = '${{ steps.vrt.outcome }}';
if (testOutcome === 'success') {
message += '✅ **All visual regression tests passed!**\n\n';
message += 'All page screenshots match the expected baselines.\n';
} else {
message += '❌ **Visual regression tests failed**\n\n';
message += 'Some pages have visual differences. Please review the artifacts:\n\n';
message += '### 📋 Actions to take:\n';
message += '1. [Download test artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n';
message += '2. Review the diff images to understand the changes\n';
message += '3. If changes are intentional, add `update-snapshots` label to this PR\n';
}
message += '\n### 📊 Test Coverage\n';
message += '- Desktop (1280x720)\n';
message += '- Tablet (iPad)\n';
message += '- Mobile (iPhone 13)\n';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
})
update-snapshots:
name: Update Visual Snapshots
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'update-snapshots')
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'gradle'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: |
npm ci
npx playwright install --with-deps chromium
- name: Build application
run: ./gradlew build -x test -x detekt
- name: Start application
run: |
./gradlew bootRun &
sleep 30
curl --retry 10 --retry-delay 5 --retry-connrefused http://localhost:8080
- name: Update snapshots
run: npm run test:vrt:update
env:
BASE_URL: http://localhost:8080
- name: Commit updated snapshots
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add tests/vrt/**/*.png
if git diff --staged --quiet; then
echo "No snapshot changes detected"
else
git commit -m "chore: update visual regression snapshots"
git push
fi
- name: Remove label
if: always()
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'update-snapshots'
})