From 051910129c92d9a634b8c6ed44865adcd56c4e2d Mon Sep 17 00:00:00 2001 From: James Amner Date: Sun, 8 Oct 2023 15:34:32 +0100 Subject: [PATCH] [FEATURE] Snapshots Rework --- .github/workflows/test.yml | 18 ++--------- .github/workflows/update-snapshots.yml | 44 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/update-snapshots.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a10819b5..77a0d193 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,22 +43,10 @@ jobs: require_tests: false job_name: ${{ matrix.playwright }} Results - name: Update Snapshots + uses: ./.github/actions/update-snapshots if: ${{ always() && contains(steps.tests.outcome, 'failure') }} - run: npx playwright test --project=${{ matrix.playwright }} --update-snapshots - - name: Create pr - if : ${{ always() && contains(steps.tests.outcome, 'failure') }} - run: | - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git config --global user.name "github-actions[bot]" - git config --global push.autoSetupRemote true - git checkout -b $BRANCH_NAME - git add . - git commit -m "Update Snapshots for ${{ matrix.playwright }}" - git push origin - gh pr create --title "Update Snapshots" --body "Automated update of snapshots for ${{ matrix.playwright }}" --base ${{ github.event.pull_request.head.ref }} --head $BRANCH_NAME --label "snapshots" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BRANCH_NAME: update-snapshots/${{ matrix.playwright}}/${{ github.sha }} + with: + base-branch: ${{ github.event.pull_request.base.ref }} report: name: Report Test Results runs-on: ubuntu-latest diff --git a/.github/workflows/update-snapshots.yml b/.github/workflows/update-snapshots.yml new file mode 100644 index 00000000..81e75a9e --- /dev/null +++ b/.github/workflows/update-snapshots.yml @@ -0,0 +1,44 @@ +name: Update Snapshots + +on: + workflow_call: + workflows: ["Test"] + inputs: + base-branch: + description: 'The name of the branch to create the PR against' + required: true + type: string + +permissions: + contents: write + pull-requests: write + checks: write + issues: write + +jobs: + update-snapshots: + name: Update Snapshots + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.event.inputs.base-branch }} + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + - name: Install dependencies + run: npm ci && npx playwright install --with-deps + - name: Update Snapshots + run: npx playwright test --update-snapshots + - name: Create Or Update PR + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git checkout -b update-snapshots-${{ github.event.inputs.base-branch }} + git add . + git commit -m "Update snapshots" + git push origin update-snapshots --force + gh pr create --title "Update snapshots" --body "This PR updates the snapshots for the ${{ github.event.inputs.base-branch }} branch" --base ${{ github.event.inputs.base-branch }} --head update-snapshots --repo ${{ github.repository }}