Skip to content

Commit 34fabd4

Browse files
committed
fix(ci): make roborazzi workflow runnable end-to-end
- compare_screenshot: align flavor with store (testPlay, not testFull) - compare_screenshot_comment: workflow_run.event is a string, not the event payload; use pull_requests[0].base.ref to get the base branch - compare_screenshot_comment: re-enable companion-branch cleanup with the original 30-day threshold (testing scaffolding had reduced it to 1s with the actual delete commented out) - compare_screenshot_comment: quote the bot email so the [bot] brackets aren't interpreted by the shell - StudyScreenScreenshotTest: keep per-test-class subdirectory in the capture path so future screenshot tests don't collide - Use dedicated Roborazzi gradle tasks (compareRoborazziPlayDebug) - Remove pinned workflows to match repo style - Use open source gradle cache provider - Rename workflows - Add Apache header https://github.com/takahirom/roborazzi/blob/main/.github/workflows/CompareScreenshot.yml https://github.com/takahirom/roborazzi/blob/main/.github/workflows/CompareScreenshotComment.yml https://github.com/takahirom/roborazzi/blob/main/.github/workflows/StoreScreenshot.yml
1 parent dee375c commit 34fabd4

5 files changed

Lines changed: 147 additions & 87 deletions

File tree

.github/workflows/compare_screenshot_comment.yml renamed to .github/workflows/screenshot_comment.yml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
name: Screenshot compare comment
1+
# Adapted from https://github.com/takahirom/roborazzi/blob/4be7f304fa23f2f00fad67ab612aec2035ac9db2/.github/workflows/CompareScreenshotComment.yml
2+
#
3+
# Copyright 2023 takahirom
4+
# Copyright 2019 Square, Inc.
5+
# Copyright The Android Open Source Project
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
name: "🛠️ Screenshots: Comment"
220

321
on:
422
workflow_run:
523
workflows:
6-
- CompareScreenshot
24+
- "🛠️ Screenshots: Compare"
725
types:
826
- completed
927

1028
permissions: { }
1129

1230
jobs:
1331
Comment-CompareScreenshot:
32+
name: comment
1433
if: >
1534
github.event.workflow_run.event == 'pull_request' &&
1635
github.event.workflow_run.conclusion == 'success'
@@ -38,7 +57,7 @@ jobs:
3857
id: checkout-main
3958
uses: actions/checkout@v4
4059
with:
41-
ref: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.event.pull_request.base.ref || github.event.repository.default_branch }}
60+
ref: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0].base.ref || github.event.repository.default_branch }}
4261
- id: switch-companion-branch
4362
env:
4463
BRANCH_NAME: companion_${{ github.event.workflow_run.head_branch }}
@@ -84,7 +103,7 @@ jobs:
84103
fi
85104
done
86105
git config --global user.name ScreenshotBot
87-
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
106+
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
88107
git commit -m "Add screenshot diff"
89108
git push origin HEAD:"$BRANCH_NAME" -f
90109
- id: generate-diff-reports
@@ -101,7 +120,7 @@ jobs:
101120
echo "reports<<${delimiter}"
102121
103122
# Create markdown table header
104-
echo "Snapshot diff report vs base branch: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.event.pull_request.base.ref || github.event.repository.default_branch }}"
123+
echo "Snapshot diff report vs base branch: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0].base.ref || github.event.repository.default_branch }}"
105124
echo "| File name | Image |"
106125
echo "|-------|-------|"
107126
} >> "$GITHUB_OUTPUT"
@@ -114,7 +133,7 @@ jobs:
114133
done
115134
echo "${delimiter}" >> "$GITHUB_OUTPUT"
116135
- name: Find Comment
117-
uses: peter-evans/find-comment@v3
136+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
118137
id: fc
119138
if: steps.generate-diff-reports.outputs.reports != ''
120139
with:
@@ -123,7 +142,7 @@ jobs:
123142
body-includes: Snapshot diff report
124143

125144
- name: Add or update comment on PR
126-
uses: peter-evans/create-or-update-comment@v4
145+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
127146
if: steps.generate-diff-reports.outputs.reports != ''
128147
with:
129148
comment-id: ${{ steps.fc.outputs.comment-id }}
@@ -138,13 +157,8 @@ jobs:
138157
last_commit_date_timestamp=$(git log -1 --format=%ct "origin/$branch")
139158
now_timestamp=$(date +%s)
140159
# Delete branch if it's older than 1 month
141-
# if [ $((now_timestamp - last_commit_date_timestamp)) -gt 2592000 ]; then
142-
# For testing purpose, delete branch if it's older than 1 second
143-
echo "branch: $branch now_timestamp: $now_timestamp last_commit_date_timestamp: $last_commit_date_timestamp"
144-
if [ $((now_timestamp - last_commit_date_timestamp)) -gt 1 ]; then
145-
# Comment out for demonstration purpose
160+
if [ $((now_timestamp - last_commit_date_timestamp)) -gt 2592000 ]; then
146161
echo "Deleting $branch"
147-
148-
# git push origin --delete "$branch"
162+
git push origin --delete "$branch"
149163
fi
150164
done
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
name: CompareScreenshot
1+
# Adapted from https://github.com/takahirom/roborazzi/blob/4be7f304fa23f2f00fad67ab612aec2035ac9db2/.github/workflows/CompareScreenshot.yml
2+
# Modified from the original: adapted to AnkiDroid CI conventions.
3+
#
4+
# Copyright 2023 takahirom
5+
# Copyright 2019 Square, Inc.
6+
# Copyright The Android Open Source Project
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
name: "🛠️ Screenshots: Compare" # do not rename - referenced by screenshot_comment.yml
221

322
on:
423
push:
@@ -10,6 +29,7 @@ permissions: {}
1029

1130
jobs:
1231
compare-screenshot-test:
32+
name: compare
1333
runs-on: ubuntu-latest
1434
timeout-minutes: 20
1535

@@ -19,7 +39,7 @@ jobs:
1939

2040
steps:
2141
- name: Checkout
22-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
42+
uses: actions/checkout@v6
2343

2444
- name: Configure JDK
2545
uses: actions/setup-java@v5
@@ -28,27 +48,28 @@ jobs:
2848
java-version: "21"
2949

3050
- name: Setup Gradle
31-
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1 # v3.5.0
51+
uses: gradle/actions/setup-gradle@v6
3252
with:
53+
# Use open source provider: https://github.com/gradle/actions/blob/main/docs/setup-gradle.md#basic-caching
54+
cache-provider: basic
3355
gradle-version: wrapper
3456

35-
3657
- uses: dawidd6/action-download-artifact@v3
3758
continue-on-error: true
3859
with:
3960
name: screenshot
40-
workflow: StoreScreenshot.yml
61+
workflow: screenshot_store.yml
4162
branch: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.event.repository.default_branch }}
4263

4364
- name: compare screenshot test
4465
id: compare-screenshot-test
4566
run: |
46-
./gradlew testFullDebugUnitTest -Pscreenshot -Proborazzi.test.compare=true --stacktrace
67+
./gradlew compareRoborazziPlayDebug -Pscreenshot --stacktrace
4768
4869
- uses: actions/upload-artifact@v4
4970
if: ${{ always() }}
5071
with:
51-
name: screenshot-diff
72+
name: screenshot-diff # downloaded by screenshot_comment.yml
5273
path: |
5374
**/build/outputs/roborazzi
5475
retention-days: 30
@@ -76,5 +97,5 @@ jobs:
7697
echo ${{ github.event.number }} > ./pr/NR
7798
- uses: actions/upload-artifact@v4
7899
with:
79-
name: pr
100+
name: pr # downloaded by screenshot_comment.yml
80101
path: pr/
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# ⚠️ Do not rename the file - screenshot_store.yml is referenced by screenshot_compare.yml
2+
#
3+
# Adapted from https://github.com/takahirom/roborazzi/blob/4be7f304fa23f2f00fad67ab612aec2035ac9db2/.github/workflows/StoreScreenshot.yml
4+
# Modified from the original: adapted to AnkiDroid CI conventions.
5+
#
6+
# Copyright 2023 takahirom
7+
# Copyright 2019 Square, Inc.
8+
# Copyright The Android Open Source Project
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
21+
22+
23+
name: "🛠️ Screenshots: Store Baseline"
24+
25+
on:
26+
push:
27+
branches:
28+
- main
29+
pull_request:
30+
31+
permissions: {}
32+
33+
jobs:
34+
store-screenshot-test:
35+
name: store
36+
runs-on: ubuntu-latest
37+
timeout-minutes: 20
38+
39+
permissions:
40+
contents: read # for clone
41+
actions: write # for upload-artifact
42+
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v6
46+
47+
- name: Configure JDK
48+
uses: actions/setup-java@v5
49+
with:
50+
distribution: "temurin"
51+
java-version: "21"
52+
53+
# Better than caching and/or extensions of actions/setup-java
54+
- name: Setup Gradle
55+
uses: gradle/actions/setup-gradle@v6
56+
with:
57+
# Use open source provider: https://github.com/gradle/actions/blob/main/docs/setup-gradle.md#basic-caching
58+
cache-provider: basic
59+
gradle-version: wrapper
60+
61+
- name: record screenshot
62+
id: record-test
63+
run: |
64+
# Use --rerun-tasks to disable cache for test task
65+
./gradlew recordRoborazziPlayDebug -Pscreenshot --stacktrace --rerun-tasks
66+
67+
- uses: actions/upload-artifact@v4
68+
if: ${{ always() }}
69+
with:
70+
name: screenshot # downloaded by screenshot_compare.yml
71+
path: |
72+
**/build/outputs/roborazzi
73+
retention-days: 30
74+
75+
- uses: actions/upload-artifact@v4
76+
if: ${{ always() }}
77+
with:
78+
name: screenshot-reports
79+
path: |
80+
**/build/reports
81+
retention-days: 30
82+
83+
- uses: actions/upload-artifact@v4
84+
if: ${{ always() }}
85+
with:
86+
name: screenshot-test-results
87+
path: |
88+
**/build/test-results
89+
retention-days: 30

.github/workflows/store_screenshot.yml

Lines changed: 0 additions & 64 deletions
This file was deleted.

AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/StudyScreenScreenshotTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class StudyScreenScreenshotTest(
4848
ReviewerFragment.getIntent(targetContext),
4949
).use { scenario ->
5050
scenario.onActivity {
51-
captureScreenRoboImage(filePath = "build/outputs/roborazzi/StudyScreen_$config.png")
51+
captureScreenRoboImage(filePath = "build/outputs/roborazzi/${this.javaClass.simpleName}/$config.png")
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)