feat: verify with the JSONSchema by default (#1171)

This commit is contained in:
Ludovic Fernandez
2025-02-15 15:02:58 +01:00
committed by GitHub
parent 0e58f8e7ab
commit 8d744d5b7f
5 changed files with 104 additions and 33 deletions

View File

@ -70,7 +70,6 @@ jobs:
version: ${{ matrix.version }} version: ${{ matrix.version }}
args: --timeout=5m --issues-exit-code=0 ./sample/... args: --timeout=5m --issues-exit-code=0 ./sample/...
only-new-issues: true only-new-issues: true
verify: true
test-go-install: # make sure the action works on a clean machine without building (go-install mode) test-go-install: # make sure the action works on a clean machine without building (go-install mode)
needs: [ build ] needs: [ build ]
@ -101,7 +100,6 @@ jobs:
args: --timeout=5m --issues-exit-code=0 ./sample/... args: --timeout=5m --issues-exit-code=0 ./sample/...
only-new-issues: true only-new-issues: true
install-mode: goinstall install-mode: goinstall
verify: true
test-go-mod: test-go-mod:
needs: [ build ] needs: [ build ]
@ -127,4 +125,3 @@ jobs:
with: with:
working-directory: ${{ matrix.wd }} working-directory: ${{ matrix.wd }}
args: --timeout=5m --issues-exit-code=0 ./... args: --timeout=5m --issues-exit-code=0 ./...
verify: true

View File

@ -24,7 +24,7 @@ inputs:
required: false required: false
verify: verify:
description: "if set to true and the action verify the configuration file against the JSONSchema" description: "if set to true and the action verify the configuration file against the JSONSchema"
default: 'false' default: 'true'
required: false required: false
only-new-issues: only-new-issues:
description: "if set to true and the action runs on a pull request - the action outputs only newly found issues" description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"

41
dist/post_run/index.js generated vendored
View File

@ -94123,15 +94123,7 @@ async function runLint(binPath, patchPath) {
} }
cmdArgs.cwd = path.resolve(workingDirectory); cmdArgs.cwd = path.resolve(workingDirectory);
} }
if (core.getBooleanInput(`verify`, { required: true })) { await runVerify(binPath, userArgsMap, cmdArgs);
let cmdVerify = `${binPath} config verify`;
if (userArgsMap.get("config")) {
cmdVerify += ` --config=${userArgsMap.get("config")}`;
}
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
const res = await execShellCommand(cmdVerify, cmdArgs);
printOutput(res);
}
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd(); const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`); core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
const startedAt = Date.now(); const startedAt = Date.now();
@ -94153,6 +94145,37 @@ async function runLint(binPath, patchPath) {
} }
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`); core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`);
} }
async function runVerify(binPath, userArgsMap, cmdArgs) {
const verify = core.getBooleanInput(`verify`, { required: true });
if (!verify) {
return;
}
const cfgPath = await getConfigPath(binPath, userArgsMap, cmdArgs);
if (!cfgPath) {
return;
}
let cmdVerify = `${binPath} config verify`;
if (userArgsMap.get("config")) {
cmdVerify += ` --config=${userArgsMap.get("config")}`;
}
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
const res = await execShellCommand(cmdVerify, cmdArgs);
printOutput(res);
}
async function getConfigPath(binPath, userArgsMap, cmdArgs) {
let cmdConfigPath = `${binPath} config path`;
if (userArgsMap.get("config")) {
cmdConfigPath += ` --config=${userArgsMap.get("config")}`;
}
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`);
try {
const resPath = await execShellCommand(cmdConfigPath, cmdArgs);
return resPath.stderr.trim();
}
catch {
return ``;
}
}
async function run() { async function run() {
try { try {
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv); const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv);

41
dist/run/index.js generated vendored
View File

@ -94123,15 +94123,7 @@ async function runLint(binPath, patchPath) {
} }
cmdArgs.cwd = path.resolve(workingDirectory); cmdArgs.cwd = path.resolve(workingDirectory);
} }
if (core.getBooleanInput(`verify`, { required: true })) { await runVerify(binPath, userArgsMap, cmdArgs);
let cmdVerify = `${binPath} config verify`;
if (userArgsMap.get("config")) {
cmdVerify += ` --config=${userArgsMap.get("config")}`;
}
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
const res = await execShellCommand(cmdVerify, cmdArgs);
printOutput(res);
}
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd(); const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`); core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
const startedAt = Date.now(); const startedAt = Date.now();
@ -94153,6 +94145,37 @@ async function runLint(binPath, patchPath) {
} }
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`); core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`);
} }
async function runVerify(binPath, userArgsMap, cmdArgs) {
const verify = core.getBooleanInput(`verify`, { required: true });
if (!verify) {
return;
}
const cfgPath = await getConfigPath(binPath, userArgsMap, cmdArgs);
if (!cfgPath) {
return;
}
let cmdVerify = `${binPath} config verify`;
if (userArgsMap.get("config")) {
cmdVerify += ` --config=${userArgsMap.get("config")}`;
}
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
const res = await execShellCommand(cmdVerify, cmdArgs);
printOutput(res);
}
async function getConfigPath(binPath, userArgsMap, cmdArgs) {
let cmdConfigPath = `${binPath} config path`;
if (userArgsMap.get("config")) {
cmdConfigPath += ` --config=${userArgsMap.get("config")}`;
}
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`);
try {
const resPath = await execShellCommand(cmdConfigPath, cmdArgs);
return resPath.stderr.trim();
}
catch {
return ``;
}
}
async function run() { async function run() {
try { try {
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv); const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv);

View File

@ -137,17 +137,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
cmdArgs.cwd = path.resolve(workingDirectory) cmdArgs.cwd = path.resolve(workingDirectory)
} }
if (core.getBooleanInput(`verify`, { required: true })) { await runVerify(binPath, userArgsMap, cmdArgs)
let cmdVerify = `${binPath} config verify`
if (userArgsMap.get("config")) {
cmdVerify += ` --config=${userArgsMap.get("config")}`
}
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
const res = await execShellCommand(cmdVerify, cmdArgs)
printOutput(res)
}
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd() const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
@ -173,6 +163,44 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`) core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`)
} }
async function runVerify(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptions): Promise<void> {
const verify = core.getBooleanInput(`verify`, { required: true })
if (!verify) {
return
}
const cfgPath = await getConfigPath(binPath, userArgsMap, cmdArgs)
if (!cfgPath) {
return
}
let cmdVerify = `${binPath} config verify`
if (userArgsMap.get("config")) {
cmdVerify += ` --config=${userArgsMap.get("config")}`
}
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
const res = await execShellCommand(cmdVerify, cmdArgs)
printOutput(res)
}
async function getConfigPath(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptions): Promise<string> {
let cmdConfigPath = `${binPath} config path`
if (userArgsMap.get("config")) {
cmdConfigPath += ` --config=${userArgsMap.get("config")}`
}
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`)
try {
const resPath = await execShellCommand(cmdConfigPath, cmdArgs)
return resPath.stderr.trim()
} catch {
return ``
}
}
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv) const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv)