Skip to content

Commit

Permalink
ci: experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
gbotrel committed Oct 11, 2023
1 parent c4621da commit a26092f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 53 deletions.
64 changes: 14 additions & 50 deletions .github/parse-tests.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,25 @@
const readline = require("readline");
const readline = require('readline');

// Create readline interface
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
terminal: false
});

const summary = { fail: [], pass: [], skip: [] };
let content = '';

rl.on("line", (line) => {
const output = JSON.parse(line);
if (
output.Action === "pass" ||
output.Action === "skip" ||
output.Action === "fail"
) {
if (output.Test) {
summary[output.Action].push(output);
}
}
// Read stdin content
rl.on('line', (line) => {
content += line + '\n';
});

rl.on('close', () => {
// Escape special characters
const escapedContent = content.replace(/`/g, '\\`').replace(/"/g, '\\"').replace(/\n/g, '\\n');

rl.on("close", () => {
console.log("## Summary");
console.log("\n");
// console.log("| | # of Tests |");
// console.log("|--|--|");
console.log(
"✅ Passed: %d",
summary.pass.length
);
console.log(
"❌ Failed: %d",
summary.fail.length
);
console.log(
"🚧 Skipped: %d",
summary.skip.length
);

if (summary.fail.length > 0) {
console.log("\n## ❌ Failures\n");
}

summary.fail.forEach((test) => {
console.log("* `%s` (%s)", test.Test, test.Package);
});

// also display skipped tests.
if (summary.skip.length > 0) {
console.log("\n## 🚧 Skipped\n");
}

summary.skip.forEach((test) => {
console.log("* `%s` (%s)", test.Test, test.Package);
});

});
// Convert the JSON object to a string
const jsonStr = JSON.stringify(escapedContent);

console.log(jsonStr);
});
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ jobs:
if: ${{ always() }}
run: |
if [ -s /tmp/gotest.log ]; then
echo "::set-output name=failures::$(cat /tmp/gotest.log)"
cat /tmp/gotest.log > $GITHUB_STEP_SUMMARY
echo "failures=$(cat /tmp/gotest.log | node .github/parse-tests.js)" > $GITHUB_OUTPUT
else
echo "::set-output name=failures::"
echo "## Success ✅" > $GITHUB_STEP_SUMMARY
echo "failures=" > $GITHUB_OUTPUT
fi
# if we failed a test, we want to comment on the PR with the log
- name: PR comment with file
if: ${{ always() }} && steps.generate-job-summary.outputs.failures != ''
Expand Down

0 comments on commit a26092f

Please sign in to comment.