Skip to content

Commit 809d3b0

Browse files
author
Sergey Vilgelm
authored
Support latest tag for golangci-lint version (#64)
1 parent b026646 commit 809d3b0

File tree

5 files changed

+77
-27
lines changed

5 files changed

+77
-27
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ jobs:
2020
- uses: actions/checkout@v2
2121
- uses: ./
2222
with:
23-
version: v1.29
23+
version: latest
2424
args: --issues-exit-code=0 ./sample/...
2525
only-new-issues: true

action.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
---
2-
name: 'Run golangci-lint'
3-
description: 'Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution.'
4-
author: 'golangci'
2+
name: "Run golangci-lint"
3+
description: "Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution."
4+
author: "golangci"
55
inputs:
66
version:
7-
description: 'version of golangci-lint to use in form of v1.2'
8-
required: true
7+
description: "version of golangci-lint to use in form of v1.2 or `latest` to use the latest version"
8+
required: false
99
args:
10-
description: 'golangci-lint command line arguments'
11-
default: ''
10+
description: "golangci-lint command line arguments"
11+
default: ""
1212
required: false
1313
working-directory:
14-
description: 'golangci-lint working directory, default is project root'
14+
description: "golangci-lint working directory, default is project root"
1515
required: false
1616
github-token:
17-
description: 'the token is used for fetching patch of a pull request to show only new issues'
17+
description: "the token is used for fetching patch of a pull request to show only new issues"
1818
default: ${{ github.token }}
1919
required: true
2020
only-new-issues:
21-
description: 'if set to true and the action runs on a pull request - the action outputs only newly found issues'
21+
description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"
2222
default: false
2323
required: true
2424

2525
runs:
26-
using: 'node12'
27-
main: 'dist/run/index.js'
28-
post: 'dist/post_run/index.js'
26+
using: "node12"
27+
main: "dist/run/index.js"
28+
post: "dist/post_run/index.js"
2929
branding:
30-
icon: 'shield'
31-
color: 'yellow'
30+
icon: "shield"
31+
color: "yellow"

dist/post_run/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,9 @@ const core = __importStar(__webpack_require__(470));
20192019
const httpm = __importStar(__webpack_require__(539));
20202020
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
20212021
const parseVersion = (s) => {
2022+
if (s == "latest" || s == "") {
2023+
return null;
2024+
}
20222025
const match = s.match(versionRe);
20232026
if (!match) {
20242027
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`);
@@ -2029,13 +2032,24 @@ const parseVersion = (s) => {
20292032
patch: match[3] === undefined ? null : parseInt(match[3]),
20302033
};
20312034
};
2032-
exports.stringifyVersion = (v) => `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`;
2035+
exports.stringifyVersion = (v) => {
2036+
if (v == null) {
2037+
return "latest";
2038+
}
2039+
return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`;
2040+
};
20332041
const minVersion = {
20342042
major: 1,
20352043
minor: 28,
20362044
patch: 3,
20372045
};
20382046
const isLessVersion = (a, b) => {
2047+
if (a == null) {
2048+
return true;
2049+
}
2050+
if (b == null) {
2051+
return false;
2052+
}
20392053
if (a.major != b.major) {
20402054
return a.major < b.major;
20412055
}
@@ -2044,8 +2058,11 @@ const isLessVersion = (a, b) => {
20442058
return a.minor < b.minor;
20452059
};
20462060
const getRequestedLintVersion = () => {
2047-
const requestedLintVersion = core.getInput(`version`, { required: true });
2061+
const requestedLintVersion = core.getInput(`version`);
20482062
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
2063+
if (parsedRequestedLintVersion == null) {
2064+
return null;
2065+
}
20492066
if (parsedRequestedLintVersion.patch !== null) {
20502067
throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
20512068
}
@@ -2076,12 +2093,12 @@ function findLintVersion() {
20762093
return __awaiter(this, void 0, void 0, function* () {
20772094
core.info(`Finding needed golangci-lint version...`);
20782095
const startedAt = Date.now();
2079-
const reqLintVersion = getRequestedLintVersion();
20802096
const config = yield getConfig();
20812097
if (!config.MinorVersionToConfig) {
20822098
core.warning(JSON.stringify(config));
20832099
throw new Error(`invalid config: no MinorVersionToConfig field`);
20842100
}
2101+
const reqLintVersion = getRequestedLintVersion();
20852102
const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
20862103
if (!versionConfig) {
20872104
throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);

dist/run/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,9 @@ const core = __importStar(__webpack_require__(470));
20192019
const httpm = __importStar(__webpack_require__(539));
20202020
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
20212021
const parseVersion = (s) => {
2022+
if (s == "latest" || s == "") {
2023+
return null;
2024+
}
20222025
const match = s.match(versionRe);
20232026
if (!match) {
20242027
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`);
@@ -2029,13 +2032,24 @@ const parseVersion = (s) => {
20292032
patch: match[3] === undefined ? null : parseInt(match[3]),
20302033
};
20312034
};
2032-
exports.stringifyVersion = (v) => `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`;
2035+
exports.stringifyVersion = (v) => {
2036+
if (v == null) {
2037+
return "latest";
2038+
}
2039+
return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`;
2040+
};
20332041
const minVersion = {
20342042
major: 1,
20352043
minor: 28,
20362044
patch: 3,
20372045
};
20382046
const isLessVersion = (a, b) => {
2047+
if (a == null) {
2048+
return true;
2049+
}
2050+
if (b == null) {
2051+
return false;
2052+
}
20392053
if (a.major != b.major) {
20402054
return a.major < b.major;
20412055
}
@@ -2044,8 +2058,11 @@ const isLessVersion = (a, b) => {
20442058
return a.minor < b.minor;
20452059
};
20462060
const getRequestedLintVersion = () => {
2047-
const requestedLintVersion = core.getInput(`version`, { required: true });
2061+
const requestedLintVersion = core.getInput(`version`);
20482062
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
2063+
if (parsedRequestedLintVersion == null) {
2064+
return null;
2065+
}
20492066
if (parsedRequestedLintVersion.patch !== null) {
20502067
throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
20512068
}
@@ -2076,12 +2093,12 @@ function findLintVersion() {
20762093
return __awaiter(this, void 0, void 0, function* () {
20772094
core.info(`Finding needed golangci-lint version...`);
20782095
const startedAt = Date.now();
2079-
const reqLintVersion = getRequestedLintVersion();
20802096
const config = yield getConfig();
20812097
if (!config.MinorVersionToConfig) {
20822098
core.warning(JSON.stringify(config));
20832099
throw new Error(`invalid config: no MinorVersionToConfig field`);
20842100
}
2101+
const reqLintVersion = getRequestedLintVersion();
20852102
const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
20862103
if (!versionConfig) {
20872104
throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);

src/version.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ export type Version = {
66
major: number
77
minor: number
88
patch: number | null
9-
}
9+
} | null
1010

1111
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
1212

1313
const parseVersion = (s: string): Version => {
14+
if (s == "latest" || s == "") {
15+
return null
16+
}
1417
const match = s.match(versionRe)
1518
if (!match) {
1619
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
@@ -23,7 +26,12 @@ const parseVersion = (s: string): Version => {
2326
}
2427
}
2528

26-
export const stringifyVersion = (v: Version): string => `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`
29+
export const stringifyVersion = (v: Version): string => {
30+
if (v == null) {
31+
return "latest"
32+
}
33+
return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`
34+
}
2735

2836
const minVersion = {
2937
major: 1,
@@ -32,6 +40,12 @@ const minVersion = {
3240
}
3341

3442
const isLessVersion = (a: Version, b: Version): boolean => {
43+
if (a == null) {
44+
return true
45+
}
46+
if (b == null) {
47+
return false
48+
}
3549
if (a.major != b.major) {
3650
return a.major < b.major
3751
}
@@ -42,8 +56,11 @@ const isLessVersion = (a: Version, b: Version): boolean => {
4256
}
4357

4458
const getRequestedLintVersion = (): Version => {
45-
const requestedLintVersion = core.getInput(`version`, { required: true })
59+
const requestedLintVersion = core.getInput(`version`)
4660
const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
61+
if (parsedRequestedLintVersion == null) {
62+
return null
63+
}
4764
if (parsedRequestedLintVersion.patch !== null) {
4865
throw new Error(
4966
`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`
@@ -93,15 +110,14 @@ const getConfig = async (): Promise<Config> => {
93110
export async function findLintVersion(): Promise<VersionConfig> {
94111
core.info(`Finding needed golangci-lint version...`)
95112
const startedAt = Date.now()
96-
const reqLintVersion = getRequestedLintVersion()
97113

98114
const config = await getConfig()
99-
100115
if (!config.MinorVersionToConfig) {
101116
core.warning(JSON.stringify(config))
102117
throw new Error(`invalid config: no MinorVersionToConfig field`)
103118
}
104119

120+
const reqLintVersion = getRequestedLintVersion()
105121
const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)]
106122
if (!versionConfig) {
107123
throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`)

0 commit comments

Comments
 (0)