@@ -5,21 +5,21 @@ import os from "os"
55import path from "path"
66import { promisify } from "util"
77
8- import { VersionConfig } from "./version"
8+ import { VersionInfo } from "./version"
99
1010const execShellCommand = promisify ( exec )
1111
12- const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
13-
14- const getAssetURL = ( versionConfig : VersionConfig ) : string => {
12+ const getAssetURL = ( versionInfo : VersionInfo ) : string => {
1513 let ext = "tar.gz"
14+
1615 let platform = os . platform ( ) . toString ( )
1716 switch ( platform ) {
1817 case "win32" :
1918 platform = "windows"
2019 ext = "zip"
2120 break
2221 }
22+
2323 let arch = os . arch ( )
2424 switch ( arch ) {
2525 case "arm64" :
@@ -33,9 +33,10 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
3333 arch = "386"
3434 break
3535 }
36- const noPrefix = versionConfig . TargetVersion . slice ( 1 )
3736
38- return `${ downloadURL } /${ versionConfig . TargetVersion } /golangci-lint-${ noPrefix } -${ platform } -${ arch } .${ ext } `
37+ const noPrefix = versionInfo . TargetVersion . slice ( 1 )
38+
39+ return `https://github.com/golangci/golangci-lint/releases/download/${ versionInfo . TargetVersion } /golangci-lint-${ noPrefix } -${ platform } -${ arch } .${ ext } `
3940}
4041
4142export enum InstallMode {
@@ -61,75 +62,75 @@ const printOutput = (res: ExecRes): void => {
6162/**
6263 * Install golangci-lint.
6364 *
64- * @param versionConfig information about version to install.
65+ * @param versionInfo information about version to install.
6566 * @param mode installation mode.
6667 * @returns path to installed binary of golangci-lint.
6768 */
68- export async function installLint ( versionConfig : VersionConfig , mode : InstallMode ) : Promise < string > {
69+ export async function installLint ( versionInfo : VersionInfo , mode : InstallMode ) : Promise < string > {
6970 core . info ( `Installation mode: ${ mode } ` )
7071
7172 switch ( mode ) {
7273 case InstallMode . Binary :
73- return installBin ( versionConfig )
74+ return installBin ( versionInfo )
7475 case InstallMode . GoInstall :
75- return goInstall ( versionConfig )
76+ return goInstall ( versionInfo )
7677 default :
77- return installBin ( versionConfig )
78+ return installBin ( versionInfo )
7879 }
7980}
8081
8182/**
8283 * Install golangci-lint via `go install`.
8384 *
84- * @param versionConfig information about version to install.
85+ * @param versionInfo information about version to install.
8586 * @returns path to installed binary of golangci-lint.
8687 */
87- export async function goInstall ( versionConfig : VersionConfig ) : Promise < string > {
88- core . info ( `Installing golangci-lint ${ versionConfig . TargetVersion } ...` )
88+ export async function goInstall ( versionInfo : VersionInfo ) : Promise < string > {
89+ core . info ( `Installing golangci-lint ${ versionInfo . TargetVersion } ...` )
8990
9091 const startedAt = Date . now ( )
9192
9293 const options : ExecOptions = { env : { ...process . env , CGO_ENABLED : "1" } }
9394
9495 // TODO(ldez): it should be updated for v2.
9596 const exres = await execShellCommand (
96- `go install github.com/golangci/golangci-lint/cmd/golangci-lint@${ versionConfig . TargetVersion } ` ,
97+ `go install github.com/golangci/golangci-lint/cmd/golangci-lint@${ versionInfo . TargetVersion } ` ,
9798 options
9899 )
99100 printOutput ( exres )
100101
101102 // TODO(ldez): it should be updated for v2.
102103 const res = await execShellCommand (
103- `go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${ versionConfig . TargetVersion } ` ,
104+ `go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${ versionInfo . TargetVersion } ` ,
104105 options
105106 )
106107 printOutput ( res )
107108
108109 // The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
109- const lintPath = res . stderr
110+ const binPath = res . stderr
110111 . split ( / \r ? \n / )
111112 . map ( ( v ) => v . trimStart ( ) . trimEnd ( ) )
112113 . filter ( ( v ) => v . startsWith ( "touch " ) )
113114 . reduce ( ( a , b ) => a + b , "" )
114115 . split ( ` ` , 2 ) [ 1 ]
115116
116- core . info ( `Installed golangci-lint into ${ lintPath } in ${ Date . now ( ) - startedAt } ms` )
117+ core . info ( `Installed golangci-lint into ${ binPath } in ${ Date . now ( ) - startedAt } ms` )
117118
118- return lintPath
119+ return binPath
119120}
120121
121122/**
122123 * Install golangci-lint via the precompiled binary.
123124 *
124- * @param versionConfig information about version to install.
125+ * @param versionInfo information about version to install.
125126 * @returns path to installed binary of golangci-lint.
126127 */
127- export async function installBin ( versionConfig : VersionConfig ) : Promise < string > {
128- core . info ( `Installing golangci-lint binary ${ versionConfig . TargetVersion } ...` )
128+ export async function installBin ( versionInfo : VersionInfo ) : Promise < string > {
129+ core . info ( `Installing golangci-lint binary ${ versionInfo . TargetVersion } ...` )
129130
130131 const startedAt = Date . now ( )
131132
132- const assetURL = getAssetURL ( versionConfig )
133+ const assetURL = getAssetURL ( versionInfo )
133134
134135 core . info ( `Downloading binary ${ assetURL } ...` )
135136
@@ -151,9 +152,9 @@ export async function installBin(versionConfig: VersionConfig): Promise<string>
151152
152153 const urlParts = assetURL . split ( `/` )
153154 const dirName = urlParts [ urlParts . length - 1 ] . replace ( repl , `` )
154- const lintPath = path . join ( extractedDir , dirName , `golangci-lint` )
155+ const binPath = path . join ( extractedDir , dirName , `golangci-lint` )
155156
156- core . info ( `Installed golangci-lint into ${ lintPath } in ${ Date . now ( ) - startedAt } ms` )
157+ core . info ( `Installed golangci-lint into ${ binPath } in ${ Date . now ( ) - startedAt } ms` )
157158
158- return lintPath
159+ return binPath
159160}
0 commit comments