-
Notifications
You must be signed in to change notification settings - Fork 730
250 lines (232 loc) · 9.19 KB
/
test.yml
File metadata and controls
250 lines (232 loc) · 9.19 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
pull-requests: read
jobs:
changes:
runs-on: ubuntu-latest
outputs:
run_ci: ${{ steps.filter.outputs.run_ci }}
steps:
- name: Determine whether CI should run
id: filter
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
with:
script: |
const IGNORED_PREFIXES = [
'docs/',
'.agents/',
'.github/ISSUE_TEMPLATE/',
'.github/PULL_REQUEST_TEMPLATE/',
'.github/codex/',
'.husky/',
'integration-tests/',
];
const isIgnoredPath = (path) => {
if (IGNORED_PREFIXES.some((prefix) => path.startsWith(prefix))) {
return true;
}
// Keep parity with "*.md" from the previous paths-ignore list.
if (!path.includes('/') && path.endsWith('.md')) {
return true;
}
return false;
};
let changedFiles = [];
if (context.eventName === 'pull_request') {
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 100,
});
changedFiles = files.map((file) => file.filename);
} else if (context.eventName === 'push') {
const before = context.payload.before;
const after = context.payload.after;
if (!before || /^0+$/.test(before)) {
core.info('No comparable base commit found. Running CI by default.');
core.setOutput('run_ci', 'true');
return;
}
const comparison = await github.rest.repos.compareCommitsWithBasehead({
owner: context.repo.owner,
repo: context.repo.repo,
basehead: `${before}...${after}`,
});
changedFiles = (comparison.data.files ?? []).map((file) => file.filename);
} else {
core.info(`Unsupported event "${context.eventName}". Running CI by default.`);
core.setOutput('run_ci', 'true');
return;
}
if (changedFiles.length === 0) {
core.info('No changed files detected. Running CI by default.');
core.setOutput('run_ci', 'true');
return;
}
const relevantFiles = changedFiles.filter((path) => !isIgnoredPath(path));
const runCi = relevantFiles.length > 0;
core.info(`Changed files: ${changedFiles.join(', ')}`);
core.info(runCi ? `CI will run because relevant files changed: ${relevantFiles.join(', ')}` : 'Only docs/meta files changed. CI will be skipped.');
core.setOutput('run_ci', runCi ? 'true' : 'false');
test:
needs: changes
runs-on: ubuntu-latest
env:
NODE_OPTIONS: "--max_old_space_size=6144"
strategy:
matrix:
# https://nodejs.org/en/about/previous-releases
# Using 24.3.x due to https://github.com/pnpm/pnpm/issues/9743
node-version: ['20', '22', '24.3.x']
steps:
- name: Skip CI for docs/meta-only changes
if: ${{ needs.changes.outputs.run_ci != 'true' }}
run: echo "Only docs/meta files changed. Marking test checks as successful without running CI."
- name: Checkout repository
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- name: Install pnpm
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: pnpm/action-setup@8912a9102ac27614460f54aedde9e1e7f9aec20d
with:
run_install: false
- name: Setup Node.js
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: Install dependencies
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm install
- name: Build all packages
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm build:ci
- name: Check generated declarations
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm -r -F "@openai/*" dist:check
- name: Run linter
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm lint
- name: Type-check docs scripts
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm docs:scripts:check
- name: Compile examples
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm -r build-check
- name: Run tests
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm test
windows-sandbox-paths:
needs: changes
runs-on: windows-latest
env:
CI: "1"
NODE_ENV: test
steps:
- name: Skip CI for docs/meta-only changes
if: ${{ needs.changes.outputs.run_ci != 'true' }}
run: echo "Only docs/meta files changed. Marking Windows sandbox path checks as successful without running CI."
- name: Checkout repository
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- name: Install pnpm
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: pnpm/action-setup@8912a9102ac27614460f54aedde9e1e7f9aec20d
with:
run_install: false
- name: Setup Node.js
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 22
cache: 'pnpm'
- name: Install dependencies
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm install
- name: Build packages
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm build
- name: Run Windows sandbox path tests
if: ${{ needs.changes.outputs.run_ci == 'true' }}
shell: bash
run: pnpm exec vitest --run --project "@openai/agents-core" packages/agents-core/test/sandboxWorkspacePaths.test.ts packages/agents-core/test/sandboxManifest.test.ts
- name: Run Windows remote path tests
if: ${{ needs.changes.outputs.run_ci == 'true' }}
shell: bash
run: pnpm exec vitest --run --project "@openai/agents-extensions" packages/agents-extensions/test/sandbox/remotePaths.test.ts
coverage:
needs: changes
runs-on: ubuntu-latest
env:
NODE_OPTIONS: "--max_old_space_size=6144"
steps:
- name: Skip CI for docs/meta-only changes
if: ${{ needs.changes.outputs.run_ci != 'true' }}
run: echo "Only docs/meta files changed. Marking coverage check as successful without running CI."
- name: Checkout repository
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- name: Install pnpm
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: pnpm/action-setup@8912a9102ac27614460f54aedde9e1e7f9aec20d
with:
run_install: false
- name: Setup Node.js
if: ${{ needs.changes.outputs.run_ci == 'true' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 22
cache: 'pnpm'
- name: Install dependencies
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm install
- name: Build all packages
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm build:ci
- name: Run tests with coverage
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: pnpm test:coverage
- name: Enforce coverage thresholds
if: ${{ needs.changes.outputs.run_ci == 'true' }}
run: |
node - <<'NODE'
const fs = require('node:fs');
const summaryPath = 'coverage/coverage-summary.json';
if (!fs.existsSync(summaryPath)) {
console.error(`Missing coverage summary at ${summaryPath}.`);
process.exit(1);
}
const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8'));
const total = summary.total ?? {};
const thresholds = {
lines: 85,
statements: 85,
functions: 85,
branches: 80,
};
let failed = false;
for (const [key, min] of Object.entries(thresholds)) {
const pct = typeof total[key]?.pct === 'number' ? total[key].pct : 0;
const status = pct >= min ? 'OK' : 'FAIL';
console.log(`${status}: ${key} ${pct}% (min ${min}%)`);
if (pct < min) {
failed = true;
}
}
if (failed) {
process.exit(1);
}
NODE