diff --git a/.github/workflows/playwright_tests.yml b/.github/workflows/playwright_tests.yml index f439fb7a4ae3..ad8a3a2685e0 100644 --- a/.github/workflows/playwright_tests.yml +++ b/.github/workflows/playwright_tests.yml @@ -416,8 +416,10 @@ jobs: path: ${{ github.workspace }}/playwright-report if-no-files-found: error + # The steps below do not need the HTML report, so they also run after a step above fails: an `if` + # without a status function such as !cancelled() gets an implicit success(). - name: Merge test traces - if: steps.mergeable-artifacts.outputs.traces == 'true' + if: ${{ !cancelled() && steps.mergeable-artifacts.outputs.traces == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -427,7 +429,7 @@ jobs: delete-merged: true - name: Merge etalons - if: steps.mergeable-artifacts.outputs.etalons == 'true' + if: ${{ !cancelled() && steps.mergeable-artifacts.outputs.etalons == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -436,7 +438,8 @@ jobs: delete-merged: true - name: Download flaky test reports - if: steps.mergeable-artifacts.outputs.flaky == 'true' + id: download-flaky-reports + if: ${{ !cancelled() && steps.mergeable-artifacts.outputs.flaky == 'true' }} uses: actions/download-artifact@v7 with: pattern: playwright-flaky-report-* @@ -444,7 +447,8 @@ jobs: # The file tools/flaky-test-reporter collects from every run of this workflow (repository-check.yml). - name: Build flaky candidates report - if: steps.mergeable-artifacts.outputs.flaky == 'true' + id: build-flaky-candidates + if: ${{ !cancelled() && steps.download-flaky-reports.outcome == 'success' }} run: | mkdir -p artifacts report=artifacts/flaky-candidates.json @@ -465,7 +469,7 @@ jobs: } >> "$GITHUB_STEP_SUMMARY" - name: Upload flaky candidates report - if: steps.mergeable-artifacts.outputs.flaky == 'true' + if: ${{ !cancelled() && steps.build-flaky-candidates.outcome == 'success' }} uses: actions/upload-artifact@v7 with: name: flaky-candidates diff --git a/.github/workflows/repository-check.yml b/.github/workflows/repository-check.yml index 6ea1d2e9597b..9cf8faadf1ec 100644 --- a/.github/workflows/repository-check.yml +++ b/.github/workflows/repository-check.yml @@ -46,37 +46,55 @@ jobs: run: | # tee opens the log before the tool runs, so the directory must already exist. mkdir -p "$GITHUB_WORKSPACE/artifacts" - report="$GITHUB_WORKSPACE/artifacts/flaky-tests-report.json" - markdown="$GITHUB_WORKSPACE/artifacts/flaky-tests-report.md" - log="$GITHUB_WORKSPACE/artifacts/collect.log" - # --silent keeps pnpm's own banner out of the summary; 2>&1 keeps the tool's warnings in. - # tee stores the plain text for the summary, then sed turns the tool's warnings into - # GitHub annotations so they surface on the run page. - pnpm --silent --filter flaky-test-reporter run collect -- \ - --repo "${{ github.repository }}" \ - --workflow playwright_tests.yml \ - --artifact flaky-candidates \ - --branch "${{ github.ref_name }}" \ - --window-hours "$WINDOW_HOURS" \ - --out-json "$report" \ - --out-markdown "$markdown" 2>&1 \ - | tee "$log" \ - | sed -e 's/^warning: /::warning::/' -e 's/^Collection failed: /::error::/' + # One report per workflow. The suffix names its files, the label its summary section, and + # the rest of the arguments go to the tool. + collect_flaky() { + suffix="$1" + label="$2" + shift 2 + log="$GITHUB_WORKSPACE/artifacts/collect$suffix.log" - { - echo "## Flaky test candidates" - echo "" - echo '```' - cat "$log" - echo '```' - } >> "$GITHUB_STEP_SUMMARY" + # --silent keeps pnpm's own banner out of the summary; 2>&1 keeps the tool's warnings in. + # tee stores the plain text for the summary, then sed turns the tool's warnings into + # GitHub annotations so they surface on the run page. + pnpm --silent --filter flaky-test-reporter run collect -- \ + --repo "${{ github.repository }}" \ + --artifact flaky-candidates \ + --branch "${{ github.ref_name }}" \ + --window-hours "$WINDOW_HOURS" \ + --out-json "$GITHUB_WORKSPACE/artifacts/flaky-tests-report$suffix.json" \ + --out-markdown "$GITHUB_WORKSPACE/artifacts/flaky-tests-report$suffix.md" \ + "$@" 2>&1 \ + | tee "$log" \ + | sed -e 's/^warning: /::warning::/' -e 's/^Collection failed: /::error::/' + + { + echo "## Flaky test candidates: $label" + echo "" + echo '```' + cat "$log" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + } + + # Both reports go into one issue body after the monitor's own sections, and GitHub caps the + # body at 65,536 characters: each report gets a share of it, the demos a smaller one. + collect_flaky "" "component tests" --workflow playwright_tests.yml --max-chars 36000 + collect_flaky "-demos" "demos" --workflow visual-tests-demos.yml \ + --title "Flaky Test Candidates (Demos)" --max-tests 10 --max-chars 18000 # Multiline output form, so the markdown crosses the job boundary as-is. The delimiter # must not occur in the content, which markdown headings and tables never produce. + # A report the tool did not write leaves out its section only. { echo 'details<> "$GITHUB_OUTPUT" @@ -88,6 +106,8 @@ jobs: path: | ${{ github.workspace }}/artifacts/flaky-tests-report.json ${{ github.workspace }}/artifacts/collect.log + ${{ github.workspace }}/artifacts/flaky-tests-report-demos.json + ${{ github.workspace }}/artifacts/collect-demos.log retention-days: 7 if-no-files-found: ignore diff --git a/.github/workflows/visual-tests-demos.yml b/.github/workflows/visual-tests-demos.yml index 1861d3044f07..9db7bd8b5b33 100644 --- a/.github/workflows/visual-tests-demos.yml +++ b/.github/workflows/visual-tests-demos.yml @@ -523,6 +523,9 @@ jobs: # The default blob name is built from the test paths only, so jobs that differ by theme or # shard alone would write the same zip and overwrite each other once merged. PLAYWRIGHT_BLOB_OUTPUT_NAME: report-${{ env.PLAYWRIGHT_JOB_NAME }}.zip + # tools/playwright/flakyReporter.ts stamps every flaky test it records with the job it ran in. + FLAKY_REPORT_JOB: ${{ matrix.CONSTEL }}-${{ matrix.STRATEGY }}-${{ matrix.THEME }} + FLAKY_REPORT_BASE_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref || github.ref_name }} run: pnpm run test-playwright - name: Run Playwright accessibility tests (jQuery) @@ -566,6 +569,15 @@ jobs: path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/test-results if-no-files-found: ignore + - name: Upload flaky test report + if: always() && matrix.STRATEGY == 'screenshots' + uses: actions/upload-artifact@v7 + with: + name: playwright-flaky-report-${{ env.PLAYWRIGHT_JOB_NAME }} + path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/flaky-report.json + retention-days: 1 + if-no-files-found: ignore + # One folder at repository paths: the new etalons the tests wrote, and the etalons of the failed # shots that tools/playwright/etalonCollector.ts collected. - name: Collect etalons @@ -743,6 +755,9 @@ jobs: # The default blob name is built from the test paths only, so jobs that differ by theme or # shard alone would write the same zip and overwrite each other once merged. PLAYWRIGHT_BLOB_OUTPUT_NAME: report-${{ env.PLAYWRIGHT_JOB_NAME }}.zip + # tools/playwright/flakyReporter.ts stamps every flaky test it records with the job it ran in. + FLAKY_REPORT_JOB: ${{ matrix.CONSTEL }}-screenshots-${{ matrix.THEME }} + FLAKY_REPORT_BASE_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref || github.ref_name }} run: pnpm run test-playwright # A test that writes a missing etalon passes (updateSnapshots: 'missing'), so this step fails the job @@ -775,6 +790,15 @@ jobs: path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/test-results if-no-files-found: ignore + - name: Upload flaky test report + if: always() + uses: actions/upload-artifact@v7 + with: + name: playwright-flaky-report-${{ env.PLAYWRIGHT_JOB_NAME }} + path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/flaky-report.json + retention-days: 1 + if-no-files-found: ignore + # One folder at repository paths: the new etalons the tests wrote, and the etalons of the failed # shots that tools/playwright/etalonCollector.ts collected. - name: Collect etalons @@ -820,6 +844,7 @@ jobs: etalons_react: /^playwright-etalons-react\(/, etalons_vue: /^playwright-etalons-vue\(/, etalons_angular: /^playwright-etalons-angular\(/, + flaky: /^playwright-flaky-report-/, }; for (const [outputName, pattern] of Object.entries(artifactGroups)) { @@ -873,8 +898,10 @@ jobs: path: ${{ github.workspace }}/playwright-report if-no-files-found: error + # The steps below do not need the HTML report, so they also run after a step above fails: an `if` + # without a status function such as !cancelled() gets an implicit success(). - name: Merge Playwright traces - if: steps.playwright-artifacts.outputs.traces == 'true' + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.traces == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -886,7 +913,7 @@ jobs: # One etalon serves every framework of a demo, so each framework gets its own artifact: merged # together, a framework that renders differently would overwrite another's picture. - name: Merge jQuery etalons - if: steps.playwright-artifacts.outputs.etalons_jquery == 'true' + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.etalons_jquery == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -895,7 +922,7 @@ jobs: delete-merged: true - name: Merge React etalons - if: steps.playwright-artifacts.outputs.etalons_react == 'true' + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.etalons_react == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -904,7 +931,7 @@ jobs: delete-merged: true - name: Merge Vue etalons - if: steps.playwright-artifacts.outputs.etalons_vue == 'true' + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.etalons_vue == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -913,7 +940,7 @@ jobs: delete-merged: true - name: Merge Angular etalons - if: steps.playwright-artifacts.outputs.etalons_angular == 'true' + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.etalons_angular == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -921,8 +948,48 @@ jobs: pattern: playwright-etalons-angular(* delete-merged: true + - name: Download flaky test reports + id: download-flaky-reports + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.flaky == 'true' }} + uses: actions/download-artifact@v8 + with: + pattern: playwright-flaky-report-* + path: ${{ github.workspace }}/flaky-reports + + # The file tools/flaky-test-reporter collects from every run of this workflow (repository-check.yml). + - name: Build flaky candidates report + id: build-flaky-candidates + if: ${{ !cancelled() && steps.download-flaky-reports.outcome == 'success' }} + run: | + mkdir -p artifacts + report=artifacts/flaky-candidates.json + find flaky-reports -type f -name flaky-report.json -print0 \ + | xargs -0 jq -s '{ schemaVersion: 1, candidates: (map(.candidates) | add) }' \ + > "$report" + + { + echo "## Flaky tests" + echo "" + if [ "$(jq '.candidates | length' "$report")" -eq 0 ]; then + echo "_none_" + else + echo "| Test | Job |" + echo "|---|---|" + jq -r '.candidates[] | "| \(.test | gsub("\\|"; "\\|")) | \(.sourceJob) |"' "$report" + fi + } >> "$GITHUB_STEP_SUMMARY" + + - name: Upload flaky candidates report + if: ${{ !cancelled() && steps.build-flaky-candidates.outcome == 'success' }} + uses: actions/upload-artifact@v7 + with: + name: flaky-candidates + path: ${{ github.workspace }}/artifacts/flaky-candidates.json + retention-days: 7 + if-no-files-found: ignore + - name: Merge jQuery accessibility reports - if: needs.playwright-jquery.result == 'failure' + if: ${{ !cancelled() && needs.playwright-jquery.result == 'failure' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: diff --git a/apps/demos/README.md b/apps/demos/README.md index 3b8692987543..9d2ddf77ff8c 100644 --- a/apps/demos/README.md +++ b/apps/demos/README.md @@ -195,7 +195,7 @@ gh run download -n playwright-traces -D ci-traces pnpm exec playwright show-report ci-report ``` -A failed comparison uploads its `-expected`, `-actual` and `-diff` images with the trace. On CI a failed test runs once more; a test that passes then is listed under "flaky" and does not fail the job. +A failed comparison uploads its `-expected`, `-actual` and `-diff` images with the trace. On CI a failed test runs once more; a test that passes then is listed under "flaky" and does not fail the job. It is not forgotten either: the job marks it with a "Flaky test" warning, the run lists the flaky tests of every job in its summary and keeps them in its `flaky-candidates` artifact, and `repository-check.yml` adds those up over 72 hours in the repository monitor issue, in a section of its own ("Flaky tests" in `e2e/playwright/README.md` describes the same for the component tests). ## Accessibility Tests diff --git a/apps/demos/playwright.config.ts b/apps/demos/playwright.config.ts index 28f2cee5e900..3e97b38ed9cb 100644 --- a/apps/demos/playwright.config.ts +++ b/apps/demos/playwright.config.ts @@ -59,10 +59,15 @@ export default defineConfig({ ? [ ['list'], ['blob', { outputDir: './testing/artifacts/playwright/blob-report' }], + // Before the flaky reporter: its annotations share the step's limit of 10 warnings. ['../../tools/playwright/etalonCollector.ts', { outputDir: './testing/artifacts/playwright/collected-etalons', repositoryRoot: '../..', }], + ['../../tools/playwright/flakyReporter.ts', { + outputFile: './testing/artifacts/playwright/flaky-report.json', + defaultTheme: THEME, + }], ] : [['list']], timeout: 60000, diff --git a/tools/flaky-test-reporter/src/main.test.ts b/tools/flaky-test-reporter/src/main.test.ts index 55b38066c365..b8d4740aa19e 100644 --- a/tools/flaky-test-reporter/src/main.test.ts +++ b/tools/flaky-test-reporter/src/main.test.ts @@ -30,6 +30,19 @@ describe('parseArgs', () => { }); }); + it('keeps the default heading and test cap unless given', () => { + expect(parseArgs(flags)).toMatchObject({ title: 'Flaky Test Candidates', maxTests: 20 }); + expect(parseArgs([...flags, '--title', 'Demos', '--max-tests', '10'])).toMatchObject({ + title: 'Demos', + maxTests: 10, + }); + }); + + it('leaves the report length open unless given', () => { + expect(parseArgs(flags).maxChars).toBeUndefined(); + expect(parseArgs([...flags, '--max-chars', '18000'])).toMatchObject({ maxChars: 18000 }); + }); + it('parses identically when invoked through `pnpm run