-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add workflow for checking version conventions (#11522)
- Loading branch information
Showing
4 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Enforce Version Conventions | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
check-version-convention: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install bun | ||
uses: oven-sh/setup-bun@v2 | ||
with: | ||
bun-version: latest | ||
|
||
- name: Run script for checking conventions | ||
run: bun scripts/check-version-conventions.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable no-console */ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import {isVersioned} from '../src/versioning'; | ||
|
||
function checkVersionConventions(dir: string): string[] { | ||
let faultyFiles: string[] = []; | ||
|
||
const files = fs.readdirSync(dir); | ||
|
||
for (const file of files) { | ||
const filePath = path.join(dir, file); | ||
const stat = fs.statSync(filePath); | ||
|
||
if (stat.isDirectory()) { | ||
faultyFiles = faultyFiles.concat(checkVersionConventions(filePath)); | ||
} else { | ||
if (isVersioned(filePath)) { | ||
const versionPattern = /^.*__v\d+\.x\.mdx$|^.*__v\d+\.\d+\.\d+\.mdx$/; | ||
const basename = path.basename(filePath); | ||
|
||
if (!versionPattern.test(basename)) { | ||
faultyFiles.push(filePath); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return faultyFiles; | ||
} | ||
|
||
const rootDir = 'docs'; | ||
const faultyFiles = checkVersionConventions(rootDir); | ||
|
||
if (faultyFiles.length > 0) { | ||
console.error( | ||
'Error: The following files do not follow the correct versioning convention:' | ||
); | ||
faultyFiles.forEach(file => console.error(` ${file}`)); | ||
console.error( | ||
'Versioned files should end with __v{MAJOR}.x.mdx or __v{MAJOR}.{MINOR}.{PATCH}.mdx' | ||
); | ||
process.exit(1); | ||
} else { | ||
console.log('✅ All files follow the correct versioning convention.'); | ||
} |