diff --git a/.github/workflows/enforce-version-convention.yml b/.github/workflows/enforce-version-convention.yml new file mode 100644 index 00000000000000..4ac32032f9353d --- /dev/null +++ b/.github/workflows/enforce-version-convention.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c05454110e14b6..d6169966e66cf5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 diff --git a/package.json b/package.json index 82e0de6c78f4a7..5c7e9161a8fa3d 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -136,4 +137,4 @@ "node": "20.11.0", "yarn": "1.22.21" } -} +} \ No newline at end of file diff --git a/scripts/check-version-conventions.ts b/scripts/check-version-conventions.ts new file mode 100644 index 00000000000000..49474fcc1933f9 --- /dev/null +++ b/scripts/check-version-conventions.ts @@ -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.'); +}