Skip to content

Commit 658a19e

Browse files
committed
chore: renaming
1 parent 9aa241a commit 658a19e

File tree

3 files changed

+69
-67
lines changed

3 files changed

+69
-67
lines changed

src/install.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import os from "os"
55
import path from "path"
66
import { promisify } from "util"
77

8-
import { VersionConfig } from "./version"
8+
import { VersionInfo } from "./version"
99

1010
const 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

4142
export 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
}

src/run.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import which from "which"
1111
import { restoreCache, saveCache } from "./cache"
1212
import { installLint, InstallMode } from "./install"
1313
import { alterDiffPatch } from "./utils/diffUtils"
14-
import { findLintVersion } from "./version"
14+
import { getVersion } from "./version"
1515

1616
const execShellCommand = promisify(exec)
1717
const writeFile = promisify(fs.writeFile)
@@ -25,16 +25,16 @@ async function prepareLint(): Promise<string> {
2525
const mode = core.getInput("install-mode").toLowerCase()
2626

2727
if (mode === InstallMode.None) {
28-
const bin = await which("golangci-lint", { nothrow: true })
29-
if (!bin) {
28+
const binPath = await which("golangci-lint", { nothrow: true })
29+
if (!binPath) {
3030
throw new Error("golangci-lint binary not found in the PATH")
3131
}
32-
return bin
32+
return binPath
3333
}
3434

35-
const versionConfig = await findLintVersion(<InstallMode>mode)
35+
const versionInfo = await getVersion(<InstallMode>mode)
3636

37-
return await installLint(versionConfig, <InstallMode>mode)
37+
return await installLint(versionInfo, <InstallMode>mode)
3838
}
3939

4040
async function fetchPatch(): Promise<string> {
@@ -141,7 +141,7 @@ async function fetchPushPatch(ctx: Context): Promise<string> {
141141
}
142142

143143
type Env = {
144-
lintPath: string
144+
binPath: string
145145
patchPath: string
146146
}
147147

@@ -151,12 +151,12 @@ async function prepareEnv(): Promise<Env> {
151151
// Prepare cache, lint and go in parallel.
152152
await restoreCache()
153153

154-
const lintPath = await prepareLint()
154+
const binPath = await prepareLint()
155155
const patchPath = await fetchPatch()
156156

157157
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
158158

159-
return { lintPath, patchPath }
159+
return { binPath: binPath, patchPath }
160160
}
161161

162162
type ExecRes = {
@@ -292,9 +292,9 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
292292

293293
export async function run(): Promise<void> {
294294
try {
295-
const { lintPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
296-
core.addPath(path.dirname(lintPath))
297-
await core.group(`run golangci-lint`, () => runLint(lintPath, patchPath))
295+
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
296+
core.addPath(path.dirname(binPath))
297+
await core.group(`run golangci-lint`, () => runLint(binPath, patchPath))
298298
} catch (error) {
299299
core.error(`Failed to run: ${error}, ${error.stack}`)
300300
core.setFailed(error.message)

src/version.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as core from "@actions/core"
22
import * as httpm from "@actions/http-client"
33
import * as fs from "fs"
4-
import os from "os"
54
import path from "path"
65

76
import { InstallMode } from "./install"
@@ -14,6 +13,7 @@ export type Version = {
1413
} | null
1514

1615
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
16+
// TODO(ldez): it should be updated to match v2 module name.
1717
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/
1818

1919
const parseVersion = (s: string): Version => {
@@ -64,52 +64,52 @@ const isLessVersion = (a: Version, b: Version): boolean => {
6464
return a.minor < b.minor
6565
}
6666

67-
const getRequestedLintVersion = (): Version => {
68-
let requestedLintVersion = core.getInput(`version`)
67+
const getRequestedVersion = (): Version => {
68+
let requestedVersion = core.getInput(`version`)
6969
const workingDirectory = core.getInput(`working-directory`)
7070

7171
let goMod = "go.mod"
7272
if (workingDirectory) {
7373
goMod = path.join(workingDirectory, goMod)
7474
}
7575

76-
if (requestedLintVersion == "" && fs.existsSync(goMod)) {
76+
if (requestedVersion == "" && fs.existsSync(goMod)) {
7777
const content = fs.readFileSync(goMod, "utf-8")
7878
const match = content.match(modVersionRe)
7979
if (match) {
80-
requestedLintVersion = match[1]
81-
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`)
80+
requestedVersion = match[1]
81+
core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`)
8282
}
8383
}
8484

85-
const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
86-
if (parsedRequestedLintVersion == null) {
85+
const parsedRequestedVersion = parseVersion(requestedVersion)
86+
if (parsedRequestedVersion == null) {
8787
return null
8888
}
8989

90-
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
90+
if (isLessVersion(parsedRequestedVersion, minVersion)) {
9191
throw new Error(
92-
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
92+
`requested golangci-lint version '${requestedVersion}' isn't supported: we support only ${stringifyVersion(
9393
minVersion
9494
)} and later versions`
9595
)
9696
}
9797

98-
return parsedRequestedLintVersion
98+
return parsedRequestedVersion
9999
}
100100

101-
export type VersionConfig = {
101+
export type VersionInfo = {
102102
Error?: string
103103
TargetVersion: string
104104
}
105105

106-
type Config = {
106+
type VersionMapping = {
107107
MinorVersionToConfig: {
108-
[minorVersion: string]: VersionConfig
108+
[minorVersion: string]: VersionInfo
109109
}
110110
}
111111

112-
const fetchConfig = async (): Promise<Config> => {
112+
const fetchVersionMapping = async (): Promise<VersionMapping> => {
113113
const http = new httpm.HttpClient(`golangci/golangci-lint-action`, [], {
114114
allowRetries: true,
115115
maxRetries: 5,
@@ -129,7 +129,7 @@ const fetchConfig = async (): Promise<Config> => {
129129
}
130130
}
131131

132-
export async function findLintVersion(mode: InstallMode): Promise<VersionConfig> {
132+
export async function getVersion(mode: InstallMode): Promise<VersionInfo> {
133133
core.info(`Finding needed golangci-lint version...`)
134134

135135
if (mode == InstallMode.GoInstall) {
@@ -138,38 +138,39 @@ export async function findLintVersion(mode: InstallMode): Promise<VersionConfig>
138138
return { TargetVersion: v ? v : "latest" }
139139
}
140140

141-
const reqLintVersion = getRequestedLintVersion()
141+
const reqVersion = getRequestedVersion()
142142

143143
// if the patched version is passed, just use it
144-
if (reqLintVersion?.major === 1 && reqLintVersion?.minor != null && reqLintVersion?.patch !== null) {
144+
// TODO(ldez): should be updated to `reqVersion?.major === 2`.
145+
if (reqVersion?.major === 1 && reqVersion?.minor != null && reqVersion?.patch !== null) {
145146
return new Promise((resolve) => {
146-
const versionWithoutV = `${reqLintVersion.major}.${reqLintVersion.minor}.${reqLintVersion.patch}`
147+
const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}`
147148
resolve({ TargetVersion: `v${versionWithoutV}` })
148149
})
149150
}
150151

151152
const startedAt = Date.now()
152153

153-
const config = await fetchConfig()
154-
if (!config.MinorVersionToConfig) {
155-
core.warning(JSON.stringify(config))
154+
const mapping = await fetchVersionMapping()
155+
if (!mapping.MinorVersionToConfig) {
156+
core.warning(JSON.stringify(mapping))
156157
throw new Error(`invalid config: no MinorVersionToConfig field`)
157158
}
158159

159-
const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)]
160-
if (!versionConfig) {
161-
throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`)
160+
const versionInfo = mapping.MinorVersionToConfig[stringifyVersion(reqVersion)]
161+
if (!versionInfo) {
162+
throw new Error(`requested golangci-lint version '${stringifyVersion(reqVersion)}' doesn't exist`)
162163
}
163164

164-
if (versionConfig.Error) {
165-
throw new Error(`failed to use requested golangci-lint version '${stringifyVersion(reqLintVersion)}': ${versionConfig.Error}`)
165+
if (versionInfo.Error) {
166+
throw new Error(`failed to use requested golangci-lint version '${stringifyVersion(reqVersion)}': ${versionInfo.Error}`)
166167
}
167168

168169
core.info(
169-
`Requested golangci-lint '${stringifyVersion(reqLintVersion)}', using '${versionConfig.TargetVersion}', calculation took ${
170+
`Requested golangci-lint '${stringifyVersion(reqVersion)}', using '${versionInfo.TargetVersion}', calculation took ${
170171
Date.now() - startedAt
171172
}ms`
172173
)
173174

174-
return versionConfig
175+
return versionInfo
175176
}

0 commit comments

Comments
 (0)