Skip to content

Commit

Permalink
ci: Add workflow for checking version conventions (#11522)
Browse files Browse the repository at this point in the history
  • Loading branch information
chargome authored Oct 9, 2024
1 parent 94e4571 commit 21816e8
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/enforce-version-convention.yml
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
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
with:
github-token: ${{ steps.token.outputs.token }}

# TODO(mjq): Bring this back once tests are working.
job_test:
name: Test
runs-on: ubuntu-latest
Expand All @@ -72,5 +71,4 @@ jobs:
- run: yarn install --frozen-lockfile
if: steps.cache.outputs.cache-hit != 'true'
- name: Run Tests
# run: yarn test
run: true
run: yarn test
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"lint:fix": "yarn run lint:prettier:fix && yarn run lint:eslint:fix",
"sidecar": "yarn spotlight-sidecar",
"test": "vitest",
"test:ci": "vitest run",
"enforce-redirects": "node ./scripts/no-vercel-json-redirects.mjs"
},
"prisma": {
Expand Down Expand Up @@ -136,4 +137,4 @@
"node": "20.11.0",
"yarn": "1.22.21"
}
}
}
47 changes: 47 additions & 0 deletions scripts/check-version-conventions.ts
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.');
}

0 comments on commit 21816e8

Please sign in to comment.