Skip to content

Commit 3625c31

Browse files
committed
Fix CI workflow to use Python-based snapshot generation
The previous workflow tried to capture terminal output with termshot, but baselines are Python-generated PNG images. Now the CI: 1. Verifies prompt syntax with zsh -n 2. Generates snapshots using generate_snapshots.py 3. Compares against committed baselines with ImageMagick 4. Uploads diffs on failure for debugging
1 parent 7cb7990 commit 3625c31

File tree

1 file changed

+59
-51
lines changed

1 file changed

+59
-51
lines changed

.github/workflows/visual-tests.yml

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,69 +20,77 @@ jobs:
2020
- name: Checkout
2121
uses: actions/checkout@v4
2222

23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: '3.11'
27+
2328
- name: Install dependencies
2429
run: |
30+
pip install Pillow
2531
sudo apt-get update
26-
sudo apt-get install -y zsh git aha wkhtmltopdf imagemagick fonts-jetbrains-mono
32+
sudo apt-get install -y zsh imagemagick
2733
28-
- name: Install termshot
34+
- name: Verify prompt syntax
2935
run: |
30-
curl -fsSL https://github.com/homeport/termshot/releases/latest/download/termshot_linux_amd64.tar.gz \
31-
| sudo tar -xz -C /usr/local/bin termshot
36+
zsh -n dot_prompt.zsh
37+
echo "Prompt syntax OK"
3238
33-
- name: Run visual regression tests
39+
- name: Generate current snapshots
3440
run: |
35-
chmod +x test/visual/run-tests.sh test/visual/scenarios.zsh
36-
./test/visual/run-tests.sh test
37-
env:
38-
TERM: xterm-256color
41+
mkdir -p test/visual/actual
42+
python3 test/visual/generate_snapshots.py
43+
mv test/visual/snapshots/*.png test/visual/actual/
3944
40-
- name: Upload diff artifacts
41-
if: failure()
42-
uses: actions/upload-artifact@v4
43-
with:
44-
name: visual-diff
45-
path: test/visual/diff/
46-
retention-days: 7
45+
- name: Restore baseline snapshots
46+
run: |
47+
git checkout HEAD -- test/visual/snapshots/
4748
48-
- name: Upload actual screenshots
49-
if: failure()
50-
uses: actions/upload-artifact@v4
51-
with:
52-
name: visual-actual
53-
path: test/visual/actual/
54-
retention-days: 7
49+
- name: Compare snapshots
50+
run: |
51+
failed=0
52+
mkdir -p test/visual/diff
5553
56-
# Job to update baselines (manual trigger)
57-
update-baselines:
58-
runs-on: ubuntu-latest
59-
if: github.event_name == 'workflow_dispatch'
54+
for baseline in test/visual/snapshots/*.png; do
55+
name=$(basename "$baseline")
56+
actual="test/visual/actual/$name"
57+
diff_file="test/visual/diff/$name"
6058
61-
steps:
62-
- name: Checkout
63-
uses: actions/checkout@v4
59+
if [ ! -f "$actual" ]; then
60+
echo "MISSING: $name"
61+
failed=1
62+
continue
63+
fi
6464
65-
- name: Install dependencies
66-
run: |
67-
sudo apt-get update
68-
sudo apt-get install -y zsh git aha wkhtmltopdf imagemagick fonts-jetbrains-mono
65+
# Compare images using ImageMagick
66+
diff_pixels=$(compare -metric AE "$baseline" "$actual" "$diff_file" 2>&1) || true
6967
70-
- name: Install termshot
71-
run: |
72-
curl -fsSL https://github.com/homeport/termshot/releases/latest/download/termshot_linux_amd64.tar.gz \
73-
| sudo tar -xz -C /usr/local/bin termshot
68+
if [ "$diff_pixels" = "0" ]; then
69+
echo "PASS: $name"
70+
rm -f "$diff_file"
71+
else
72+
echo "FAIL: $name ($diff_pixels pixels differ)"
73+
failed=1
74+
fi
75+
done
7476
75-
- name: Generate baselines
76-
run: |
77-
chmod +x test/visual/run-tests.sh test/visual/scenarios.zsh
78-
./test/visual/run-tests.sh generate
79-
env:
80-
TERM: xterm-256color
77+
if [ $failed -eq 1 ]; then
78+
echo ""
79+
echo "Visual regression test failed!"
80+
echo "If changes are intentional, run: python3 test/visual/generate_snapshots.py"
81+
echo "Then commit the updated snapshots."
82+
exit 1
83+
fi
8184
82-
- name: Commit updated baselines
83-
run: |
84-
git config user.name "GitHub Actions"
85-
git config user.email "actions@github.com"
86-
git add test/visual/snapshots/
87-
git commit -m "Update visual regression baselines" || echo "No changes to commit"
88-
git push
85+
echo ""
86+
echo "All visual tests passed!"
87+
88+
- name: Upload diff artifacts
89+
if: failure()
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: visual-diff
93+
path: |
94+
test/visual/diff/
95+
test/visual/actual/
96+
retention-days: 7

0 commit comments

Comments
 (0)