diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a3482e3d..e315354f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,6 +9,7 @@ permissions: pages: write id-token: write deployments: write + jobs: build: runs-on: macos-latest @@ -61,7 +62,7 @@ jobs: path: playwright-report/ retention-days: 30 - if: ${{ failure() && steps.screenshot_tests.conclusion == 'failure' }} - run: npm run test.int -- --grep @screenshots --update-snapshots + run: npm run test.int -- --grep @screenshots --update-snapshots --last-failed - if: ${{ failure() && steps.screenshot_tests.conclusion == 'failure' }} name: Upload screens uses: actions/upload-artifact@v4 diff --git a/.github/workflows/update-snapshots.yml b/.github/workflows/update-snapshots.yml index 74dfdd27..1eca9d60 100644 --- a/.github/workflows/update-snapshots.yml +++ b/.github/workflows/update-snapshots.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: pr_number: - description: 'Pull Request Number' + description: 'Pull Request Number (Warning: This action will push a commit to the referenced PR)' required: true type: string @@ -17,25 +17,59 @@ jobs: name: Update PR Snapshots runs-on: macos-latest steps: - - name: Checkout PR + - uses: actions/checkout@v3 + - name: Checkout PR ${{ github.event.inputs.pr_number }} if: github.event_name == 'workflow_dispatch' run: gh pr checkout ${{ github.event.inputs.pr_number }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Run command - if: github.event_name == 'workflow_dispatch' + - name: Use Node.js from .nvmrc + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + + - name: Cache node modules + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + run: npm ci + + - name: Build all + run: npm run build && npm run build.debug + + - name: Fetch fonts + run: npm run fetch-fonts + + - name: Install Playwright Browsers + run: npx playwright install --with-deps + + - name: Run Screenshot tests + id: screenshot_tests + run: npm run test.int -- screenshots.js --grep @screenshots + + - if: ${{ failure() && steps.screenshot_tests.conclusion == 'success' }} + run: | + echo "nothing to update - tests all passed" + + - name: Re-Running Playwright to update snapshots + id: screenshot_tests_update + if: ${{ failure() && steps.screenshot_tests.conclusion == 'failure' }} + run: npm run test.int -- screenshots.js --grep @screenshots --update-snapshots --last-failed + + - name: Commit the updated files to the PR branch + if: ${{ failure() && steps.screenshot_tests_update.conclusion == 'success' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - echo "Running A command here command..." - - # Step 5: Commit and push changes back to the PR branch - -# - name: Commit and push changes -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# run: | -# git config user.name "github-actions[bot]" -# git config user.email "github-actions[bot]@users.noreply.github.com" -# git add . -# git commit -m "Automated updates from GitHub Actions" -# git push origin ${{ env.PR_BRANCH }} + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add integration-tests/* + git commit -m "Updated snapshots via workflow" + git push origin HEAD diff --git a/.gitignore b/.gitignore index 59d9235e..a5b6208b 100755 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ build/ build/app_backup bslive.yml .vscode +/json-reports \ No newline at end of file