Skip to content

Commit

Permalink
use actions summary
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 4, 2024
1 parent d9f4bd0 commit 51867e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
39 changes: 23 additions & 16 deletions github-actions-summary/github-actions-summary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';
import path from 'path';
import EC from 'eight-colors';
import { summary } from '@actions/core';

export default (reportData, helper) => {

Expand All @@ -11,27 +12,31 @@ export default (reportData, helper) => {
});
}

const summaryFile = path.resolve(summaryDir, 'test-summary.md');
const summaryFile = path.resolve(summaryDir, 'summary.html');
fs.writeFileSync(summaryFile, '');
process.env.GITHUB_STEP_SUMMARY = summaryFile;
process.env.GITHUB_ACTIONS = 'true';

const {
name, dateH, durationH, summary
} = reportData;

const lines = [`## ${name}`, `> ${dateH} (${durationH})`];
summary.addHeading(reportData.name, '2');
summary.addRaw(`> ${reportData.dateH} (${reportData.durationH})`);
summary.addEOL();

const rows = [];
['tests', 'passed', 'flaky', 'skipped', 'failed'].forEach((k) => {
const item = summary[k];
const item = reportData.summary[k];
const percent = item.percent ? ` (${item.percent})` : '';
lines.push(`- **${item.name}** ${item.value} ${percent}`);
rows.push([{
data: item.name
}, {
data: item.value
}, {
data: percent
}]);
});
summary.addTable(rows);

lines.push('\n ');

if (summary.passed.value === summary.tests.value) {
lines.push('✔ Congratulations! All tests passed.');
} else if (summary.failed.value > 0) {
if (reportData.summary.passed.value === reportData.summary.tests.value) {
summary.addRaw('✔ Congratulations! All tests passed.');
} else if (reportData.summary.failed.value > 0) {
// @owners of all failed cases
const owners = [];
helper.forEach((item) => {
Expand All @@ -40,11 +45,13 @@ export default (reportData, helper) => {
}
});
if (owners.length) {
lines.push(`Hey ${owners.join(' ')}, please fix the failed cases and run test again.`);
summary.addRaw(`Hey ${owners.join(' ')}, please fix the failed cases and run test again.`);
}
}

fs.writeFileSync(summaryFile, lines.join('\n'));
summary.write({
overwrite: true
});

EC.logGreen('[github-actions-summary] completed');

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"type": "git",
"url": "git+https://github.com/cenfun/playwright-reporter-integrations.git"
},
"dependencies": {},
"devDependencies": {
"@actions/core": "^1.10.1",
"@playwright/test": "^1.45.1",
"@slack/web-api": "^7.3.0",
"@slack/webhook": "^7.0.2",
Expand All @@ -30,4 +30,4 @@
"qaseio": "^2.1.4",
"testrail-api": "^1.3.6"
}
}
}

0 comments on commit 51867e2

Please sign in to comment.