diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e0596121..613de20c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,8 +34,11 @@ Browse through [`ARCHITECTURE.md`](ARCHITECTURE.md) to get a sense of how all pi You can test your code locally by running `./scripts/check.sh`. There are snapshots test that might need to be updated. Run the tests with `UPDATE_SNAPSHOTS=true cargo test --workspace --all-features` to update all of them. +If CI keeps complaining about snapshots (which could happen if you don't use macOS, snapshots in CI are currently +rendered with macOS), you can instead run `./scripts/update_snapshots_from_ci.sh` to update your local snapshots from +the last CI run of your PR (which will download the `test_results` artefact). For more info about the tests see [egui_kittest](./crates/egui_kittest/README.md). -Snapshots and other big files are stored with git lfs. See [Working with lfs](#working-with-lfs) for more info. +Snapshots and other big files are stored with git lfs. See [Working with git lfs](#working-with-git-lfs) for more info. If you see an `InvalidSignature` error when running snapshot tests, it's probably a problem related to git-lfs. When you have something that works, open a draft PR. You may get some helpful feedback early! diff --git a/scripts/update_snapshots_from_ci.sh b/scripts/update_snapshots_from_ci.sh new file mode 100755 index 00000000..755399d1 --- /dev/null +++ b/scripts/update_snapshots_from_ci.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# This script searches for the last CI run with your branch name, downloads the test_results artefact +# and replaces your existing snapshots with the new ones. +# Make sure you have the gh cli installed and authenticated before running this script. + +set -eu + +BRANCH=$(git rev-parse --abbrev-ref HEAD) + +RUN_ID=$(gh run list --branch "$BRANCH" --workflow "Rust" --json databaseId -q '.[0].databaseId') + +ECHO "Downloading test results from run $RUN_ID from branch $BRANCH" + +# remove any existing .new.png that might have been left behind +find . -type d -path "*/tests/snapshots*" | while read dir; do + find "$dir" -type f -name "*.new.png" | while read file; do + rm "$file" + done +done + + +gh run download "$RUN_ID" --name "test-results" --dir tmp_artefacts + +# move the snapshots to the correct location, overwriting the existing ones +rsync -a tmp_artefacts/ . + +rm -r tmp_artefacts + +# rename the .new.png files to .png +find . -type d -path "*/tests/snapshots*" | while read dir; do + find "$dir" -type f -name "*.new.png" | while read file; do + mv -f "$file" "${file%.new.png}.png" + done +done + +echo "Done!"