Skip to content

Commit

Permalink
Fix when compare files don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed May 6, 2023
1 parent 2b9a8be commit eb36a34
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions .github/workflows/CompareScreenshotComment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,50 @@ jobs:
run_id: ${{ github.event.workflow_run.id }}
name: screenshot-diff
path: screenshot-diff
- id: check-if-there-are-valid-files
name: Check if there are valid files
shell: bash
run: |
# Find all the files ending with _compare.png
files_to_add=$(find . -type f -name "*_compare.png")
# Check for invalid file names and add only valid ones
exist_valid_files="false"
for file in $files_to_add; do
if [[ $file =~ ^[a-zA-Z0-9_./-]+$ ]]; then
exist_valid_files="true"
break
fi
done
echo "exist_valid_files=$exist_valid_files" >> $GITHUB_OUTPUT
- id: push-screenshot-diff
shell: bash
if: steps.check-if-there-are-valid-files.outputs.exist_valid_files == 'true'
env:
BRANCH_NAME: companion_${{ github.event.workflow_run.head_branch }}
run: |
git add "*compare.png"
# Find all the files ending with _compare.png
files_to_add=$(find . -type f -name "*_compare.png")
# Check for invalid file names and add only valid ones
for file in $files_to_add; do
if [[ $file =~ ^[a-zA-Z0-9_./-]+$ ]]; then
git add "$file"
fi
done
git config --global user.name ScreenshotBot
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -m "Add screenshot diff"
git push origin HEAD:$BRANCH_NAME -f
- id: generate-diff-reports
name: Generate diff reports
if: steps.check-if-there-are-valid-files.outputs.exist_valid_files == 'true'
env:
BRANCH_NAME: companion_${{ github.event.workflow_run.head_branch }}
shell: bash
run: |
# Find all the files ending with _compare.png in roborazzi folder
files=$(find . -type f -name "*_compare.png" | grep "roborazzi/" | grep -E "^[a-zA-Z0-9_./-]+$")
# If there are no files, exit
if [ -z "$files" ]; then
echo "No files found"
exit 0
fi
delimiter="$(openssl rand -hex 8)"
echo "reports<<${delimiter}" >> $GITHUB_OUTPUT
Expand Down

0 comments on commit eb36a34

Please sign in to comment.