Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/Android-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ jobs:
MPChartExample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected
MPChartExample/build/outputs/androidTest-results/connected
- name: Compare screenshots
env:
CLASSIC_TOKEN: ${{ secrets.CLASSIC_TOKEN }}
run: |
ls -ls MPChartExample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected
cp MPChartExample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected/emulator\(AVD\)\ -\ 9/* screenshotsToCompare
Expand Down
45 changes: 45 additions & 0 deletions screenShotCompare.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
#!/bin/zsh

diffFiles=./screenshotDiffs
mkdir $diffFiles
#cp MPChartExample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected/emulator\(AVD\)\ -\ 9/* screenshotsToCompare
set -x
./git-diff-image/install.sh
GIT_DIFF_IMAGE_OUTPUT_DIR=$diffFiles git diff-image

source scripts/lib.sh

PR=$(echo "$GITHUB_REF_NAME" | sed "s/\// /" | awk '{print $1}')
echo pr=$PR
brew install jq

# delete all old comments, starting with "Screenshot differs:"
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"|")
echo "comments=$comments"
echo "$oldComments" | while read comment; do
echo "delete comment=$comment"
curl_gh -X DELETE https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/comments/"$comment"
done

pushd $diffFiles
body=""
COUNTER=0
ls -la

# ignore an error, when no files where found https://unix.stackexchange.com/a/723909/201876
setopt no_nomatch
for f in *.png; do
if [[ ${f} == "*.png" ]]
then
echo "nothing found"
else
(( COUNTER++ ))

newName="$1-${f}"
mv "${f}" "$newName"
echo "==> Uploaded screenshot $newName"
curl -i -F "file=@$newName" https://www.mxtracks.info/github
echo "==> Add screenshot comment $PR"
body="$body ${f}![screenshot](https://www.mxtracks.info/github/uploads/$newName) <br/><br/>"
fi
done

if [ ! "$body" == "" ]; then
curl_gh -X POST https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/$PR/comments -d "{ \"body\" : \"Screenshot differs: $COUNTER <br/><br/> $body \" }"
fi

popd 1>/dev/null

# set error when diffs are there
[ "$(ls -A $diffFiles)" ] && exit 1 || exit 0
18 changes: 18 additions & 0 deletions scripts/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

## This file is intended to be sourced by other scripts

function err() {
echo >&2 "$@"
}

function curl_gh() {
if [[ -n "$CLASSIC_TOKEN" ]]; then
curl \
--silent \
--header "Authorization: token $CLASSIC_TOKEN" \
"$@"
else
err "WARNING: No CLASSIC_TOKEN found. Skipping API call"
fi
}