Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: check that all device config files have a .json extension #7099

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading