Skip to content

Commit

Permalink
Adding helper for quickly fixing goldens (#6203)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderDake authored Aug 18, 2023
1 parent 0af79f0 commit 0dfcda3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ jobs:
with:
name: golden_image_failures.${{ matrix.bot }}
path: packages/devtools_app/test/**/failures/*.png
- name: Notify of Quick Fix
if: failure()
env:
WORKFLOW_ID: ${{ github.run_id }}
run: |
echo "::notice title=To Quickly Fix Goldens:: Run \`./tool/fix_goldens.sh $WORKFLOW_ID\` on your local branch."
integration-test:
name: integration-test ${{ matrix.bot }} - ${{ matrix.device }}
Expand Down
65 changes: 65 additions & 0 deletions tool/fix_goldens.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash -e
RUN_ID=$1

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR/.."

help()
{
# Display Help
>&2 echo "A helper script for downloading and applying golden fixes, when they are broken."
>&2 echo
>&2 echo "Syntax: fix_goldens.sh RUN_ID"
>&2 echo "RUN_ID The ID of the workflow run where the goldens are failing"
>&2 echo
}

if [ $# -gt 1 ]
then
>&2 echo "ERROR: $0 takes only 1 argument"
help
exit 1
fi

if [ -z "$1" ]
then
>&2 echo "ERROR: Expected a RUN_ID"
help
exit 1
fi

DOWNLOAD_DIR=$(mktemp -d)

echo "Downloading the artifacts to $DOWNLOAD_DIR"
gh run download $RUN_ID -p "*golden_image_failures*" -D "$DOWNLOAD_DIR"

NEW_GOLDENS=$(find $DOWNLOAD_DIR -type f | grep "testImage.png" )

cd packages/devtools_app/test/

while IFS= read -r GOLDEN ; do
FILE_NAME=$(basename $GOLDEN | sed "s|_testImage.png$|.png|")
FOUND_FILES=$(find . -name "$FILE_NAME" )
FOUND_FILE_COUNT=$(echo -n "$FOUND_FILES" | grep -c '^')

if [[ $FOUND_FILE_COUNT -ne 1 ]] ; then
# If there are goldens with conflicting names, we need to pick which one
# maps to the artifact.
echo "Multiple goldens found for $(echo $GOLDEN| sed 's|^.*golden_image_failures[^/]*/||')"
echo "Select which golden should be overridden:"

select SELECTED_FILE in $FOUND_FILES
do
DEST_PATH="$SELECTED_FILE"
break;
done </dev/tty
else
DEST_PATH=$FOUND_FILES
fi

echo "FIXED: $DEST_PATH"
mv "$GOLDEN" "$DEST_PATH"
done <<< "$NEW_GOLDENS"

echo "Done updating $(echo -n "$NEW_GOLDENS" | grep -c '^') goldens"

0 comments on commit 0dfcda3

Please sign in to comment.