Skip to content

Commit 86b34df

Browse files
authored
ci: adopt the hardened shared risk gate
One gate file for every QuantStrategyLab repository, with the receipt-selection and high-risk classification fixes Codex found on the unification pull requests.
1 parent 3dbb797 commit 86b34df

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

‎.github/workflows/risk-gate.yml‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ jobs:
168168
const isWorkflow = path => path.startsWith('.github/workflows/');
169169
function highRisk(path) {
170170
const p = path.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase();
171-
if (/(^|\/)codeowners$/.test(p)) return true;
171+
if (p.startsWith('.github/governance/') || /(^|\/)codeowners$/.test(p)) return true;
172172
if (/(^|\/)(docs?|tests?|examples?|fixtures)(\/|$)/.test(p)) return false;
173173
if (/(^|\/)\.env(?:[./_-]|$)/.test(p)) return true;
174174
// Runtime configuration decides behaviour the diff does not show.
@@ -180,9 +180,11 @@ jobs:
180180
// workflow file, and a diff alone cannot show who calls it.
181181
if (/^\.github\/scripts\//.test(path)) return true;
182182
if (/^scripts\/[^/]*(?:check|verify|validate|hygiene|lint)[^/]*\.(?:py|sh|js|cjs|mjs|ts)$/.test(p)) return true;
183-
if (/(^|[\/_.-])(trad(?:e|es|ing)|execution|executors?|orders?|brokers?|risk|deploy(?:ment)?|secrets?|credentials?|iam|runtime|strateg(?:y|ies))([\/_.-]|$)/.test(p)) return true;
183+
// Release, deployment, credential and live-trading tooling are named here
184+
// because a diff alone rarely shows what a script changes at run time.
185+
if (/(^|[\/_.-])(ai_service|aiservice|kelly|stop_loss|trad(?:e|es|ing)|execution|executors?|orders?|brokers?|risk|release|deploy(?:ment)?|secrets?|credentials?|iam|service_account|serviceaccount|permission|role_binding|k8s|kubernetes|runtime|strateg(?:y|ies))([\/_.-]|$)/.test(p)) return true;
184186
return /(^|\/)(dockerfile(?:\..*)?|docker-compose[^/]*|compose\.ya?ml|vercel\.json|wrangler\.(?:toml|jsonc?)|firebase\.json)$/.test(p)
185-
|| /\.(?:tf|tfvars)$/.test(p);
187+
|| /\.(?:tf|tfvars|pem|key|p12|pfx)$/.test(p);
186188
}
187189
// A repin keeps the action and changes only its ref. Swapping in a
188190
// different action is a different change and takes the normal tier.
@@ -296,15 +298,30 @@ jobs:
296298
return { state: 'failure', description: 'Base branch advanced since this head was built; update the branch then comment @codex review' };
297299
}
298300
const comments = await github.paginate(github.rest.issues.listComments, { ...repo, issue_number: prNumber, per_page: 100 });
301+
// The newest marker-bearing comment is the one that counts, and it is
302+
// chosen before its contents are validated. Choosing the newest
303+
// *parseable* receipt instead would let a newer malformed or blocking
304+
// receipt fall back to an older clean one, which is approval by
305+
// accident. Comments updated in the same second are ordered by the
306+
// higher id, so a refresher written later in that second still wins.
307+
const stamped = comment => {
308+
const value = Date.parse(comment.updated_at);
309+
return Number.isFinite(value) ? value : 0;
310+
};
299311
const receipts = comments
300-
.filter(comment => CODEX_LOGIN.test(comment.user?.login || ''))
301-
.map(comment => ({ comment, match: REVIEW_RECEIPT.exec(comment.body || '') }))
302-
.filter(entry => entry.match)
303-
.sort((a, b) => new Date(b.comment.updated_at) - new Date(a.comment.updated_at));
312+
.filter(comment => CODEX_LOGIN.test(comment.user?.login || '')
313+
&& typeof comment.body === 'string'
314+
&& comment.body.includes('codex-review-state:v1'))
315+
.sort((a, b) => stamped(b) - stamped(a) || (b.id || 0) - (a.id || 0));
304316
if (!receipts.length) return { state: 'pending', description: 'No Codex review yet; comment @codex review to start one' };
317+
const markers = [...receipts[0].body.matchAll(/<!--\s*codex-review-state:v1\s*([\s\S]*?)\s*-->/g)];
318+
// Two markers in one comment cannot both be the review that was run.
319+
if (markers.length !== 1) {
320+
return { state: 'error', description: 'Newest Codex review comment has a missing or duplicated receipt' };
321+
}
305322
let receipt;
306323
try {
307-
receipt = JSON.parse(receipts[0].match[1]);
324+
receipt = JSON.parse(markers[0][1]);
308325
} catch {
309326
return { state: 'error', description: 'Codex review receipt is not valid JSON' };
310327
}

0 commit comments

Comments
 (0)