Support latest tag for golangci-lint version (#64)
This commit is contained in:
		
							parent
							
								
									b026646c83
								
							
						
					
					
						commit
						809d3b078b
					
				
							
								
								
									
										2
									
								
								.github/workflows/test.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/test.yml
									
									
									
									
										vendored
									
									
								
							@ -20,6 +20,6 @@ jobs:
 | 
				
			|||||||
      - uses: actions/checkout@v2
 | 
					      - uses: actions/checkout@v2
 | 
				
			||||||
      - uses: ./
 | 
					      - uses: ./
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          version: v1.29
 | 
					          version: latest
 | 
				
			||||||
          args: --issues-exit-code=0 ./sample/...
 | 
					          args: --issues-exit-code=0 ./sample/...
 | 
				
			||||||
          only-new-issues: true
 | 
					          only-new-issues: true
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										30
									
								
								action.yml
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								action.yml
									
									
									
									
									
								
							@ -1,31 +1,31 @@
 | 
				
			|||||||
---
 | 
					---
 | 
				
			||||||
name: 'Run golangci-lint'
 | 
					name: "Run golangci-lint"
 | 
				
			||||||
description: 'Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution.'
 | 
					description: "Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution."
 | 
				
			||||||
author: 'golangci'
 | 
					author: "golangci"
 | 
				
			||||||
inputs:
 | 
					inputs:
 | 
				
			||||||
  version:
 | 
					  version:
 | 
				
			||||||
    description: 'version of golangci-lint to use in form of v1.2'
 | 
					    description: "version of golangci-lint to use in form of v1.2 or `latest` to use the latest version"
 | 
				
			||||||
    required: true
 | 
					    required: false
 | 
				
			||||||
  args:
 | 
					  args:
 | 
				
			||||||
    description: 'golangci-lint command line arguments'
 | 
					    description: "golangci-lint command line arguments"
 | 
				
			||||||
    default: ''
 | 
					    default: ""
 | 
				
			||||||
    required: false
 | 
					    required: false
 | 
				
			||||||
  working-directory:
 | 
					  working-directory:
 | 
				
			||||||
    description: 'golangci-lint working directory, default is project root'
 | 
					    description: "golangci-lint working directory, default is project root"
 | 
				
			||||||
    required: false
 | 
					    required: false
 | 
				
			||||||
  github-token:
 | 
					  github-token:
 | 
				
			||||||
    description: 'the token is used for fetching patch of a pull request to show only new issues'
 | 
					    description: "the token is used for fetching patch of a pull request to show only new issues"
 | 
				
			||||||
    default: ${{ github.token }}
 | 
					    default: ${{ github.token }}
 | 
				
			||||||
    required: true
 | 
					    required: true
 | 
				
			||||||
  only-new-issues:
 | 
					  only-new-issues:
 | 
				
			||||||
    description: 'if set to true and the action runs on a pull request - the action outputs only newly found issues'
 | 
					    description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"
 | 
				
			||||||
    default: false
 | 
					    default: false
 | 
				
			||||||
    required: true
 | 
					    required: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
runs:
 | 
					runs:
 | 
				
			||||||
  using: 'node12'
 | 
					  using: "node12"
 | 
				
			||||||
  main: 'dist/run/index.js'
 | 
					  main: "dist/run/index.js"
 | 
				
			||||||
  post: 'dist/post_run/index.js'
 | 
					  post: "dist/post_run/index.js"
 | 
				
			||||||
branding:
 | 
					branding:
 | 
				
			||||||
  icon: 'shield'
 | 
					  icon: "shield"
 | 
				
			||||||
  color: 'yellow'
 | 
					  color: "yellow"
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								dist/post_run/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								dist/post_run/index.js
									
									
									
									
										vendored
									
									
								
							@ -2019,6 +2019,9 @@ const core = __importStar(__webpack_require__(470));
 | 
				
			|||||||
const httpm = __importStar(__webpack_require__(539));
 | 
					const httpm = __importStar(__webpack_require__(539));
 | 
				
			||||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
 | 
					const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
 | 
				
			||||||
const parseVersion = (s) => {
 | 
					const parseVersion = (s) => {
 | 
				
			||||||
 | 
					    if (s == "latest" || s == "") {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    const match = s.match(versionRe);
 | 
					    const match = s.match(versionRe);
 | 
				
			||||||
    if (!match) {
 | 
					    if (!match) {
 | 
				
			||||||
        throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`);
 | 
					        throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`);
 | 
				
			||||||
@ -2029,13 +2032,24 @@ const parseVersion = (s) => {
 | 
				
			|||||||
        patch: match[3] === undefined ? null : parseInt(match[3]),
 | 
					        patch: match[3] === undefined ? null : parseInt(match[3]),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
exports.stringifyVersion = (v) => `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`;
 | 
					exports.stringifyVersion = (v) => {
 | 
				
			||||||
 | 
					    if (v == null) {
 | 
				
			||||||
 | 
					        return "latest";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
const minVersion = {
 | 
					const minVersion = {
 | 
				
			||||||
    major: 1,
 | 
					    major: 1,
 | 
				
			||||||
    minor: 28,
 | 
					    minor: 28,
 | 
				
			||||||
    patch: 3,
 | 
					    patch: 3,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
const isLessVersion = (a, b) => {
 | 
					const isLessVersion = (a, b) => {
 | 
				
			||||||
 | 
					    if (a == null) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (b == null) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (a.major != b.major) {
 | 
					    if (a.major != b.major) {
 | 
				
			||||||
        return a.major < b.major;
 | 
					        return a.major < b.major;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -2044,8 +2058,11 @@ const isLessVersion = (a, b) => {
 | 
				
			|||||||
    return a.minor < b.minor;
 | 
					    return a.minor < b.minor;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
const getRequestedLintVersion = () => {
 | 
					const getRequestedLintVersion = () => {
 | 
				
			||||||
    const requestedLintVersion = core.getInput(`version`, { required: true });
 | 
					    const requestedLintVersion = core.getInput(`version`);
 | 
				
			||||||
    const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
 | 
					    const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
 | 
				
			||||||
 | 
					    if (parsedRequestedLintVersion == null) {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (parsedRequestedLintVersion.patch !== null) {
 | 
					    if (parsedRequestedLintVersion.patch !== null) {
 | 
				
			||||||
        throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
 | 
					        throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -2076,12 +2093,12 @@ function findLintVersion() {
 | 
				
			|||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
        core.info(`Finding needed golangci-lint version...`);
 | 
					        core.info(`Finding needed golangci-lint version...`);
 | 
				
			||||||
        const startedAt = Date.now();
 | 
					        const startedAt = Date.now();
 | 
				
			||||||
        const reqLintVersion = getRequestedLintVersion();
 | 
					 | 
				
			||||||
        const config = yield getConfig();
 | 
					        const config = yield getConfig();
 | 
				
			||||||
        if (!config.MinorVersionToConfig) {
 | 
					        if (!config.MinorVersionToConfig) {
 | 
				
			||||||
            core.warning(JSON.stringify(config));
 | 
					            core.warning(JSON.stringify(config));
 | 
				
			||||||
            throw new Error(`invalid config: no MinorVersionToConfig field`);
 | 
					            throw new Error(`invalid config: no MinorVersionToConfig field`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        const reqLintVersion = getRequestedLintVersion();
 | 
				
			||||||
        const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
 | 
					        const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
 | 
				
			||||||
        if (!versionConfig) {
 | 
					        if (!versionConfig) {
 | 
				
			||||||
            throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);
 | 
					            throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								dist/run/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								dist/run/index.js
									
									
									
									
										vendored
									
									
								
							@ -2019,6 +2019,9 @@ const core = __importStar(__webpack_require__(470));
 | 
				
			|||||||
const httpm = __importStar(__webpack_require__(539));
 | 
					const httpm = __importStar(__webpack_require__(539));
 | 
				
			||||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
 | 
					const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
 | 
				
			||||||
const parseVersion = (s) => {
 | 
					const parseVersion = (s) => {
 | 
				
			||||||
 | 
					    if (s == "latest" || s == "") {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    const match = s.match(versionRe);
 | 
					    const match = s.match(versionRe);
 | 
				
			||||||
    if (!match) {
 | 
					    if (!match) {
 | 
				
			||||||
        throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`);
 | 
					        throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`);
 | 
				
			||||||
@ -2029,13 +2032,24 @@ const parseVersion = (s) => {
 | 
				
			|||||||
        patch: match[3] === undefined ? null : parseInt(match[3]),
 | 
					        patch: match[3] === undefined ? null : parseInt(match[3]),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
exports.stringifyVersion = (v) => `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`;
 | 
					exports.stringifyVersion = (v) => {
 | 
				
			||||||
 | 
					    if (v == null) {
 | 
				
			||||||
 | 
					        return "latest";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
const minVersion = {
 | 
					const minVersion = {
 | 
				
			||||||
    major: 1,
 | 
					    major: 1,
 | 
				
			||||||
    minor: 28,
 | 
					    minor: 28,
 | 
				
			||||||
    patch: 3,
 | 
					    patch: 3,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
const isLessVersion = (a, b) => {
 | 
					const isLessVersion = (a, b) => {
 | 
				
			||||||
 | 
					    if (a == null) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (b == null) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (a.major != b.major) {
 | 
					    if (a.major != b.major) {
 | 
				
			||||||
        return a.major < b.major;
 | 
					        return a.major < b.major;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -2044,8 +2058,11 @@ const isLessVersion = (a, b) => {
 | 
				
			|||||||
    return a.minor < b.minor;
 | 
					    return a.minor < b.minor;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
const getRequestedLintVersion = () => {
 | 
					const getRequestedLintVersion = () => {
 | 
				
			||||||
    const requestedLintVersion = core.getInput(`version`, { required: true });
 | 
					    const requestedLintVersion = core.getInput(`version`);
 | 
				
			||||||
    const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
 | 
					    const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
 | 
				
			||||||
 | 
					    if (parsedRequestedLintVersion == null) {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (parsedRequestedLintVersion.patch !== null) {
 | 
					    if (parsedRequestedLintVersion.patch !== null) {
 | 
				
			||||||
        throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
 | 
					        throw new Error(`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -2076,12 +2093,12 @@ function findLintVersion() {
 | 
				
			|||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
        core.info(`Finding needed golangci-lint version...`);
 | 
					        core.info(`Finding needed golangci-lint version...`);
 | 
				
			||||||
        const startedAt = Date.now();
 | 
					        const startedAt = Date.now();
 | 
				
			||||||
        const reqLintVersion = getRequestedLintVersion();
 | 
					 | 
				
			||||||
        const config = yield getConfig();
 | 
					        const config = yield getConfig();
 | 
				
			||||||
        if (!config.MinorVersionToConfig) {
 | 
					        if (!config.MinorVersionToConfig) {
 | 
				
			||||||
            core.warning(JSON.stringify(config));
 | 
					            core.warning(JSON.stringify(config));
 | 
				
			||||||
            throw new Error(`invalid config: no MinorVersionToConfig field`);
 | 
					            throw new Error(`invalid config: no MinorVersionToConfig field`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        const reqLintVersion = getRequestedLintVersion();
 | 
				
			||||||
        const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
 | 
					        const versionConfig = config.MinorVersionToConfig[exports.stringifyVersion(reqLintVersion)];
 | 
				
			||||||
        if (!versionConfig) {
 | 
					        if (!versionConfig) {
 | 
				
			||||||
            throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);
 | 
					            throw new Error(`requested golangci-lint version '${exports.stringifyVersion(reqLintVersion)}' doesn't exist`);
 | 
				
			||||||
 | 
				
			|||||||
@ -6,11 +6,14 @@ export type Version = {
 | 
				
			|||||||
  major: number
 | 
					  major: number
 | 
				
			||||||
  minor: number
 | 
					  minor: number
 | 
				
			||||||
  patch: number | null
 | 
					  patch: number | null
 | 
				
			||||||
}
 | 
					} | null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
 | 
					const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const parseVersion = (s: string): Version => {
 | 
					const parseVersion = (s: string): Version => {
 | 
				
			||||||
 | 
					  if (s == "latest" || s == "") {
 | 
				
			||||||
 | 
					    return null
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  const match = s.match(versionRe)
 | 
					  const match = s.match(versionRe)
 | 
				
			||||||
  if (!match) {
 | 
					  if (!match) {
 | 
				
			||||||
    throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
 | 
					    throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
 | 
				
			||||||
@ -23,7 +26,12 @@ const parseVersion = (s: string): Version => {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const stringifyVersion = (v: Version): string => `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`
 | 
					export const stringifyVersion = (v: Version): string => {
 | 
				
			||||||
 | 
					  if (v == null) {
 | 
				
			||||||
 | 
					    return "latest"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const minVersion = {
 | 
					const minVersion = {
 | 
				
			||||||
  major: 1,
 | 
					  major: 1,
 | 
				
			||||||
@ -32,6 +40,12 @@ const minVersion = {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const isLessVersion = (a: Version, b: Version): boolean => {
 | 
					const isLessVersion = (a: Version, b: Version): boolean => {
 | 
				
			||||||
 | 
					  if (a == null) {
 | 
				
			||||||
 | 
					    return true
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (b == null) {
 | 
				
			||||||
 | 
					    return false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  if (a.major != b.major) {
 | 
					  if (a.major != b.major) {
 | 
				
			||||||
    return a.major < b.major
 | 
					    return a.major < b.major
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -42,8 +56,11 @@ const isLessVersion = (a: Version, b: Version): boolean => {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getRequestedLintVersion = (): Version => {
 | 
					const getRequestedLintVersion = (): Version => {
 | 
				
			||||||
  const requestedLintVersion = core.getInput(`version`, { required: true })
 | 
					  const requestedLintVersion = core.getInput(`version`)
 | 
				
			||||||
  const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
 | 
					  const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
 | 
				
			||||||
 | 
					  if (parsedRequestedLintVersion == null) {
 | 
				
			||||||
 | 
					    return null
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  if (parsedRequestedLintVersion.patch !== null) {
 | 
					  if (parsedRequestedLintVersion.patch !== null) {
 | 
				
			||||||
    throw new Error(
 | 
					    throw new Error(
 | 
				
			||||||
      `requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`
 | 
					      `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> => {
 | 
				
			|||||||
export async function findLintVersion(): Promise<VersionConfig> {
 | 
					export async function findLintVersion(): Promise<VersionConfig> {
 | 
				
			||||||
  core.info(`Finding needed golangci-lint version...`)
 | 
					  core.info(`Finding needed golangci-lint version...`)
 | 
				
			||||||
  const startedAt = Date.now()
 | 
					  const startedAt = Date.now()
 | 
				
			||||||
  const reqLintVersion = getRequestedLintVersion()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const config = await getConfig()
 | 
					  const config = await getConfig()
 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (!config.MinorVersionToConfig) {
 | 
					  if (!config.MinorVersionToConfig) {
 | 
				
			||||||
    core.warning(JSON.stringify(config))
 | 
					    core.warning(JSON.stringify(config))
 | 
				
			||||||
    throw new Error(`invalid config: no MinorVersionToConfig field`)
 | 
					    throw new Error(`invalid config: no MinorVersionToConfig field`)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const reqLintVersion = getRequestedLintVersion()
 | 
				
			||||||
  const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)]
 | 
					  const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)]
 | 
				
			||||||
  if (!versionConfig) {
 | 
					  if (!versionConfig) {
 | 
				
			||||||
    throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`)
 | 
					    throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user