Skip to content

Commit c06324f

Browse files
committed
add workflow for checking version conventions
1 parent 0c9542f commit c06324f

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
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
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)