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: ./ | ||||
|         with: | ||||
|           version: v1.29 | ||||
|           version: latest | ||||
|           args: --issues-exit-code=0 ./sample/... | ||||
|           only-new-issues: true | ||||
|  | ||||
							
								
								
									
										30
									
								
								action.yml
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								action.yml
									
									
									
									
									
								
							| @ -1,31 +1,31 @@ | ||||
| --- | ||||
| name: 'Run golangci-lint' | ||||
| description: 'Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution.' | ||||
| author: 'golangci' | ||||
| name: "Run golangci-lint" | ||||
| description: "Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution." | ||||
| author: "golangci" | ||||
| inputs: | ||||
|   version: | ||||
|     description: 'version of golangci-lint to use in form of v1.2' | ||||
|     required: true | ||||
|     description: "version of golangci-lint to use in form of v1.2 or `latest` to use the latest version" | ||||
|     required: false | ||||
|   args: | ||||
|     description: 'golangci-lint command line arguments' | ||||
|     default: '' | ||||
|     description: "golangci-lint command line arguments" | ||||
|     default: "" | ||||
|     required: false | ||||
|   working-directory: | ||||
|     description: 'golangci-lint working directory, default is project root' | ||||
|     description: "golangci-lint working directory, default is project root" | ||||
|     required: false | ||||
|   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 }} | ||||
|     required: true | ||||
|   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 | ||||
|     required: true | ||||
| 
 | ||||
| runs: | ||||
|   using: 'node12' | ||||
|   main: 'dist/run/index.js' | ||||
|   post: 'dist/post_run/index.js' | ||||
|   using: "node12" | ||||
|   main: "dist/run/index.js" | ||||
|   post: "dist/post_run/index.js" | ||||
| branding: | ||||
|   icon: 'shield' | ||||
|   color: 'yellow' | ||||
|   icon: "shield" | ||||
|   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 versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/; | ||||
| const parseVersion = (s) => { | ||||
|     if (s == "latest" || s == "") { | ||||
|         return null; | ||||
|     } | ||||
|     const match = s.match(versionRe); | ||||
|     if (!match) { | ||||
|         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]), | ||||
|     }; | ||||
| }; | ||||
| 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 = { | ||||
|     major: 1, | ||||
|     minor: 28, | ||||
|     patch: 3, | ||||
| }; | ||||
| const isLessVersion = (a, b) => { | ||||
|     if (a == null) { | ||||
|         return true; | ||||
|     } | ||||
|     if (b == null) { | ||||
|         return false; | ||||
|     } | ||||
|     if (a.major != b.major) { | ||||
|         return a.major < b.major; | ||||
|     } | ||||
| @ -2044,8 +2058,11 @@ const isLessVersion = (a, b) => { | ||||
|     return a.minor < b.minor; | ||||
| }; | ||||
| const getRequestedLintVersion = () => { | ||||
|     const requestedLintVersion = core.getInput(`version`, { required: true }); | ||||
|     const requestedLintVersion = core.getInput(`version`); | ||||
|     const parsedRequestedLintVersion = parseVersion(requestedLintVersion); | ||||
|     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`); | ||||
|     } | ||||
| @ -2076,12 +2093,12 @@ function findLintVersion() { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         core.info(`Finding needed golangci-lint version...`); | ||||
|         const startedAt = Date.now(); | ||||
|         const reqLintVersion = getRequestedLintVersion(); | ||||
|         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`); | ||||
|  | ||||
							
								
								
									
										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 versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/; | ||||
| const parseVersion = (s) => { | ||||
|     if (s == "latest" || s == "") { | ||||
|         return null; | ||||
|     } | ||||
|     const match = s.match(versionRe); | ||||
|     if (!match) { | ||||
|         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]), | ||||
|     }; | ||||
| }; | ||||
| 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 = { | ||||
|     major: 1, | ||||
|     minor: 28, | ||||
|     patch: 3, | ||||
| }; | ||||
| const isLessVersion = (a, b) => { | ||||
|     if (a == null) { | ||||
|         return true; | ||||
|     } | ||||
|     if (b == null) { | ||||
|         return false; | ||||
|     } | ||||
|     if (a.major != b.major) { | ||||
|         return a.major < b.major; | ||||
|     } | ||||
| @ -2044,8 +2058,11 @@ const isLessVersion = (a, b) => { | ||||
|     return a.minor < b.minor; | ||||
| }; | ||||
| const getRequestedLintVersion = () => { | ||||
|     const requestedLintVersion = core.getInput(`version`, { required: true }); | ||||
|     const requestedLintVersion = core.getInput(`version`); | ||||
|     const parsedRequestedLintVersion = parseVersion(requestedLintVersion); | ||||
|     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`); | ||||
|     } | ||||
| @ -2076,12 +2093,12 @@ function findLintVersion() { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         core.info(`Finding needed golangci-lint version...`); | ||||
|         const startedAt = Date.now(); | ||||
|         const reqLintVersion = getRequestedLintVersion(); | ||||
|         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`); | ||||
|  | ||||
| @ -6,11 +6,14 @@ export type Version = { | ||||
|   major: number | ||||
|   minor: number | ||||
|   patch: number | null | ||||
| } | ||||
| } | null | ||||
| 
 | ||||
| const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/ | ||||
| 
 | ||||
| const parseVersion = (s: string): Version => { | ||||
|   if (s == "latest" || s == "") { | ||||
|     return null | ||||
|   } | ||||
|   const match = s.match(versionRe) | ||||
|   if (!match) { | ||||
|     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 = { | ||||
|   major: 1, | ||||
| @ -32,6 +40,12 @@ const minVersion = { | ||||
| } | ||||
| 
 | ||||
| const isLessVersion = (a: Version, b: Version): boolean => { | ||||
|   if (a == null) { | ||||
|     return true | ||||
|   } | ||||
|   if (b == null) { | ||||
|     return false | ||||
|   } | ||||
|   if (a.major != b.major) { | ||||
|     return a.major < b.major | ||||
|   } | ||||
| @ -42,8 +56,11 @@ const isLessVersion = (a: Version, b: Version): boolean => { | ||||
| } | ||||
| 
 | ||||
| const getRequestedLintVersion = (): Version => { | ||||
|   const requestedLintVersion = core.getInput(`version`, { required: true }) | ||||
|   const requestedLintVersion = core.getInput(`version`) | ||||
|   const parsedRequestedLintVersion = parseVersion(requestedLintVersion) | ||||
|   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` | ||||
| @ -93,15 +110,14 @@ const getConfig = async (): Promise<Config> => { | ||||
| export async function findLintVersion(): Promise<VersionConfig> { | ||||
|   core.info(`Finding needed golangci-lint version...`) | ||||
|   const startedAt = Date.now() | ||||
|   const reqLintVersion = getRequestedLintVersion() | ||||
| 
 | ||||
|   const config = await getConfig() | ||||
| 
 | ||||
|   if (!config.MinorVersionToConfig) { | ||||
|     core.warning(JSON.stringify(config)) | ||||
|     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`) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Sergey Vilgelm
						Sergey Vilgelm