Skip to content

Commit a1c5369

Browse files
authored
feat(version): Support for patch verison (#101)
This commit is to support X.Y.Z version in config. - if X.Y.Z version is passed, honour it 👍 - if X.Y version is passed, keep the same behaviour as it is right now. Closes #98 Signed-off-by: Tam Mach <[email protected]>
1 parent 90fbd40 commit a1c5369

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

.github/workflows/test.yml

+17
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,20 @@ jobs:
2929
version: latest
3030
args: --issues-exit-code=0 ./sample/...
3131
only-new-issues: true
32+
33+
# Test with full version vX.Y.Z
34+
test-full-version:
35+
strategy:
36+
matrix:
37+
os:
38+
- ubuntu-latest
39+
- macos-latest
40+
- windows-latest
41+
runs-on: ${{ matrix.os }}
42+
steps:
43+
- uses: actions/checkout@v2
44+
- uses: ./
45+
with:
46+
version: v1.28.3
47+
args: --issues-exit-code=0 ./sample/...
48+
only-new-issues: true

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Official golangci-lint action with line-attached annotations for f
44
author: "golangci"
55
inputs:
66
version:
7-
description: "version of golangci-lint to use in form of v1.2 or `latest` to use the latest version"
7+
description: "version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version"
88
required: false
99
args:
1010
description: "golangci-lint command line arguments"

dist/post_run/index.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -2099,9 +2099,6 @@ const getRequestedLintVersion = () => {
20992099
if (parsedRequestedLintVersion == null) {
21002100
return null;
21012101
}
2102-
if (parsedRequestedLintVersion.patch !== null) {
2103-
throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
2104-
}
21052102
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
21062103
throw new Error(`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${exports.stringifyVersion(minVersion)} and later versions`);
21072104
}
@@ -2128,13 +2125,23 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
21282125
function findLintVersion() {
21292126
return __awaiter(this, void 0, void 0, function* () {
21302127
core.info(`Finding needed golangci-lint version...`);
2128+
const reqLintVersion = getRequestedLintVersion();
2129+
// if the patched version is passed, just use it
2130+
if ((reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.major) !== null && (reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.minor) != null && (reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.patch) !== null) {
2131+
return new Promise((resolve) => {
2132+
const versionWithoutV = `${reqLintVersion.major}.${reqLintVersion.minor}.${reqLintVersion.patch}`;
2133+
resolve({
2134+
TargetVersion: `v${versionWithoutV}`,
2135+
AssetURL: `https://github.com/golangci/golangci-lint/releases/download/v${versionWithoutV}/golangci-lint-${versionWithoutV}-linux-amd64.tar.gz`,
2136+
});
2137+
});
2138+
}
21312139
const startedAt = Date.now();
21322140
const config = yield getConfig();
21332141
if (!config.MinorVersionToConfig) {
21342142
core.warning(JSON.stringify(config));
21352143
throw new Error(`invalid config: no MinorVersionToConfig field`);
21362144
}
2137-
const reqLintVersion = getRequestedLintVersion();
21382145
const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
21392146
if (!versionConfig) {
21402147
throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);

dist/run/index.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -2099,9 +2099,6 @@ const getRequestedLintVersion = () => {
20992099
if (parsedRequestedLintVersion == null) {
21002100
return null;
21012101
}
2102-
if (parsedRequestedLintVersion.patch !== null) {
2103-
throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
2104-
}
21052102
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
21062103
throw new Error(`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${exports.stringifyVersion(minVersion)} and later versions`);
21072104
}
@@ -2128,13 +2125,23 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
21282125
function findLintVersion() {
21292126
return __awaiter(this, void 0, void 0, function* () {
21302127
core.info(`Finding needed golangci-lint version...`);
2128+
const reqLintVersion = getRequestedLintVersion();
2129+
// if the patched version is passed, just use it
2130+
if ((reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.major) !== null && (reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.minor) != null && (reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.patch) !== null) {
2131+
return new Promise((resolve) => {
2132+
const versionWithoutV = `${reqLintVersion.major}.${reqLintVersion.minor}.${reqLintVersion.patch}`;
2133+
resolve({
2134+
TargetVersion: `v${versionWithoutV}`,
2135+
AssetURL: `https://github.com/golangci/golangci-lint/releases/download/v${versionWithoutV}/golangci-lint-${versionWithoutV}-linux-amd64.tar.gz`,
2136+
});
2137+
});
2138+
}
21312139
const startedAt = Date.now();
21322140
const config = yield getConfig();
21332141
if (!config.MinorVersionToConfig) {
21342142
core.warning(JSON.stringify(config));
21352143
throw new Error(`invalid config: no MinorVersionToConfig field`);
21362144
}
2137-
const reqLintVersion = getRequestedLintVersion();
21382145
const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
21392146
if (!versionConfig) {
21402147
throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"format": "prettier --write **/*.ts",
1717
"format-check": "prettier --check **/*.ts",
1818
"all": "npm run prepare-deps && npm run build && npm run format-check && npm run lint",
19-
"local": "npm run build && act -j test -b"
19+
"local": "npm run build && act -j test -b",
20+
"local-full-version": "npm run build && act -j test-full-version -b"
2021
},
2122
"repository": {
2223
"type": "git",

src/version.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ const getRequestedLintVersion = (): Version => {
6161
if (parsedRequestedLintVersion == null) {
6262
return null
6363
}
64-
if (parsedRequestedLintVersion.patch !== null) {
65-
throw new Error(
66-
`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`
67-
)
68-
}
6964
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
7065
throw new Error(
7166
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
@@ -109,6 +104,17 @@ const getConfig = async (): Promise<Config> => {
109104

110105
export async function findLintVersion(): Promise<VersionConfig> {
111106
core.info(`Finding needed golangci-lint version...`)
107+
const reqLintVersion = getRequestedLintVersion()
108+
// if the patched version is passed, just use it
109+
if (reqLintVersion?.major !== null && reqLintVersion?.minor != null && reqLintVersion?.patch !== null) {
110+
return new Promise((resolve) => {
111+
const versionWithoutV = `${reqLintVersion.major}.${reqLintVersion.minor}.${reqLintVersion.patch}`
112+
resolve({
113+
TargetVersion: `v${versionWithoutV}`,
114+
AssetURL: `https://github.com/golangci/golangci-lint/releases/download/v${versionWithoutV}/golangci-lint-${versionWithoutV}-linux-amd64.tar.gz`,
115+
})
116+
})
117+
}
112118
const startedAt = Date.now()
113119

114120
const config = await getConfig()
@@ -117,7 +123,6 @@ export async function findLintVersion(): Promise<VersionConfig> {
117123
throw new Error(`invalid config: no MinorVersionToConfig field`)
118124
}
119125

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

0 commit comments

Comments
 (0)