Skip to content

Commit be82599

Browse files
authored
Merge pull request #213 from AppDevNext/ScreenshotsDiffInPullrequest
Screenshot diff in pull request
2 parents cf1ec54 + e8f9082 commit be82599

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

.github/workflows/Android-CI.yml

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ jobs:
6363
MPChartExample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected
6464
MPChartExample/build/outputs/androidTest-results/connected
6565
- name: Compare screenshots
66+
env:
67+
CLASSIC_TOKEN: ${{ secrets.CLASSIC_TOKEN }}
6668
run: |
6769
ls -ls MPChartExample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected
6870
cp MPChartExample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected/emulator\(AVD\)\ -\ 9/* screenshotsToCompare

screenShotCompare.sh

+45
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,54 @@
1+
#!/bin/zsh
2+
13
diffFiles=./screenshotDiffs
24
mkdir $diffFiles
35
#cp MPChartExample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected/emulator\(AVD\)\ -\ 9/* screenshotsToCompare
46
set -x
57
./git-diff-image/install.sh
68
GIT_DIFF_IMAGE_OUTPUT_DIR=$diffFiles git diff-image
79

10+
source scripts/lib.sh
11+
12+
PR=$(echo "$GITHUB_REF_NAME" | sed "s/\// /" | awk '{print $1}')
13+
echo pr=$PR
14+
brew install jq
15+
16+
# delete all old comments, starting with "Screenshot differs:"
17+
oldComments=$(curl_gh -X GET https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/"$PR"/comments | jq '.[] | (.id |tostring) + "|" + (.user.login | test("github-actions") | tostring) + "|" + (.body | test("Screenshot differs:.*") | tostring)' | grep "true|true" | tr -d "\"" | cut -f1 -d"|")
18+
echo "comments=$comments"
19+
echo "$oldComments" | while read comment; do
20+
echo "delete comment=$comment"
21+
curl_gh -X DELETE https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/comments/"$comment"
22+
done
23+
24+
pushd $diffFiles
25+
body=""
26+
COUNTER=0
27+
ls -la
28+
29+
# ignore an error, when no files where found https://unix.stackexchange.com/a/723909/201876
30+
setopt no_nomatch
31+
for f in *.png; do
32+
if [[ ${f} == "*.png" ]]
33+
then
34+
echo "nothing found"
35+
else
36+
(( COUNTER++ ))
37+
38+
newName="$1-${f}"
39+
mv "${f}" "$newName"
40+
echo "==> Uploaded screenshot $newName"
41+
curl -i -F "file=@$newName" https://www.mxtracks.info/github
42+
echo "==> Add screenshot comment $PR"
43+
body="$body ${f}![screenshot](https://www.mxtracks.info/github/uploads/$newName) <br/><br/>"
44+
fi
45+
done
46+
47+
if [ ! "$body" == "" ]; then
48+
curl_gh -X POST https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/$PR/comments -d "{ \"body\" : \"Screenshot differs: $COUNTER <br/><br/> $body \" }"
49+
fi
50+
51+
popd 1>/dev/null
52+
853
# set error when diffs are there
954
[ "$(ls -A $diffFiles)" ] && exit 1 || exit 0

scripts/lib.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
## This file is intended to be sourced by other scripts
4+
5+
function err() {
6+
echo >&2 "$@"
7+
}
8+
9+
function curl_gh() {
10+
if [[ -n "$CLASSIC_TOKEN" ]]; then
11+
curl \
12+
--silent \
13+
--header "Authorization: token $CLASSIC_TOKEN" \
14+
"$@"
15+
else
16+
err "WARNING: No CLASSIC_TOKEN found. Skipping API call"
17+
fi
18+
}

0 commit comments

Comments
 (0)