diff --git a/.github/workflows/selenium-lab-tests.yaml b/.github/workflows/selenium-lab-tests.yaml index a5cbf02a84..cb65f49d45 100644 --- a/.github/workflows/selenium-lab-tests.yaml +++ b/.github/workflows/selenium-lab-tests.yaml @@ -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 * * *' @@ -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 \ diff --git a/.github/workflows/update-screenshots.yaml b/.github/workflows/update-screenshots.yaml new file mode 100644 index 0000000000..1b218f242e --- /dev/null +++ b/.github/workflows/update-screenshots.yaml @@ -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/action-tmate@v3.6 + with: + limit-access-to-actor: true + if: failure()