Skip to content

Commit 647f80c

Browse files
authored
Merge pull request #689 from OskarEichler/codex/viewshot-snapshot-import
fix(tooling): import only unambiguous actual CI snapshots
2 parents eb3dce2 + a42dd53 commit 647f80c

2 files changed

Lines changed: 35 additions & 66 deletions

File tree

example-web/scripts/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ When the CI generates new snapshots for Linux (chromium-linux), you can easily i
2828
### What it does
2929

3030
1. Downloads the `web-snapshots-actual` artifact from the specified CI run
31-
2. Extracts the snapshots
32-
3. Copies them to `e2e/snapshots/reference/viewshot.spec.ts-snapshots/`
33-
4. Renames `-actual.png` files to the standard naming convention
31+
2. Stages only `*-actual.png` images; expected/diff images are ignored
32+
3. Rejects empty or duplicate-name artifacts before changing references
33+
4. Copies the staged images to `e2e/snapshots/reference/viewshot.spec.ts-snapshots/`, dropping the `-actual` suffix
34+
5. Removes its temporary download directory on exit
3435

3536
### After running
3637

3738
1. Review changes: `git diff e2e/snapshots/reference/`
3839
2. Commit: `git add e2e/snapshots/reference/ && git commit -m "Update Linux snapshots from CI"`
3940
3. Push: `git push`
4041

41-
The next CI run will use these new reference snapshots and should pass ✅
42+
The next CI run uses the reviewed references. Other functional failures or
43+
unintended visual changes still need investigation; importing images is not a
44+
substitute for checking correctness.
Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,41 @@
11
#!/bin/bash
2+
# Import actual Linux snapshots from one GitHub Actions run.
3+
set -euo pipefail
24

3-
# Script to update Linux snapshots from CI artifacts
4-
# Usage: ./scripts/update-snapshots-from-ci.sh <run-id>
5-
6-
set -e
7-
8-
if [ -z "$1" ]; then
9-
echo "❌ Error: Please provide a GitHub Actions run ID"
10-
echo "Usage: $0 <run-id>"
11-
echo ""
12-
echo "Example: $0 18528005182"
13-
echo ""
14-
echo "Find the run ID in the GitHub Actions URL:"
15-
echo "https://github.com/gre/react-native-view-shot/actions/runs/<RUN_ID>"
5+
if [ "$#" -ne 1 ] || [[ ! $1 =~ ^[0-9]+$ ]]; then
6+
echo "Usage: $0 <numeric-run-id>" >&2
167
exit 1
178
fi
189

1910
RUN_ID=$1
2011
ARTIFACT_NAME="web-snapshots-actual"
2112
SNAPSHOT_DIR="e2e/snapshots/reference/viewshot.spec.ts-snapshots"
13+
DOWNLOAD_DIR=$(mktemp -d "${TMPDIR:-/tmp}/viewshot-snapshots.XXXXXX")
14+
trap 'rm -rf -- "$DOWNLOAD_DIR"' EXIT
2215

23-
echo "🔍 Fetching artifacts from run $RUN_ID..."
24-
25-
# Download the artifact
2616
cd "$(dirname "$0")/.."
27-
gh run download "$RUN_ID" -n "$ARTIFACT_NAME" -D /tmp/playwright-snapshots || {
28-
echo "❌ Failed to download artifact '$ARTIFACT_NAME'"
29-
echo ""
30-
echo "💡 Make sure:"
31-
echo " 1. The run ID is correct"
32-
echo " 2. The artifact exists (may take a few minutes after test completion)"
33-
echo " 3. You have GitHub CLI (gh) installed and authenticated"
34-
exit 1
35-
}
36-
37-
echo "✅ Artifact downloaded to /tmp/playwright-snapshots"
38-
39-
# Create snapshot directory if it doesn't exist
40-
mkdir -p "$SNAPSHOT_DIR"
41-
42-
# Copy actual snapshots to reference directory
43-
if [ -d "/tmp/playwright-snapshots" ]; then
44-
echo "📂 Copying snapshots to $SNAPSHOT_DIR..."
45-
46-
# Find all PNG files and copy them
47-
find /tmp/playwright-snapshots -name "*.png" | while read -r file; do
48-
filename=$(basename "$file")
49-
50-
# If it's an -actual.png file, rename it to the standard name
51-
if [[ $filename == *"-actual.png" ]]; then
52-
newname="${filename%-actual.png}.png"
53-
echo "$newname"
54-
cp "$file" "$SNAPSHOT_DIR/$newname"
55-
else
56-
echo "$filename"
57-
cp "$file" "$SNAPSHOT_DIR/$filename"
58-
fi
59-
done
60-
61-
echo ""
62-
echo "✅ Snapshots updated successfully!"
63-
echo ""
64-
echo "📋 Next steps:"
65-
echo " 1. Review the changes: git diff $SNAPSHOT_DIR"
66-
echo " 2. Commit the new snapshots: git add $SNAPSHOT_DIR && git commit -m 'Update Linux snapshots from CI'"
67-
echo " 3. Push: git push"
68-
69-
# Clean up
70-
rm -rf /tmp/playwright-snapshots
71-
else
72-
echo "❌ No snapshots found in artifact"
17+
echo "Fetching $ARTIFACT_NAME from run $RUN_ID..."
18+
gh run download "$RUN_ID" -n "$ARTIFACT_NAME" -D "$DOWNLOAD_DIR/artifact"
19+
20+
# Validate all destinations before changing any checked-in reference image.
21+
mkdir "$DOWNLOAD_DIR/staged"
22+
count=0
23+
while IFS= read -r -d '' file; do
24+
filename=${file##*/}
25+
destination="$DOWNLOAD_DIR/staged/${filename%-actual.png}.png"
26+
if [ -e "$destination" ]; then
27+
echo "Duplicate snapshot destination: ${filename%-actual.png}.png" >&2
28+
exit 1
29+
fi
30+
cp "$file" "$destination"
31+
count=$((count + 1))
32+
done < <(find "$DOWNLOAD_DIR/artifact" -type f -name '*-actual.png' -print0)
33+
34+
if [ "$count" -eq 0 ]; then
35+
echo "No actual snapshots found in artifact." >&2
7336
exit 1
7437
fi
7538

39+
mkdir -p "$SNAPSHOT_DIR"
40+
cp "$DOWNLOAD_DIR/staged/"*.png "$SNAPSHOT_DIR/"
41+
echo "Updated $count snapshots. Review git diff -- $SNAPSHOT_DIR before committing."

0 commit comments

Comments
 (0)