Skip to content

Commit

Permalink
Merge pull request #318 from mathoudebine/feature/detect-theme-change…
Browse files Browse the repository at this point in the history
…s-on-pr
  • Loading branch information
mathoudebine authored Sep 13, 2023
2 parents 1613620 + 4a98899 commit 485e2ee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
10 changes: 9 additions & 1 deletion .github/workflows/themes-screenshot-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ jobs:

# Rename screen capture
cp screencap.png "screenshot-$theme.png"

# Compare with original theme preview to detect changes, generate a diff
python3 tools/compare-images.py "screenshot-$theme.png" "$dir/preview.png" "diff-$theme.png"
if [ -f "diff-$theme.png" ]; then
echo "::warning::$theme theme rendering has changed, check if it is intentional or a side-effect. A diff is included in the job artifacts."
fi
fi
done

- name: Archive screenshots
uses: actions/upload-artifact@v3
with:
name: themes-screenshots
path: screenshot-*.png
path: |
screenshot-*.png
diff-*.png
34 changes: 34 additions & 0 deletions tools/compare-images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# turing-smart-screen-python - a Python system monitor and library for USB-C displays like Turing Smart Screen or XuanFang
# https://github.com/mathoudebine/turing-smart-screen-python/

# Copyright (C) 2021-2023 Matthieu Houdebine (mathoudebine)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# compare-images.py: Run by GitHub actions on new PR, to compare theme renderings and generate a diff if it has changed

import sys

from PIL import Image, ImageChops

im1 = Image.open(sys.argv[1]).convert('RGB')
im2 = Image.open(sys.argv[2]).convert('RGB')

if list(im1.getdata()) == list(im2.getdata()):
print("The 2 pictures are visually identical")
else:
print("The 2 pictures are different!")
diff = ImageChops.difference(im1, im2)
diff.save(sys.argv[3])

0 comments on commit 485e2ee

Please sign in to comment.