-
Notifications
You must be signed in to change notification settings - Fork 30
184 lines (160 loc) · 6.61 KB
/
snapshot_test.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
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
name: SnapshotTest
on:
workflow_dispatch:
pull_request:
branches-ignore:
- 'bump/**'
paths-ignore:
- 'README.md'
- 'image/**'
jobs:
snapshot-testing-and-report:
permissions:
contents: write
pull-requests: write
issues: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Run screenshot tests
id: verifyRoborazziDebug
continue-on-error: true
run: ./gradlew verifyRoborazziDebug -Psnapshot
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract-branch
- name: Remove _compare files if verifyRoborazziDebug is success
id: remove-compare-file
shell: bash
if: steps.verifyRoborazziDebug.outcome == 'success'
run: |
files_to_remove=$(git ls-files "*_compare.png")
# Find all the files ending with _compare.png that are previously tracked
# Check for invalid file names and remove them
for file in $files_to_remove; do
if [[ "$file" =~ ^[a-zA-Z0-9_./-]+$ ]]; then
git rm "$file" -f
fi
done
if [[ -z ${files_to_remove[@]} ]]; then
echo "No files to remove"
else
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -m "Remove screenshot diff"
git push
fi
- name: Upload Test Diff
uses: actions/upload-artifact@v3.1.2
if: ${{ always() }}
with:
name: snapshot-test-diff
path: |
**/build/outputs/roborazzi
retention-days: 30
- name: Upload Test Result
uses: actions/upload-artifact@v3.1.2
if: ${{ always() }}
with:
name: snapshot-test-results
path: |
**/build/test-results
retention-days: 30
- name: Push screenshot Diff
id: push-screenshot-diff
shell: bash
if: steps.verifyRoborazziDebug.outcome == 'failure'
env:
BRANCH_NAME: ${{ steps.extract-branch.outputs.branch }}
run: |
# Find all the files ending with _compare.png
files_to_add=$(find . -type f -name "*_compare.png" | grep "outputs/roborazzi/")
# Check for invalid file names and add only valid ones
for file in $files_to_add; do
if [[ "$file" =~ ^[a-zA-Z0-9_./-]+$ ]]; then
git add "$file" -f
fi
done
if [[ -z ${files_to_add[@]} ]]; then
echo "No files to add"
else
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -m "Add screenshot diff"
git push origin HEAD:"$BRANCH_NAME"
fi
- name: Generate diff reports
id: generate-diff-reports
if: steps.verifyRoborazziDebug.outcome == 'failure'
env:
BRANCH_NAME: ${{ steps.extract-branch.outputs.branch }}
shell: bash
run: |
# Find all the files ending with _compare.png in roborazzi folder
files=$(find . -type f -name "*_compare.png" | grep "roborazzi/" | grep -E "^[a-zA-Z0-9_./-]+$")
delimiter="$(openssl rand -hex 8)"
{
echo "reports<<${delimiter}"
# Create markdown table header
echo "### Snapshot Testing Diff Report"
echo "| File | Compare Image |"
echo "|------|---------------|"
} >> "$GITHUB_OUTPUT"
# Iterate over the files and create table rows
for file in $files; do
# Get the file name and insert newlines every 20 characters
fileName=$(basename "$file" | sed -r 's/(.{20})/\1<br>/g')
urlPart="${BRANCH_NAME//#/%23}/${file//#/%23}"
echo "| [$fileName](https://github.com/${{ github.repository }}/blob/$urlPart) | ![](https://github.com/${{ github.repository }}/blob/$urlPart?raw=true) |" >> "$GITHUB_OUTPUT"
done
echo "${delimiter}" >> "$GITHUB_OUTPUT"
- name: Generate confirm reports
id: generate-confirm-reports
if: steps.verifyRoborazziDebug.outcome == 'success'
env:
BRANCH_NAME: ${{ steps.extract-branch.outputs.branch }}
shell: bash
run: |
# Find all the files ending with .png in roborazzi folder
files=$(find . -type f -name "*.png" | grep "outputs/roborazzi/" | grep -E "^[a-zA-Z0-9_./-]+$")
delimiter="$(openssl rand -hex 8)"
{
echo "reports<<${delimiter}"
# Create markdown table header
echo "### Snapshot Testing Diff Report"
echo "| File | Result |"
echo "|------|--------|"
} >> "$GITHUB_OUTPUT"
# Iterate over the files and create table rows
for file in $files; do
# Get the file name and insert newlines every 20 characters
fileName=$(basename "$file" | sed -r 's/(.{20})/\1<br>/g')
urlPart="${BRANCH_NAME//#/%23}/${file//#/%23}"
echo "| [$fileName](https://github.com/${{ github.repository }}/blob/$urlPart) | ✅ |" >> "$GITHUB_OUTPUT"
done
echo "${delimiter}" >> "$GITHUB_OUTPUT"
- name: Find comment
uses: peter-evans/find-comment@v3
id: find-comment
if: steps.generate-diff-reports.outputs.reports != '' || steps.generate-confirm-reports.outputs.reports != ''
with:
issue-number: ${{ github.event.number }}
comment-author: 'github-actions[bot]'
body-includes: Snapshot Testing Diff Report
- name: Add or update comment on PR
uses: peter-evans/create-or-update-comment@v4
if: steps.generate-diff-reports.outputs.reports != '' || steps.generate-confirm-reports.outputs.reports != ''
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body: ${{ steps.generate-diff-reports.outputs.reports != '' && steps.generate-diff-reports.outputs.reports || steps.generate-confirm-reports.outputs.reports }}
edit-mode: replace