Skip to content

Commit

Permalink
feat(version): Support for patch verison (#101)
Browse files Browse the repository at this point in the history
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 <sayboras@yahoo.com>
  • Loading branch information
sayboras authored Oct 17, 2020
1 parent 90fbd40 commit a1c5369
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@ jobs:
version: latest
args: --issues-exit-code=0 ./sample/...
only-new-issues: true

# Test with full version vX.Y.Z
test-full-version:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: ./
with:
version: v1.28.3
args: --issues-exit-code=0 ./sample/...
only-new-issues: true
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: "Official golangci-lint action with line-attached annotations for f
author: "golangci"
inputs:
version:
description: "version of golangci-lint to use in form of v1.2 or `latest` to use the latest version"
description: "version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version"
required: false
args:
description: "golangci-lint command line arguments"
Expand Down
15 changes: 11 additions & 4 deletions dist/post_run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2099,9 +2099,6 @@ const getRequestedLintVersion = () => {
if (parsedRequestedLintVersion == null) {
return null;
}
if (parsedRequestedLintVersion.patch !== null) {
throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
}
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
throw new Error(`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${exports.stringifyVersion(minVersion)} and later versions`);
}
Expand All @@ -2128,13 +2125,23 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
function findLintVersion() {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Finding needed golangci-lint version...`);
const reqLintVersion = getRequestedLintVersion();
// if the patched version is passed, just use it
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) {
return new Promise((resolve) => {
const versionWithoutV = `${reqLintVersion.major}.${reqLintVersion.minor}.${reqLintVersion.patch}`;
resolve({
TargetVersion: `v${versionWithoutV}`,
AssetURL: `https://github.com/golangci/golangci-lint/releases/download/v${versionWithoutV}/golangci-lint-${versionWithoutV}-linux-amd64.tar.gz`,
});
});
}
const startedAt = Date.now();
const config = yield getConfig();
if (!config.MinorVersionToConfig) {
core.warning(JSON.stringify(config));
throw new Error(`invalid config: no MinorVersionToConfig field`);
}
const reqLintVersion = getRequestedLintVersion();
const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
if (!versionConfig) {
throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);
Expand Down
15 changes: 11 additions & 4 deletions dist/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2099,9 +2099,6 @@ const getRequestedLintVersion = () => {
if (parsedRequestedLintVersion == null) {
return null;
}
if (parsedRequestedLintVersion.patch !== null) {
throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
}
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
throw new Error(`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${exports.stringifyVersion(minVersion)} and later versions`);
}
Expand All @@ -2128,13 +2125,23 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
function findLintVersion() {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Finding needed golangci-lint version...`);
const reqLintVersion = getRequestedLintVersion();
// if the patched version is passed, just use it
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) {
return new Promise((resolve) => {
const versionWithoutV = `${reqLintVersion.major}.${reqLintVersion.minor}.${reqLintVersion.patch}`;
resolve({
TargetVersion: `v${versionWithoutV}`,
AssetURL: `https://github.com/golangci/golangci-lint/releases/download/v${versionWithoutV}/golangci-lint-${versionWithoutV}-linux-amd64.tar.gz`,
});
});
}
const startedAt = Date.now();
const config = yield getConfig();
if (!config.MinorVersionToConfig) {
core.warning(JSON.stringify(config));
throw new Error(`invalid config: no MinorVersionToConfig field`);
}
const reqLintVersion = getRequestedLintVersion();
const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
if (!versionConfig) {
throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"all": "npm run prepare-deps && npm run build && npm run format-check && npm run lint",
"local": "npm run build && act -j test -b"
"local": "npm run build && act -j test -b",
"local-full-version": "npm run build && act -j test-full-version -b"
},
"repository": {
"type": "git",
Expand Down
17 changes: 11 additions & 6 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ const getRequestedLintVersion = (): Version => {
if (parsedRequestedLintVersion == null) {
return null
}
if (parsedRequestedLintVersion.patch !== null) {
throw new Error(
`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`
)
}
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
throw new Error(
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
Expand Down Expand Up @@ -109,6 +104,17 @@ const getConfig = async (): Promise<Config> => {

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

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

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

0 comments on commit a1c5369

Please sign in to comment.