Skip to content

Commit 903bd81

Browse files
authored
Add script to update local snapshots from CI (#5816)
It seems like the thresholds are too low for all tests to pass when snapshots are generated from windows / linux. We need a better solution to this problem, but in the meantime this script should allow contributors to update their snapshots by downloading them from the last CI run.
1 parent 390e0bf commit 903bd81

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

CONTRIBUTING.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ Browse through [`ARCHITECTURE.md`](ARCHITECTURE.md) to get a sense of how all pi
3434
You can test your code locally by running `./scripts/check.sh`.
3535
There are snapshots test that might need to be updated.
3636
Run the tests with `UPDATE_SNAPSHOTS=true cargo test --workspace --all-features` to update all of them.
37+
If CI keeps complaining about snapshots (which could happen if you don't use macOS, snapshots in CI are currently
38+
rendered with macOS), you can instead run `./scripts/update_snapshots_from_ci.sh` to update your local snapshots from
39+
the last CI run of your PR (which will download the `test_results` artefact).
3740
For more info about the tests see [egui_kittest](./crates/egui_kittest/README.md).
38-
Snapshots and other big files are stored with git lfs. See [Working with lfs](#working-with-lfs) for more info.
41+
Snapshots and other big files are stored with git lfs. See [Working with git lfs](#working-with-git-lfs) for more info.
3942
If you see an `InvalidSignature` error when running snapshot tests, it's probably a problem related to git-lfs.
4043

4144
When you have something that works, open a draft PR. You may get some helpful feedback early!

scripts/update_snapshots_from_ci.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# This script searches for the last CI run with your branch name, downloads the test_results artefact
3+
# and replaces your existing snapshots with the new ones.
4+
# Make sure you have the gh cli installed and authenticated before running this script.
5+
6+
set -eu
7+
8+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
9+
10+
RUN_ID=$(gh run list --branch "$BRANCH" --workflow "Rust" --json databaseId -q '.[0].databaseId')
11+
12+
ECHO "Downloading test results from run $RUN_ID from branch $BRANCH"
13+
14+
# remove any existing .new.png that might have been left behind
15+
find . -type d -path "*/tests/snapshots*" | while read dir; do
16+
find "$dir" -type f -name "*.new.png" | while read file; do
17+
rm "$file"
18+
done
19+
done
20+
21+
22+
gh run download "$RUN_ID" --name "test-results" --dir tmp_artefacts
23+
24+
# move the snapshots to the correct location, overwriting the existing ones
25+
rsync -a tmp_artefacts/ .
26+
27+
rm -r tmp_artefacts
28+
29+
# rename the .new.png files to .png
30+
find . -type d -path "*/tests/snapshots*" | while read dir; do
31+
find "$dir" -type f -name "*.new.png" | while read file; do
32+
mv -f "$file" "${file%.new.png}.png"
33+
done
34+
done
35+
36+
echo "Done!"

0 commit comments

Comments
 (0)