diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml
index a02c5306..ea67234a 100644
--- a/.github/workflows/pullrequest.yml
+++ b/.github/workflows/pullrequest.yml
@@ -5,6 +5,8 @@ on:
branches:
- master
pull_request:
+env:
+ resourceRunID: ${{ github.run_id }}-${{ github.run_number }}
jobs:
Build:
@@ -72,7 +74,8 @@ jobs:
set -x
cp extendedSample/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected/emulator\(AVD\)\ -\ ${{ matrix.emulatorApi }}/* screenshotsToCompare${{ matrix.emulatorApi }}
set +x
- ./screenShotCompare.sh
+ echo ${{ env.resourceRunID }}
+ ./screenShotCompare.sh ${{ env.resourceRunID }}
- name: Archive screenshots diffs ${{ matrix.emulatorApi }}
if: ${{ always() }}
uses: actions/upload-artifact@v4
diff --git a/screenShotCompare.sh b/screenShotCompare.sh
index 66080dfe..063213da 100755
--- a/screenShotCompare.sh
+++ b/screenShotCompare.sh
@@ -1,9 +1,53 @@
+#!/bin/bash
+
diffFiles=./screenshotDiffs
mkdir $diffFiles
-#cp app/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
+
+echo "delete all old comments, starting with Screenshot differs:$emulatorApi"
+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:'$emulatorApi'.*") | 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)
"
+ fi
+done
+
+if [ ! "$body" == "" ]; then
+ curl_gh -X POST https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/$PR/comments -d "{ \"body\" : \"Screenshot differs:$emulatorApi $COUNTER
$body \" }"
+fi
+
+popd 1>/dev/null
+
# set error when diffs are there
[ "$(ls -A $diffFiles)" ] && exit 1 || exit 0
diff --git a/scripts/lib.sh b/scripts/lib.sh
new file mode 100644
index 00000000..0952ac9a
--- /dev/null
+++ b/scripts/lib.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+## This file is intended to be sourced by other scripts
+
+function err() {
+ echo >&2 "$@"
+}
+
+function curl_gh() {
+ if [[ -n "$GITHUB_TOKEN" ]]; then
+ curl \
+ --silent \
+ --header "Authorization: token $GITHUB_TOKEN" \
+ "$@"
+ else
+ err "WARNING: No GITHUB_TOKEN found. Skipping API call"
+ fi
+}