feat: add install-only option

This commit is contained in:
Fernandez Ludovic 2025-11-05 02:04:22 +01:00
parent 7fe1b22e0c
commit 77c258332f
3 changed files with 42 additions and 2 deletions

View file

@ -302,6 +302,27 @@ with:
</details>
### `install-only`
(optional)
If set to `true`, the action will only install golangci-lint.
It does not run golangci-lint.
The default value is `false`.
<details>
<summary>Example</summary>
```yml
uses: golangci/golangci-lint-action@v8
with:
install-only: true
# ...
```
</details>
### `github-token`
(optional)

View file

@ -15,6 +15,10 @@ inputs:
description: "The mode to install golangci-lint. It can be 'binary', 'goinstall', or 'none'."
default: "binary"
required: false
install-only:
description: "Only install golangci-lint. It does not run golangci-lint."
default: 'false'
required: false
working-directory:
description: "golangci-lint working directory. The default is the project root."
required: false

View file

@ -16,13 +16,18 @@ type Env = {
patchPath: string
}
async function prepareEnv(): Promise<Env> {
async function prepareEnv(installOnly: boolean): Promise<Env> {
const startedAt = Date.now()
// Prepare cache, lint and go in parallel.
await restoreCache()
const binPath = await install()
if (installOnly) {
return { binPath, patchPath: `` }
}
const patchPath = await fetchPatch()
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
@ -196,8 +201,18 @@ async function getConfigPath(binPath: string, userArgsMap: Map<string, string>,
export async function run(): Promise<void> {
try {
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
const installOnly = core.getBooleanInput(`install-only`, { required: true })
const { binPath, patchPath } = await core.group(`prepare environment`, () => {
return prepareEnv(installOnly)
})
core.addPath(path.dirname(binPath))
if (installOnly) {
return
}
await core.group(`run golangci-lint`, () => runLint(binPath, patchPath))
} catch (error) {
core.error(`Failed to run: ${error}, ${error.stack}`)