Skip to content

Commit 21816e8

Browse files
authored
ci: Add workflow for checking version conventions (#11522)
1 parent 94e4571 commit 21816e8

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Enforce Version Conventions
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
check-version-convention:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Install bun
17+
uses: oven-sh/setup-bun@v2
18+
with:
19+
bun-version: latest
20+
21+
- name: Run script for checking conventions
22+
run: bun scripts/check-version-conventions.ts

.github/workflows/test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ jobs:
5757
with:
5858
github-token: ${{ steps.token.outputs.token }}
5959

60-
# TODO(mjq): Bring this back once tests are working.
6160
job_test:
6261
name: Test
6362
runs-on: ubuntu-latest
@@ -72,5 +71,4 @@ jobs:
7271
- run: yarn install --frozen-lockfile
7372
if: steps.cache.outputs.cache-hit != 'true'
7473
- name: Run Tests
75-
# run: yarn test
76-
run: true
74+
run: yarn test

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"lint:fix": "yarn run lint:prettier:fix && yarn run lint:eslint:fix",
3333
"sidecar": "yarn spotlight-sidecar",
3434
"test": "vitest",
35+
"test:ci": "vitest run",
3536
"enforce-redirects": "node ./scripts/no-vercel-json-redirects.mjs"
3637
},
3738
"prisma": {
@@ -136,4 +137,4 @@
136137
"node": "20.11.0",
137138
"yarn": "1.22.21"
138139
}
139-
}
140+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable no-console */
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
import {isVersioned} from '../src/versioning';
6+
7+
function checkVersionConventions(dir: string): string[] {
8+
let faultyFiles: string[] = [];
9+
10+
const files = fs.readdirSync(dir);
11+
12+
for (const file of files) {
13+
const filePath = path.join(dir, file);
14+
const stat = fs.statSync(filePath);
15+
16+
if (stat.isDirectory()) {
17+
faultyFiles = faultyFiles.concat(checkVersionConventions(filePath));
18+
} else {
19+
if (isVersioned(filePath)) {
20+
const versionPattern = /^.*__v\d+\.x\.mdx$|^.*__v\d+\.\d+\.\d+\.mdx$/;
21+
const basename = path.basename(filePath);
22+
23+
if (!versionPattern.test(basename)) {
24+
faultyFiles.push(filePath);
25+
}
26+
}
27+
}
28+
}
29+
30+
return faultyFiles;
31+
}
32+
33+
const rootDir = 'docs';
34+
const faultyFiles = checkVersionConventions(rootDir);
35+
36+
if (faultyFiles.length > 0) {
37+
console.error(
38+
'Error: The following files do not follow the correct versioning convention:'
39+
);
40+
faultyFiles.forEach(file => console.error(` ${file}`));
41+
console.error(
42+
'Versioned files should end with __v{MAJOR}.x.mdx or __v{MAJOR}.{MINOR}.{PATCH}.mdx'
43+
);
44+
process.exit(1);
45+
} else {
46+
console.log('✅ All files follow the correct versioning convention.');
47+
}

0 commit comments

Comments
 (0)