-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (117 loc) · 3.9 KB
/
ci.yml
File metadata and controls
130 lines (117 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: CI
on:
push:
branches: [main]
paths:
- 'packages/**'
- 'knowledge/**'
- '.github/workflows/ci.yml'
- 'package.json'
- 'tsconfig.base.json'
pull_request:
branches: [main]
paths:
- 'packages/**'
- 'knowledge/**'
- '.github/workflows/ci.yml'
- 'package.json'
- 'tsconfig.base.json'
jobs:
ci:
runs-on: ubuntu-latest
permissions:
pull-requests: write
strategy:
matrix:
node-version: [20, 22]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build scorer
run: npm run build --workspace=packages/scorer
- name: Build packages
run: npm run build
- name: Validate knowledge schema
run: node scripts/validate-knowledge.js
continue-on-error: false
- name: Run tests
id: run_tests
continue-on-error: true
run: |
set -o pipefail
npm test -- --run 2>&1 | tee /tmp/test-output.txt
- name: Post test failure comment
if: github.event_name == 'pull_request' && steps.run_tests.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let output = '';
try {
output = fs.readFileSync('/tmp/test-output.txt', 'utf8').slice(0, 4000);
} catch (e) {
output = '(could not read test output)';
}
const body = [
'## ❌ Test Suite Failed — PR cannot be merged',
'',
'### What failed',
'',
'The test suite did not pass on Node.js `${{ matrix.node-version }}`. All tests must pass before this PR can be merged.',
'',
'<details>',
'<summary>Test output (first 4000 characters)</summary>',
'',
'```',
output,
'```',
'',
'</details>',
'',
'### How to fix',
'',
'1. Pull the latest changes from this branch locally.',
'2. Run `npm test -- --run` in the repository root to reproduce the failures.',
'3. Fix the failing tests or the code that causes them to fail.',
'4. Push your fixes — CI will re-run automatically.',
'',
'> **Note:** ALL tests must pass before this PR can be merged.',
].join('\n');
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});
- name: Fail build if tests failed
if: steps.run_tests.outcome == 'failure'
run: exit 1
- name: Score new knowledge entries
if: github.event_name == 'pull_request'
id: score_entries
run: node scripts/score-pr-knowledge.js
continue-on-error: true
- name: Comment PR with knowledge scores
if: github.event_name == 'pull_request' && steps.score_entries.outputs.scores != ''
uses: actions/github-script@v7
with:
script: |
const scores = process.env.KNOWLEDGE_SCORES;
if (scores) {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## Fluently Knowledge Entry Fluency Scores\n\n${scores}`
});
}
env:
KNOWLEDGE_SCORES: ${{ steps.score_entries.outputs.scores }}