Skip to content

Switch from J11 to J17 in Gradle Updater CI #100

Switch from J11 to J17 in Gradle Updater CI

Switch from J11 to J17 in Gradle Updater CI #100

Workflow file for this run

name: SnapshotTest
on:
workflow_dispatch:
pull_request:
branches-ignore:
- 'bump/**'
paths-ignore:
- 'README.md'
- 'image/**'
jobs:
snapshot-testing-and-report:
permissions:
contents: write
pull-requests: write
issues: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Run screenshot tests
id: verifyRoborazziDebug
continue-on-error: true
run: ./gradlew verifyRoborazziDebug -Psnapshot
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract-branch
- name: Remove _compare files if verifyRoborazziDebug is success
id: remove-compare-file
shell: bash
if: steps.verifyRoborazziDebug.outcome == 'success'
run: |
files_to_remove=$(git ls-files "*_compare.png")
# Find all the files ending with _compare.png that are previously tracked
# Check for invalid file names and remove them
for file in $files_to_remove; do
if [[ "$file" =~ ^[a-zA-Z0-9_./-]+$ ]]; then
git rm "$file" -f
fi
done
if [[ -z ${files_to_remove[@]} ]]; then
echo "No files to remove"
else
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -m "Remove screenshot diff"
git push
fi
- name: Upload Test Diff
uses: actions/upload-artifact@v3.1.2
if: ${{ always() }}
with:
name: snapshot-test-diff
path: |
**/build/outputs/roborazzi
retention-days: 30
- name: Upload Test Result
uses: actions/upload-artifact@v3.1.2
if: ${{ always() }}
with:
name: snapshot-test-results
path: |
**/build/test-results
retention-days: 30
- name: Push screenshot Diff
id: push-screenshot-diff
shell: bash
if: steps.verifyRoborazziDebug.outcome == 'failure'
env:
BRANCH_NAME: ${{ steps.extract-branch.outputs.branch }}
run: |
# Find all the files ending with _compare.png
files_to_add=$(find . -type f -name "*_compare.png" | grep "outputs/roborazzi/")
# 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" -f
fi
done
if [[ -z ${files_to_add[@]} ]]; then
echo "No files to add"
else
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -m "Add screenshot diff"
git push origin HEAD:"$BRANCH_NAME"
fi
- name: Generate diff reports
id: generate-diff-reports
if: steps.verifyRoborazziDebug.outcome == 'failure'
env:
BRANCH_NAME: ${{ steps.extract-branch.outputs.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_./-]+$")
delimiter="$(openssl rand -hex 8)"
{
echo "reports<<${delimiter}"
# Create markdown table header
echo "### Snapshot Testing Diff Report"
echo "| File | Compare Image |"
echo "|------|---------------|"
} >> "$GITHUB_OUTPUT"
# Iterate over the files and create table rows
for file in $files; do
# Get the file name and insert newlines every 20 characters
fileName=$(basename "$file" | sed -r 's/(.{20})/\1<br>/g')
urlPart="${BRANCH_NAME//#/%23}/${file//#/%23}"
echo "| [$fileName](https://github.com/${{ github.repository }}/blob/$urlPart) | ![](https://github.com/${{ github.repository }}/blob/$urlPart?raw=true) |" >> "$GITHUB_OUTPUT"
done
echo "${delimiter}" >> "$GITHUB_OUTPUT"
- name: Generate confirm reports
id: generate-confirm-reports
if: steps.verifyRoborazziDebug.outcome == 'success'
env:
BRANCH_NAME: ${{ steps.extract-branch.outputs.branch }}
shell: bash
run: |
# Find all the files ending with .png in roborazzi folder
files=$(find . -type f -name "*.png" | grep "outputs/roborazzi/" | grep -E "^[a-zA-Z0-9_./-]+$")
delimiter="$(openssl rand -hex 8)"
{
echo "reports<<${delimiter}"
# Create markdown table header
echo "### Snapshot Testing Diff Report"
echo "| File | Result |"
echo "|------|--------|"
} >> "$GITHUB_OUTPUT"
# Iterate over the files and create table rows
for file in $files; do
# Get the file name and insert newlines every 20 characters
fileName=$(basename "$file" | sed -r 's/(.{20})/\1<br>/g')
urlPart="${BRANCH_NAME//#/%23}/${file//#/%23}"
echo "| [$fileName](https://github.com/${{ github.repository }}/blob/$urlPart) | ✅ |" >> "$GITHUB_OUTPUT"
done
echo "${delimiter}" >> "$GITHUB_OUTPUT"
- name: Find comment
uses: peter-evans/find-comment@v3
id: find-comment
if: steps.generate-diff-reports.outputs.reports != '' || steps.generate-confirm-reports.outputs.reports != ''
with:
issue-number: ${{ github.event.number }}
comment-author: 'github-actions[bot]'
body-includes: Snapshot Testing Diff Report
- name: Add or update comment on PR
uses: peter-evans/create-or-update-comment@v4
if: steps.generate-diff-reports.outputs.reports != '' || steps.generate-confirm-reports.outputs.reports != ''
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body: ${{ steps.generate-diff-reports.outputs.reports != '' && steps.generate-diff-reports.outputs.reports || steps.generate-confirm-reports.outputs.reports }}
edit-mode: replace