-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgolang.js
91 lines (74 loc) · 3.02 KB
/
golang.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import assert from "assert"
import core from "@actions/core"
import Tool from "./tool.js"
export default class Golang extends Tool {
static tool = "go"
static toolVersion = "go version"
static envVar = "GOENV_ROOT"
static envPaths = ["bin", "shims", "plugins/go-build/bin"]
static installer = "goenv"
constructor() {
super(Golang.tool)
}
// desiredVersion : The desired version of golang, e.g. "1.16.4"
// assumes goenv is already installed on the self-hosted runner, is a failure
// condition otherwise.
async setup(desiredVersion) {
const [checkVersion, isVersionOverridden] = this.getVersion(
desiredVersion,
".go-version",
)
if (!(await this.haveVersion(checkVersion))) {
return checkVersion
}
// Check if goenv exists and can be run, and capture the version info while
// we're at it, should be pre-installed on self-hosted runners.
await this.findInstaller()
/*
if (!io.which("go")) {
// This has to be invoked otherwise it just returns a function
this.logAndExit(`${this.envVar} misconfigured`)()
}
*/
// Set downstream environment variable for future steps in this Job
if (isVersionOverridden) {
core.exportVariable("GOENV_VERSION", checkVersion)
}
// using -s option to skip the install and become a no-op if the
// version requested to be installed is already installed according to goenv.
let installCommand = `goenv install -s`
// goenv install does not pick up the environment variable GOENV_VERSION
// unlike tfenv, so we specify it here as an argument explicitly, if it's set
if (isVersionOverridden) installCommand += ` ${checkVersion}`
await this.subprocessShell(installCommand).catch(
this.logAndExit(`failed to install golang version ${checkVersion}`),
)
// Sanity check that the go command works and its reported version
// matches what we have requested to be in place.
await this.validateVersion(checkVersion)
// If we got this far, we have successfully configured golang.
core.setOutput(Golang.tool, checkVersion)
this.info("golang success!")
return checkVersion
}
async setEnv() {
core.exportVariable("GOENV_SHELL", "bash")
return super.setEnv()
}
/**
* Download and configures goenv.
*
* @param {string} root - Directory to install goenv into (GOENV_ROOT).
* @return {string} The value of GOENV_ROOT.
*/
async install(root) {
assert(root, "root is required")
const gh = `https://${process.env.GITHUB_SERVER || "github.com"}/syndbg`
const url = `${gh}/goenv/archive/refs/heads/master.tar.gz`
root = await this.downloadTool(url, { dest: root, strip: 1 })
this.info(`Downloaded goenv to ${root}`)
return root
}
}
// Register the subclass in our tool list
Golang.register()