Skip to content

p4: Add & update documentation #464

p4: Add & update documentation

p4: Add & update documentation #464

Workflow file for this run

name: Test
on:
pull_request:
merge_group:
types: [checks_requested]
push:
branches: [ main ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Check for Android changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
android: ${{ steps.filter.outputs.android }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
android:
- 'android/**'
- '.github/**'
screenshots:
name: Screenshot tests
needs: changes
if: ${{ needs.changes.outputs.android == 'true' }}
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: wrapper
- name: Run tests
id: screenshot-tests
run: |
cd android
./gradlew verifyPaparazziDebug --continue --quiet
- name: Create companion branch and comment content
id: create-companion-branch
# Don't run on merge queue branches
if: ${{ !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && failure() }}
shell: bash
env:
PR_NUMBER: ${{ github.event.number }}
run: |
# Name for companion branch
COMPANION_BRANCH=companion/${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
git branch -D "$COMPANION_BRANCH" || true
git checkout "$COMPANION_BRANCH" || git checkout -B "$COMPANION_BRANCH"
# Find all the files starting with delta-*.png
files_to_add=$(find . -type f -name "delta-*.png")
# Check for invalid file names and add only valid ones
for file in $files_to_add; do
git add -f "$file"
done
# Don't commit any other files
git restore .
# TODO: Use Github app instead of personal access token
git config --global user.name GuardianAndroid
git config --global user.email [email protected]
git commit -m "Add screenshot diff"
git push origin HEAD:"$COMPANION_BRANCH" -f
delimiter="$(openssl rand -hex 8)"
{
echo "reports<<${delimiter}"
# Create markdown table header
echo "**Screenshot tests failed**<br/>${#files_to_add[@]} failures. Please check the failure diffs:"
echo "| Image |"
echo "|-------|"
} >> "$GITHUB_OUTPUT"
# Iterate over the files and create table rows
for file in $files_to_add; do
# Get the file name, strip down to only test class and function name
fileName=$(basename "$file" | sed 's/^[^_]*_//')
echo "| $fileName ![](https://github.com/${{ github.repository }}/blob/$COMPANION_BRANCH/$file?raw=true) |" >> "$GITHUB_OUTPUT"
done
echo "${delimiter}" >> "$GITHUB_OUTPUT"
echo "BRANCH IS ${GITHUB_REF}"
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
# Don't run on merge queue branches
if: ${{ always() && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.ref != 'refs/heads/main' }}
with:
issue-number: ${{ github.event.number }}
comment-author: 'github-actions[bot]'
body-includes: Screenshot tests failed
- name: Add or update comment on PR
uses: peter-evans/create-or-update-comment@v4
# Don't run on merge queue branches, only run if screenshot tests failed and companion branch created
if: ${{ failure() && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.ref != 'refs/heads/main' && steps.screenshot-tests.outcome != 'success' && steps.create-companion-branch.outcome == 'success' }}
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body: ${{ steps.create-companion-branch.outputs.reports }}
edit-mode: replace
- name: Resolve comment on PR
uses: peter-evans/create-or-update-comment@v4
# Don't run on merge queue branches, only run if screenshot tests passed and comment exists
if: ${{ success() && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.ref != 'refs/heads/main' && success() && steps.find-comment.outputs.comment-id != '' }}
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body: |
**Screenshot tests failed**
Errors resolved.
edit-mode: replace
- name: Cleanup outdated companion branches
if: ${{ always() }}
run: |
# Find outdated companion branches with last commit date
git branch -r --format="%(refname:lstrip=3)" | grep companion/ | while read -r branch; do
last_commit_date_timestamp=$(git log -1 --format=%ct "origin/$branch")
now_timestamp=$(date +%s)
echo "branch: $branch now_timestamp: $now_timestamp last_commit_date_timestamp: $last_commit_date_timestamp"
# For testing purpose, delete branch if it's older than 1 second
# if [ $((now_timestamp - last_commit_date_timestamp)) -gt 1 ]; then
# Delete branch if it's older than 1 month
if [ $((now_timestamp - last_commit_date_timestamp)) -gt 2592000 ]; then
echo "Deleting $branch"
git push origin --delete "$branch"
fi
done