From 72b84f67647691d7d20a8f76464c996fcdc63284 Mon Sep 17 00:00:00 2001 From: AlCalzone Date: Mon, 12 Aug 2024 21:34:48 +0200 Subject: [PATCH] ci: check that all device config files have a `.json` extension (#7099) --- .github/workflows/test-and-release.yml | 3 +- .../config/maintenance/lintConfigFiles.ts | 32 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index fab9b9200193..a87edccc4a02 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -183,7 +183,8 @@ jobs: githubToken: ${{ secrets.GITHUB_TOKEN }} - name: Lint config files and Z-Wave specifics - run: yarn run lint:zwave $TURBO_FLAGS + # Disable log prefix, so GitHub recognizes annotations in the output + run: yarn run lint:zwave $TURBO_FLAGS --log-prefix=none # =================== # Runs unit tests on all supported node versions and OSes diff --git a/packages/config/maintenance/lintConfigFiles.ts b/packages/config/maintenance/lintConfigFiles.ts index caac9dee5def..d04bef72770c 100644 --- a/packages/config/maintenance/lintConfigFiles.ts +++ b/packages/config/maintenance/lintConfigFiles.ts @@ -5,7 +5,12 @@ import { getMinimumShiftForBitMask, } from "@zwave-js/core"; import { reportProblem } from "@zwave-js/maintenance"; -import { formatId, getErrorMessage, num2hex } from "@zwave-js/shared"; +import { + enumFilesRecursive, + formatId, + getErrorMessage, + num2hex, +} from "@zwave-js/shared"; import { distinct } from "alcalzone-shared/arrays"; import { wait } from "alcalzone-shared/async"; import { isArray, isObject } from "alcalzone-shared/typeguards"; @@ -201,10 +206,6 @@ interface LintDevicesContext extends LintDevicesContextConditional { async function lintDevices(): Promise { process.env.NODE_ENV = "test"; - await configManager.loadDeviceIndex(); - const index = configManager.getIndex()!; - // Device config files are lazy-loaded, so we need to parse them all - const uniqueFiles = distinct(index.map((e) => e.filename)).sort(); const errors = new Map(); function addError( @@ -254,8 +255,27 @@ async function lintDevices(): Promise { warnings.get(filename)!.push(errorPrefix + warning); } + const rootDir = path.join(configDir, "devices"); + + const forbiddenFiles = await enumFilesRecursive( + rootDir, + (filename) => !filename.endsWith(".json"), + ); + for (const file of forbiddenFiles) { + addError( + path.relative(rootDir, file), + `Invalid extension for device config file. Expected ".json", got "${ + path.extname(file) + }"`, + ); + } + + await configManager.loadDeviceIndex(); + const index = configManager.getIndex()!; + // Device config files are lazy-loaded, so we need to parse them all + const uniqueFiles = distinct(index.map((e) => e.filename)).sort(); + for (const file of uniqueFiles) { - const rootDir = path.join(configDir, "devices"); const filePath = path.join(rootDir, file); // Try parsing the file