Skip to content

Commit 1ff0c0c

Browse files
authored
Create main.yml
1 parent 37d6de2 commit 1ff0c0c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

.github/workflows/main.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Node.js CI with PR Comment
2+
3+
on:
4+
pull_request:
5+
branches: [ '**' ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [14.x, 16.x, 18.x]
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
21+
- name: Install dependencies
22+
run: yarn install
23+
24+
- name: Run tests and capture output
25+
run: |
26+
mkdir -p test_results
27+
yarn run test > test_results/results.txt 2>&1
28+
29+
- name: Post PR Comment with Test Results
30+
uses: actions/github-script@v5
31+
if: github.event_name == 'pull_request'
32+
with:
33+
github-token: ${{secrets.GITHUB_TOKEN}}
34+
script: |
35+
const fs = require('fs');
36+
const path = 'test_results/results.txt';
37+
const testResults = fs.readFileSync(path, { encoding: 'utf8' });
38+
const commentBody = `🚀 Test Results:\n\`\`\`\n${testResults}\n\`\`\``;
39+
github.rest.issues.createComment({
40+
...context.repo,
41+
issue_number: context.issue.number,
42+
body: commentBody
43+
});
44+
45+
- name: Archive test results
46+
if: success()
47+
uses: actions/upload-artifact@v2
48+
with:
49+
name: test-results
50+
path: |
51+
test_results/

0 commit comments

Comments
 (0)