Skip to content

Commit f0bfeab

Browse files
committed
CIHelper: validate the user-provided config Action input
This uses the freshly-installed `typia` module to create a validator for the `IConfig` interface at compile-time, and uses it to validate user-provided JSON against that interface. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent c160f9a commit f0bfeab

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"tbdiff",
8484
"Thái",
8585
"Truthy",
86+
"typia",
8687
"unportable",
8788
"vger",
8889
"VSTS",

lib/ci-helper.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from "@actions/core";
22
import * as fs from "fs";
33
import * as os from "os";
4+
import typia from "typia";
45
import * as util from "util";
56
import { spawnSync } from "child_process";
67
import addressparser from "nodemailer/lib/addressparser/index.js";
@@ -53,13 +54,20 @@ export class CIHelper {
5354
return configFile ? await getExternalConfig(configFile) : getConfig();
5455
}
5556

57+
public static validateConfig = typia.createValidate<IConfig>();
58+
5659
protected static getConfigAsGitHubActionInput(): IConfig | undefined {
5760
if (process.env.GITHUB_ACTIONS !== "true") return undefined;
5861
const json = core.getInput("config");
5962
if (!json) return undefined;
6063
const config = JSON.parse(json) as IConfig | undefined;
61-
if (typeof config === "object" && config.project !== undefined) return config;
62-
return undefined;
64+
const result = CIHelper.validateConfig(config);
65+
if (result.success) return config;
66+
throw new Error(
67+
`Invalid config:\n- ${result.errors
68+
.map((e) => `${e.path} (value: ${e.value}, expected: ${e.expected}): ${e.description}`)
69+
.join("\n- ")}`,
70+
);
6371
}
6472

6573
public constructor(workDir: string = "pr-repo.git", config?: IConfig, skipUpdate?: boolean, gggConfigDir = ".") {

0 commit comments

Comments
 (0)