Skip to content

Commit 071c503

Browse files
authored
ci(ai-instructions): fail lint when a NEEDS YOU marker is a GitHub shortcode (#1269)
Adds a composite action that fails the ai-instructions lint when a NEEDS YOU marker is written as a GitHub shortcode, and wires it into the ai-instructions-lint workflow. Closes #1235
2 parents 763b9d8 + cb7cef6 commit 071c503

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--- # Fail if an AI instruction file writes a NEEDS YOU marker as a GitHub shortcode
2+
# Maintain in repo: cs-template
3+
name: "Check Instructions NEEDS YOU Markers"
4+
description: "Fails if a line under ai/ or in .ai-instructions contains NEEDS YOU together with a :stop_sign:, :warning: or :white_check_mark: shortcode"
5+
6+
runs:
7+
using: composite
8+
steps:
9+
- name: "Check NEEDS YOU markers"
10+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
11+
with:
12+
script: |
13+
// NEEDS YOU markers must be literal emoji characters because a terminal shows a
14+
// shortcode as plain text. Only lines that mention NEEDS YOU are checked, so shortcodes
15+
// elsewhere (which GitHub renders) are left alone.
16+
17+
const { execFileSync } = require('node:child_process');
18+
const { readFileSync } = require('node:fs');
19+
const path = require('node:path');
20+
21+
const NEEDS_YOU = 'NEEDS YOU';
22+
const MARKER_SHORTCODES = [':stop_sign:', ':warning:', ':white_check_mark:'];
23+
24+
function trackedInstructionFiles(root) {
25+
return execFileSync('git', ['ls-files', '-z', '--', 'ai', '.ai-instructions'], { cwd: root, encoding: 'utf8' })
26+
.split('\0')
27+
.filter(Boolean);
28+
}
29+
30+
function shortcodesOnLine(text) {
31+
return text.includes(NEEDS_YOU) ? MARKER_SHORTCODES.filter((shortcode) => text.includes(shortcode)) : [];
32+
}
33+
34+
function findProblems(root, files) {
35+
return files.flatMap((file) =>
36+
readFileSync(path.join(root, file), 'utf8')
37+
.split('\n')
38+
.flatMap((text, index) =>
39+
shortcodesOnLine(text).map((shortcode) => ({
40+
file,
41+
line: index + 1,
42+
message: `NEEDS YOU marker written as the shortcode ${shortcode}; use the emoji character instead`,
43+
})),
44+
),
45+
);
46+
}
47+
48+
const root = execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).trim();
49+
const problems = findProblems(root, trackedInstructionFiles(root));
50+
51+
if (problems.length > 0) {
52+
for (const problem of problems) {
53+
core.error(problem.message, { file: problem.file, startLine: problem.line });
54+
}
55+
56+
core.setFailed('❌ Found NEEDS YOU markers written as GitHub shortcodes.');
57+
return;
58+
}
59+
60+
core.info('✅ All NEEDS YOU markers use emoji characters.');

‎.github/workflows/ai-instructions-lint.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
--- # AI instructions: enforce numbering and cross-reference anchor conventions
1+
--- # AI instructions: enforce numbering, cross-reference anchor and NEEDS YOU marker conventions
22
# Maintain in repo: cs-template
33
name: "PR: AI Instructions Lint"
44
on:
@@ -12,6 +12,7 @@ on:
1212
- ".ai-instructions"
1313
- ".github/workflows/ai-instructions-lint.yml"
1414
- ".github/actions/check-instructions-anchors/**"
15+
- ".github/actions/check-instructions-needs-you-markers/**"
1516
- ".github/actions/check-instructions-numbering/**"
1617

1718
permissions:
@@ -42,3 +43,7 @@ jobs:
4243
- name: "Check instruction anchors"
4344
if: success() || failure()
4445
uses: ./.github/actions/check-instructions-anchors
46+
47+
- name: "Check NEEDS YOU markers"
48+
if: success() || failure()
49+
uses: ./.github/actions/check-instructions-needs-you-markers

0 commit comments

Comments
 (0)