Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Experimental workflow to update screenshots in a PR #4991

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/selenium-lab-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ on:
test_filter:
description: "A filter to run a subset of the tests. If empty, all tests will run."
required: false
workflow_call:
# Allows for reuse from other workflows, such as "Update All Screenshots"
# workflow.
inputs:
pr:
description: "A PR number to build and test in the lab. If empty, will build and test from main."
required: false
test_filter:
description: "A filter to run a subset of the tests. If empty, all tests will run."
required: false
ignore_test_status:
description: "If true, ignore test failures and treat the workflow as a success."
schedule:
# Runs every night at 2am PST / 10am UTC, testing against the main branch.
- cron: '0 10 * * *'
Expand Down Expand Up @@ -199,6 +211,11 @@ jobs:
extra_flags="$extra_flags --filter $filter"
fi

ignore_test_status="${{ github.event.inputs.ignore_test_status }}"
if [[ "$ignore_test_status" == "true" ]]; then
extra_flags="$extra_flags || true"
fi

python3 build/test.py \
--no-build \
--reporters spec --spec-hide-passed \
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/update-screenshots.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Update All Screenshots
# Updates all screenshots on an existing PR, assuming permission has been given
# to maintainers to make edits.

on:
workflow_dispatch:
# Allows for manual triggering on PRs. They should be reviewed first, to
# avoid malicious code executing in the lab.
inputs:
pr:
description: "A PR number to build and test in the lab, then update all the screenshots."
required: true

jobs:
run-lab-tests:
name: Get Selenium Lab Screenshots
uses: ./.github/workflows/selenium-lab-tests.yaml
with:
pr: ${{ github.event.inputs.pr }}
test_filter: 'layout'
ignore_test_status: true

update-pr:
name: Update PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: refs/pull/${{ github.event.inputs.pr }}/head

- name: Get artifacts
uses: actions/download-artifact@v3

- name: Update screenshots
run: |
# Unpack screenshots from the lab.
for i in screenshots-*.zip; do
unzip -d test/test/assets/screenshots/ "$i"
done

# Update the official screenshots for any that has visibly changed.
# This is not a byte-for-byte comparison.
./build/updateScreenshots.py

# Emulate the actions bot.
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

# Update the PR.
git add test/test/assets/screenshots/*/*.png
git commit -m ':robot: Update all screenshots'

PR_API_URL="/repos/${{ github.repository }}/pulls/${{ github.event.inputs.pr }}"
REMOTE=$(gh api $GH_API_URL | jq -r .head.repo.html_url)
BRANCH=$(gh api $GH_API_URL | jq -r .head.ref)

git push "$REMOTE" "$BRANCH"

- name: Debug
uses: mxschmitt/[email protected]
with:
limit-access-to-actor: true
if: failure()