Skip to content

Commit 8d744d5

Browse files
authored
feat: verify with the JSONSchema by default (#1171)
1 parent 0e58f8e commit 8d744d5

File tree

5 files changed

+104
-33
lines changed

5 files changed

+104
-33
lines changed

.github/workflows/test.yml

-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ jobs:
7070
version: ${{ matrix.version }}
7171
args: --timeout=5m --issues-exit-code=0 ./sample/...
7272
only-new-issues: true
73-
verify: true
7473

7574
test-go-install: # make sure the action works on a clean machine without building (go-install mode)
7675
needs: [ build ]
@@ -101,7 +100,6 @@ jobs:
101100
args: --timeout=5m --issues-exit-code=0 ./sample/...
102101
only-new-issues: true
103102
install-mode: goinstall
104-
verify: true
105103

106104
test-go-mod:
107105
needs: [ build ]
@@ -127,4 +125,3 @@ jobs:
127125
with:
128126
working-directory: ${{ matrix.wd }}
129127
args: --timeout=5m --issues-exit-code=0 ./...
130-
verify: true

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ inputs:
2424
required: false
2525
verify:
2626
description: "if set to true and the action verify the configuration file against the JSONSchema"
27-
default: 'false'
27+
default: 'true'
2828
required: false
2929
only-new-issues:
3030
description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"

dist/post_run/index.js

+32-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/run/index.js

+32-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/run.ts

+39-11
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
137137
cmdArgs.cwd = path.resolve(workingDirectory)
138138
}
139139

140-
if (core.getBooleanInput(`verify`, { required: true })) {
141-
let cmdVerify = `${binPath} config verify`
142-
if (userArgsMap.get("config")) {
143-
cmdVerify += ` --config=${userArgsMap.get("config")}`
144-
}
145-
146-
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
147-
148-
const res = await execShellCommand(cmdVerify, cmdArgs)
149-
printOutput(res)
150-
}
140+
await runVerify(binPath, userArgsMap, cmdArgs)
151141

152142
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
153143

@@ -173,6 +163,44 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
173163
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`)
174164
}
175165

166+
async function runVerify(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptions): Promise<void> {
167+
const verify = core.getBooleanInput(`verify`, { required: true })
168+
if (!verify) {
169+
return
170+
}
171+
172+
const cfgPath = await getConfigPath(binPath, userArgsMap, cmdArgs)
173+
if (!cfgPath) {
174+
return
175+
}
176+
177+
let cmdVerify = `${binPath} config verify`
178+
if (userArgsMap.get("config")) {
179+
cmdVerify += ` --config=${userArgsMap.get("config")}`
180+
}
181+
182+
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
183+
184+
const res = await execShellCommand(cmdVerify, cmdArgs)
185+
printOutput(res)
186+
}
187+
188+
async function getConfigPath(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptions): Promise<string> {
189+
let cmdConfigPath = `${binPath} config path`
190+
if (userArgsMap.get("config")) {
191+
cmdConfigPath += ` --config=${userArgsMap.get("config")}`
192+
}
193+
194+
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`)
195+
196+
try {
197+
const resPath = await execShellCommand(cmdConfigPath, cmdArgs)
198+
return resPath.stderr.trim()
199+
} catch {
200+
return ``
201+
}
202+
}
203+
176204
export async function run(): Promise<void> {
177205
try {
178206
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv)

0 commit comments

Comments
 (0)