Skip to content

Commit c288c84

Browse files
committed
ci: including the jest tests report on a comment on the active PR
1 parent 149c3fb commit c288c84

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

.github/workflows/actions-scripts-tests.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,36 @@ jobs:
2727
- name: Install dependencies
2828
run: npm ci
2929

30-
# Run tests and collect coverage
31-
- name: Run tests and generate coverage
32-
run: npm test
30+
# Run tests and capture output
31+
- name: Run tests
32+
id: run_tests
33+
run: |
34+
{
35+
echo 'tests_report<<EOF'
36+
npm test 2>&1
37+
echo EOF
38+
} >> "$GITHUB_OUTPUT"
39+
40+
# Post comment on PR
41+
- name: Add JEST results as a PR comment
42+
uses: actions/github-script@v7
43+
with:
44+
script: |
45+
const steps = ${{ toJSON(steps) }};
46+
const marker = 'to show where the warning was created)';
47+
const output = steps.run_tests.outputs.tests_report;
48+
const sanitized = output.split(marker);
49+
const msg = (sanitized.length > 1) ? sanitized[1] : sanitized[0];
50+
51+
const prNumber = context.payload.issue.number;
52+
53+
if (sanitized.length >= 1) {
54+
github.rest.issues.createComment({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
issue_number: prNumber,
58+
body: msg,
59+
});
60+
} else {
61+
core.setFailed('No tests report data available.')
62+
}

0 commit comments

Comments
 (0)