From ff1429ba7a6b3324a7a872a5893a71446023bcf3 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 26 Apr 2022 04:02:48 +0545 Subject: [PATCH] chore(ci): fix update screenshot action to account for existing screenshot (#25190) --- .../actions/test-core-screenshot/action.yml | 35 +++++++++++++++++-- .../update-reference-screenshots/action.yml | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.github/workflows/actions/test-core-screenshot/action.yml b/.github/workflows/actions/test-core-screenshot/action.yml index f5628b933b4..6593fa7f083 100644 --- a/.github/workflows/actions/test-core-screenshot/action.yml +++ b/.github/workflows/actions/test-core-screenshot/action.yml @@ -41,10 +41,41 @@ runs: shell: bash working-directory: ./core - name: Test and Update + id: test-and-update if: inputs.update == 'true' - run: npx playwright test --shard=${{ inputs.shard }}/${{ inputs.totalShards }} --update-snapshots + # Keep track of the files that were + # changed so they can be correctly restored + # in the combine step. + # To do this, we move only the changed files + # to a separate directory, while preserving the + # directory structure of the source. + # When, we create and archive of these results + # so that the combine step can simply + # unzip and move the changed files into place. + # We have extra logic added so that job runners + # that do not have any new screenshots do not create + # an unnecessary .zip. + # Note that we need to unzip directory to be "core" + # which is why we not using the upload-archive + # composite step here. + run: | + npx playwright test --shard=${{ inputs.shard }}/${{ inputs.totalShards }} --update-snapshots + git add src/\*.png --force + mkdir updated-screenshots + cd ../ && rsync -R --progress $(git diff --name-only --cached) core/updated-screenshots + if [ -d core/updated-screenshots/core ]; then + echo "::set-output name=hasUpdatedScreenshots::$(echo 'true')" + cd core/updated-screenshots + zip -q -r ../../UpdatedScreenshots-${{ inputs.shard }}-${{ inputs.totalShards }}.zip core + fi shell: bash working-directory: ./core + - name: Archive Updated Screenshots + if: inputs.update == 'true' && steps.test-and-update.outputs.hasUpdatedScreenshots == 'true' + uses: actions/upload-artifact@v2 + with: + name: updated-screenshots-${{ inputs.shard }}-${{ inputs.totalShards }} + path: UpdatedScreenshots-${{ inputs.shard }}-${{ inputs.totalShards }}.zip - name: Archive Test Results # The always() ensures that this step # runs even if the previous step fails. @@ -57,4 +88,4 @@ runs: with: name: test-results-${{ inputs.shard }}-${{ inputs.totalShards }} output: core/TestResults-${{ inputs.shard }}-${{ inputs.totalShards }}.zip - paths: core/playwright-report core/src + paths: core/playwright-report diff --git a/.github/workflows/actions/update-reference-screenshots/action.yml b/.github/workflows/actions/update-reference-screenshots/action.yml index 2573e1175b8..4da754282d0 100644 --- a/.github/workflows/actions/update-reference-screenshots/action.yml +++ b/.github/workflows/actions/update-reference-screenshots/action.yml @@ -18,7 +18,7 @@ runs: # directory, including nested directories. # It then unzips every .zip to the root directory run: | - find . -type f -name '*.zip' -exec unzip -q -o -d ../ -- '{}' -x '*.zip' \; + find . -type f -name 'UpdatedScreenshots-*.zip' -exec unzip -q -o -d ../ {} \; shell: bash working-directory: ./artifacts - name: Push Screenshots