File tree Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 \. m d x $ | ^ .* _ _ v \d + \. \d + \. \d + \. m d x $ / ;
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+ }
You can’t perform that action at this time.
0 commit comments