mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2025-12-12 14:01:14 +00:00
feat: add version-file option (#1320)
This commit is contained in:
parent
a6071aaacb
commit
aa6fad0ea0
5 changed files with 116 additions and 15 deletions
53
README.md
53
README.md
|
|
@ -261,21 +261,22 @@ You will also likely need to add the following `.gitattributes` file to ensure t
|
||||||
|
|
||||||
### Overview
|
### Overview
|
||||||
|
|
||||||
| Option | Description |
|
| Option | Description |
|
||||||
|---------------------------------------------------------------|----------------------------------------------------|
|
|---------------------------------------------------------------|-------------------------------------------------------|
|
||||||
| [`version`](#version) | The version of golangci-lint to use. |
|
| [`version`](#version) | The version of golangci-lint to use. |
|
||||||
| [`install-mode`](#install-mode) | The mode to install golangci-lint. |
|
| [`version-file`](#version-file) | Gets the version of golangci-lint to use from a file. |
|
||||||
| [`install-only`](#install-only) | Only install golangci-lint. |
|
| [`install-mode`](#install-mode) | The mode to install golangci-lint. |
|
||||||
| [`verify`](#verify) | Validates golangci-lint configuration file. |
|
| [`install-only`](#install-only) | Only install golangci-lint. |
|
||||||
| [`github-token`](#github-token) | Used by the `only-new-issues` option. |
|
| [`verify`](#verify) | Validates golangci-lint configuration file. |
|
||||||
| [`only-new-issues`](#only-new-issues) | Show only new issues. |
|
| [`github-token`](#github-token) | Used by the `only-new-issues` option. |
|
||||||
| [`working-directory`](#working-directory) | The golangci-lint working directory. |
|
| [`only-new-issues`](#only-new-issues) | Show only new issues. |
|
||||||
| [`args`](#args) | Golangci-lint command line arguments. |
|
| [`working-directory`](#working-directory) | The golangci-lint working directory. |
|
||||||
| [`skip-cache`](#skip-cache) | Disable cache support. |
|
| [`args`](#args) | Golangci-lint command line arguments. |
|
||||||
| [`skip-save-cache`](#skip-save-cache) | Don't save cache. |
|
| [`skip-cache`](#skip-cache) | Disable cache support. |
|
||||||
| [`cache-invalidation-interval`](#cache-invalidation-interval) | Number of days before cache invalidation. |
|
| [`skip-save-cache`](#skip-save-cache) | Don't save cache. |
|
||||||
| [`problem-matchers`](#problem-matchers) | Forces the usage of the embedded problem matchers. |
|
| [`cache-invalidation-interval`](#cache-invalidation-interval) | Number of days before cache invalidation. |
|
||||||
| [Experimental](#experimental) | Experimental options |
|
| [`problem-matchers`](#problem-matchers) | Forces the usage of the embedded problem matchers. |
|
||||||
|
| [Experimental](#experimental) | Experimental options |
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
|
|
@ -302,6 +303,28 @@ with:
|
||||||
|
|
||||||
</details>
|
</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`
|
#### `install-mode`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,13 @@ inputs:
|
||||||
- `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit.
|
- `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit.
|
||||||
- `none`: the value is ignored.
|
- `none`: the value is ignored.
|
||||||
required: false
|
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:
|
install-mode:
|
||||||
description: "The mode to install golangci-lint. It can be 'binary', 'goinstall', or 'none'."
|
description: "The mode to install golangci-lint. It can be 'binary', 'goinstall', or 'none'."
|
||||||
default: "binary"
|
default: "binary"
|
||||||
|
|
|
||||||
22
dist/post_run/index.js
generated
vendored
22
dist/post_run/index.js
generated
vendored
|
|
@ -97912,6 +97912,10 @@ const isLessVersion = (a, b) => {
|
||||||
};
|
};
|
||||||
const getRequestedVersion = () => {
|
const getRequestedVersion = () => {
|
||||||
let requestedVersion = core.getInput(`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`);
|
const workingDirectory = core.getInput(`working-directory`);
|
||||||
let goMod = "go.mod";
|
let goMod = "go.mod";
|
||||||
if (workingDirectory) {
|
if (workingDirectory) {
|
||||||
|
|
@ -97925,6 +97929,24 @@ const getRequestedVersion = () => {
|
||||||
core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`);
|
core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (requestedVersion == "" && versionFilePath) {
|
||||||
|
if (workingDirectory) {
|
||||||
|
versionFilePath = path_1.default.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_1.default.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);
|
const parsedRequestedVersion = parseVersion(requestedVersion);
|
||||||
if (parsedRequestedVersion == null) {
|
if (parsedRequestedVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
22
dist/run/index.js
generated
vendored
22
dist/run/index.js
generated
vendored
|
|
@ -97912,6 +97912,10 @@ const isLessVersion = (a, b) => {
|
||||||
};
|
};
|
||||||
const getRequestedVersion = () => {
|
const getRequestedVersion = () => {
|
||||||
let requestedVersion = core.getInput(`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`);
|
const workingDirectory = core.getInput(`working-directory`);
|
||||||
let goMod = "go.mod";
|
let goMod = "go.mod";
|
||||||
if (workingDirectory) {
|
if (workingDirectory) {
|
||||||
|
|
@ -97925,6 +97929,24 @@ const getRequestedVersion = () => {
|
||||||
core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`);
|
core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (requestedVersion == "" && versionFilePath) {
|
||||||
|
if (workingDirectory) {
|
||||||
|
versionFilePath = path_1.default.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_1.default.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);
|
const parsedRequestedVersion = parseVersion(requestedVersion);
|
||||||
if (parsedRequestedVersion == null) {
|
if (parsedRequestedVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,12 @@ const isLessVersion = (a: Version, b: Version): boolean => {
|
||||||
|
|
||||||
const getRequestedVersion = (): Version => {
|
const getRequestedVersion = (): Version => {
|
||||||
let requestedVersion = core.getInput(`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`)
|
const workingDirectory = core.getInput(`working-directory`)
|
||||||
|
|
||||||
let goMod = "go.mod"
|
let goMod = "go.mod"
|
||||||
|
|
@ -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)
|
const parsedRequestedVersion = parseVersion(requestedVersion)
|
||||||
if (parsedRequestedVersion == null) {
|
if (parsedRequestedVersion == null) {
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue