Skip to content

Commit

Permalink
ci: check that all device config files have a .json extension (#7099)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Aug 12, 2024
1 parent 7d781ad commit 72b84f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 26 additions & 6 deletions packages/config/maintenance/lintConfigFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -201,10 +206,6 @@ interface LintDevicesContext extends LintDevicesContextConditional {

async function lintDevices(): Promise<void> {
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<string, string[]>();
function addError(
Expand Down Expand Up @@ -254,8 +255,27 @@ async function lintDevices(): Promise<void> {
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
Expand Down

0 comments on commit 72b84f6

Please sign in to comment.