diff --git a/README.md b/README.md index 3d0cdff..35794e4 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,27 @@ with: +### `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`. + +
+Example + +```yml +uses: golangci/golangci-lint-action@v8 +with: + install-only: true + # ... +``` + +
+ ### `github-token` (optional) diff --git a/action.yml b/action.yml index 4922368..0598392 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/src/run.ts b/src/run.ts index 8f79b99..52ea0f0 100644 --- a/src/run.ts +++ b/src/run.ts @@ -16,13 +16,18 @@ type Env = { patchPath: string } -async function prepareEnv(): Promise { +async function prepareEnv(installOnly: boolean): Promise { 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, export async function run(): Promise { 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}`)