Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,22 @@ You will also likely need to add the following `.gitattributes` file to ensure t

### Overview

| Option | Description |
|---------------------------------------------------------------|----------------------------------------------------|
| [`version`](#version) | The version of golangci-lint to use. |
| [`install-mode`](#install-mode) | The mode to install golangci-lint. |
| [`install-only`](#install-only) | Only install golangci-lint. |
| [`verify`](#verify) | Validates golangci-lint configuration file. |
| [`github-token`](#github-token) | Used by the `only-new-issues` option. |
| [`only-new-issues`](#only-new-issues) | Show only new issues. |
| [`working-directory`](#working-directory) | The golangci-lint working directory. |
| [`args`](#args) | Golangci-lint command line arguments. |
| [`skip-cache`](#skip-cache) | Disable cache support. |
| [`skip-save-cache`](#skip-save-cache) | Don't save cache. |
| [`cache-invalidation-interval`](#cache-invalidation-interval) | Number of days before cache invalidation. |
| [`problem-matchers`](#problem-matchers) | Forces the usage of the embedded problem matchers. |
| [Experimental](#experimental) | Experimental options |
| Option | Description |
|---------------------------------------------------------------|-------------------------------------------------------|
| [`version`](#version) | The version of golangci-lint to use. |
| [`version-file`](#version-file) | Gets the version of golangci-lint to use from a file. |
| [`install-mode`](#install-mode) | The mode to install golangci-lint. |
| [`install-only`](#install-only) | Only install golangci-lint. |
| [`verify`](#verify) | Validates golangci-lint configuration file. |
| [`github-token`](#github-token) | Used by the `only-new-issues` option. |
| [`only-new-issues`](#only-new-issues) | Show only new issues. |
| [`working-directory`](#working-directory) | The golangci-lint working directory. |
| [`args`](#args) | Golangci-lint command line arguments. |
| [`skip-cache`](#skip-cache) | Disable cache support. |
| [`skip-save-cache`](#skip-save-cache) | Don't save cache. |
| [`cache-invalidation-interval`](#cache-invalidation-interval) | Number of days before cache invalidation. |
| [`problem-matchers`](#problem-matchers) | Forces the usage of the embedded problem matchers. |
| [Experimental](#experimental) | Experimental options |

### Installation

Expand All @@ -302,6 +303,28 @@ with:

</details>

#### `version-file`

Gets the version of golangci-lint to use from a file.

The path must be relative to the root of the project, or the `working-directory` if defined.

This parameter supports `.golangci-lint-version`, and `.tool-versions` files.

Only works with `install-mode: binary` (the default).

<details>
<summary>Example</summary>

```yml
uses: golangci/golangci-lint-action@v9
with:
version-file: .tool-versions
# ...
```

</details>

#### `install-mode`

(optional)
Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ inputs:
- `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit.
- `none`: the value is ignored.
required: false
version-file:
description: |
Gets the version of golangci-lint to use from a file.
The path must be relative to the root of the project, or the `working-directory` if defined.
This parameter supports `.golangci-lint-version`, and `.tool-versions` files.
Only works with `install-mode: binary` (the default).
required: false
install-mode:
description: "The mode to install golangci-lint. It can be 'binary', 'goinstall', or 'none'."
default: "binary"
Expand Down
22 changes: 22 additions & 0 deletions dist/post_run/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions dist/run/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ const isLessVersion = (a: Version, b: Version): boolean => {

const getRequestedVersion = (): Version => {
let requestedVersion = core.getInput(`version`)
let versionFilePath = core.getInput(`version-file`)

if (requestedVersion && versionFilePath) {
core.warning(`Both version (${requestedVersion}) and version-file (${versionFilePath}) inputs are specified, only version will be used`)
}

const workingDirectory = core.getInput(`working-directory`)

let goMod = "go.mod"
Expand All @@ -83,6 +89,27 @@ const getRequestedVersion = (): Version => {
}
}

if (requestedVersion == "" && versionFilePath) {
if (workingDirectory) {
versionFilePath = path.join(workingDirectory, versionFilePath)
}

if (!fs.existsSync(versionFilePath)) {
throw new Error(`The specified golangci-lint version file at: ${versionFilePath} does not exist`)
}

const content = fs.readFileSync(versionFilePath, "utf-8")

if (path.basename(versionFilePath) === ".tool-versions") {
// asdf/mise file.
const match = content.match(/^golangci-lint\s+([^\n#]+)/m)
requestedVersion = match ? "v" + match[1].trim().replace(/^v/gi, "") : ""
} else {
// .golangci-lint-version file.
requestedVersion = "v" + content.trim().replace(/^v/gi, "")
}
}

const parsedRequestedVersion = parseVersion(requestedVersion)
if (parsedRequestedVersion == null) {
return null
Expand Down
Loading