From 41c3065aeb82d1249e1e723a8567ee3ef2f3a327 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Tue, 16 Jun 2026 10:17:59 +0800 Subject: [PATCH] fix(lint-md-action): unify basePath in getConfig() and add JSON parse error handling --- src/lint-md-action.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lint-md-action.ts b/src/lint-md-action.ts index 2e197ca..c1c1d69 100644 --- a/src/lint-md-action.ts +++ b/src/lint-md-action.ts @@ -32,19 +32,22 @@ export class LintMdAction { } getConfig() { - // 获取用户传入的配置文件目录 - const configPath = path.resolve(process.env.GITHUB_WORKSPACE || process.cwd(), core.getInput('configFile')) + const configPath = path.resolve(this.basePath, core.getInput('configFile')) if (!fs.existsSync(configPath)) { core.warning('The user does not have a configuration file to pass in, we will use the default configuration instead...') return {} } - // JavaScript 模块,直接 require if (configPath.endsWith('.js')) { return require(`${configPath}`) } const content = fs.readFileSync(configPath).toString() - return JSON.parse(content) + try { + return JSON.parse(content) + } catch (e) { + core.warning(`Failed to parse config file: ${(e as Error).message}`) + return {} + } } isPass() {