From 79b5d7c34eee51a6e952d9706bb6fcdc88cbe147 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Sat, 9 Nov 2024 11:57:28 -0600 Subject: [PATCH] write to file --- .github/workflows/testing.yml | 24 +++++++++++++ src/utils/processResults.ts | 64 ++++++++++++++++------------------- 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 4dc729a..a88d721 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -83,3 +83,27 @@ jobs: - name: Run Playwright tests run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} continue-on-error: true + + - name: Upload summary artifact + uses: actions/upload-artifact@v2 + with: + name: playwright-summary-${{ matrix.shardIndex }} + path: playwright-summary-${{ matrix.shardIndex }}.md + + e2e-report: + runs-on: ubuntu-latest + needs: [testing-matrix] + steps: + - name: Download all summaries + uses: actions/download-artifact@v4 + with: + name: playwright-summary-* + path: combined-summaries + + - name: Combine summaries + run: | + cat combined-summaries/playwright-summary-shard-*.md > combined-summaries/combined-summary.md + + - name: Post combined summary to GitHub + run: | + cat combined-summaries/combined-summary.md >> $GITHUB_STEP_SUMMARY diff --git a/src/utils/processResults.ts b/src/utils/processResults.ts index 895e913..e65bc70 100644 --- a/src/utils/processResults.ts +++ b/src/utils/processResults.ts @@ -1,5 +1,3 @@ -import * as core from "@actions/core"; -import { SUMMARY_ENV_VAR } from "@actions/core/lib/summary"; import { Suite } from "@playwright/test/reporter"; import { existsSync, unlinkSync, writeFileSync } from "fs"; import { basename, join } from "path"; @@ -16,36 +14,32 @@ export const processResults = async ( suite: Suite | undefined, options: GitHubActionOptions ) => { - if (process.env.NODE_ENV === "development") { - const summaryFile = join(__dirname, "../../summary.html"); - if (existsSync(summaryFile)) { - unlinkSync(summaryFile); - } - writeFileSync(summaryFile, "", "utf-8"); - process.env[SUMMARY_ENV_VAR] = summaryFile; - process.env.GITHUB_ACTIONS = "true"; - } - if (process.env.GITHUB_ACTIONS && suite) { const os = process.platform; - const summary = core.summary; + + // Generate a unique summary file path using matrix.shardIndex + const shardIndex = process.env.SHARD_INDEX || "default"; + const summaryFilePath = join( + process.cwd(), + `playwright-summary-${shardIndex}.md` + ); + + if (existsSync(summaryFilePath)) { + unlinkSync(summaryFilePath); + } + + let summaryContent = ""; const summaryTitle = getSummaryTitle(options.title); if (summaryTitle) { - summary.addHeading(summaryTitle, 1); + summaryContent += `# ${summaryTitle}\n\n`; } - console.log(summaryTitle); const headerText = getSummaryDetails(suite); - summary.addRaw(headerText.join(`  |  `)); - - // if (options.useDetails) { - // summary.addSeparator(); - // } + summaryContent += headerText.join(`  |  `) + "\n\n"; - for (const crntSuite of suite?.suites) { + for (const crntSuite of suite.suites) { const project = crntSuite.project(); - const tests = getTestsPerFile(crntSuite); for (const filePath of Object.keys(tests)) { @@ -60,17 +54,14 @@ export const processResults = async ( options.includeResults as DisplayLevel[] ); - if (!content) { - continue; + if (content) { + const testStatusIcon = getSuiteStatusIcon(tests[filePath]); + summaryContent += `
${testStatusIcon} ${getTestHeading( + fileName, + os, + project + )}\n\n${content}\n\n
\n\n`; } - - // Check if there are any failed tests - const testStatusIcon = getSuiteStatusIcon(tests[filePath]); - - summary.addDetails( - `${testStatusIcon} ${getTestHeading(fileName, os, project)}`, - content - ); } else { const tableRows = await getTableRows( tests[filePath], @@ -81,13 +72,16 @@ export const processResults = async ( ); if (tableRows.length !== 0) { - summary.addHeading(getTestHeading(fileName, os, project), 2); - summary.addTable(tableRows); + summaryContent += `## ${getTestHeading(fileName, os, project)}\n\n`; + summaryContent += + "| Test | Result | Details |\n| --- | --- | --- |\n"; + summaryContent += + tableRows.map((row) => row.join(" | ")).join("\n") + "\n\n"; } } } } - await summary.write(); + writeFileSync(summaryFilePath, summaryContent, "utf-8"); } };