Skip to content

Commit 6e5d89b

Browse files
committed
move validation to index.ts
Signed-off-by: Andrew Duffy <andrew@a10y.dev>
1 parent 28008c7 commit 6e5d89b

4 files changed

Lines changed: 69 additions & 67 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Bun
16+
uses: oven-sh/setup-bun@v2
17+
18+
- name: Install dependencies
19+
run: bun install
20+
21+
- name: Build
22+
run: bun run build

.github/workflows/validate-proposals.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

index.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,42 @@ function parseRFCNumber(filename: string): string {
129129
return match?.[1] ?? "0000";
130130
}
131131

132+
interface ValidationError {
133+
filename: string;
134+
message: string;
135+
}
136+
137+
async function validateProposals(): Promise<ValidationError[]> {
138+
const errors: ValidationError[] = [];
139+
const glob = new Bun.Glob("*");
140+
const seenNumbers = new Map<string, string>();
141+
142+
for await (const filename of glob.scan("./proposals")) {
143+
// Check filename format: NNNN-slug.md
144+
if (!filename.match(/^\d{4}-[a-zA-Z0-9_-]+\.md$/)) {
145+
errors.push({
146+
filename,
147+
message: `Invalid filename format. Expected: NNNN-name.md (e.g., 0007-my-proposal.md)`,
148+
});
149+
continue;
150+
}
151+
152+
// Check for duplicate RFC numbers
153+
const number = filename.slice(0, 4);
154+
const existing = seenNumbers.get(number);
155+
if (existing) {
156+
errors.push({
157+
filename,
158+
message: `Duplicate RFC number ${number} (also used by ${existing})`,
159+
});
160+
} else {
161+
seenNumbers.set(number, filename);
162+
}
163+
}
164+
165+
return errors;
166+
}
167+
132168
function parseTitle(markdown: string, filename: string): string {
133169
// Try to extract title from first # heading
134170
const match = markdown.match(/^#\s+(.+)$/m);
@@ -143,6 +179,17 @@ function parseTitle(markdown: string, filename: string): string {
143179
async function build(liveReload: boolean = false): Promise<number> {
144180
console.log("Building Vortex RFC site...\n");
145181

182+
// Validate proposals first
183+
const validationErrors = await validateProposals();
184+
if (validationErrors.length > 0) {
185+
console.error("Validation errors found:\n");
186+
for (const error of validationErrors) {
187+
console.error(` ${error.filename}: ${error.message}`);
188+
}
189+
console.error("");
190+
process.exit(1);
191+
}
192+
146193
const glob = new Bun.Glob("*.md");
147194
const rfcs: RFC[] = [];
148195

scripts/validate-proposals.sh

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)