forked from luarocks/gh-actions-luarocks
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
160 lines (121 loc) · 4.25 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const core = require("@actions/core")
const exec = require("@actions/exec")
const io = require("@actions/io")
const tc = require("@actions/tool-cache")
const fsp = require("fs").promises
const semver = require("semver")
const path = require("path")
const BUILD_PREFIX = ".build-luarocks"
const LUA_PREFIX = ".lua" // default location for existing Lua installation
const LUAROCKS_PREFIX = ".luarocks" // default location for LuaRocks installation
const isWindows = () => (process.platform || "").startsWith("win32")
async function installWindows(luaRocksVersion, tempBuildPath, luaRocksInstallPath, luaPath) {
const binaryZip = await tc.downloadTool(`https://luarocks.org/releases/luarocks-${luaRocksVersion}-windows-64.zip`)
await tc.extractZip(binaryZip, tempBuildPath)
const srcDir = path.join(tempBuildPath, `luarocks-${luaRocksVersion}-windows-64`)
const dstDir = path.join(luaRocksInstallPath, "bin")
await io.mkdirP(dstDir)
for (let file of ["luarocks.exe", "luarocks-admin.exe"]) {
await fsp.copyFile(path.join(srcDir, file), path.join(dstDir, file))
}
let luaVersion = ""
await exec.exec(`lua -e "print(_VERSION:sub(5))"`, undefined, {
listeners: {
stdout: (data) => {
luaVersion += data.toString()
}
}
})
await exec.exec(`luarocks config lua_version ${luaVersion}`, undefined, {})
if (semver.lt(luaRocksVersion, "3.9.2") && !process.env["VCINSTALLDIR"]) {
await exec.exec(`luarocks config variables.CC "x86_64-w64-mingw32-gcc"`, undefined, {})
await exec.exec(`luarocks config variables.LD "x86_64-w64-mingw32-gcc"`, undefined, {})
}
}
async function installUnix(luaRocksVersion, tempBuildPath, luaRocksInstallPath, luaPath) {
const sourceTar = await tc.downloadTool(`https://luarocks.org/releases/luarocks-${luaRocksVersion}.tar.gz`)
await tc.extractTar(sourceTar, path.join(tempBuildPath))
const luaRocksExtractPath = path.join(tempBuildPath, `luarocks-${luaRocksVersion}`)
const configureArgs = [
`--with-lua="${luaPath}"`,
`--prefix="${luaRocksInstallPath}"`
]
await exec.exec(`./configure ${configureArgs.join(" ")}`, undefined, {
cwd: luaRocksExtractPath
})
await exec.exec("make", undefined, {
cwd: luaRocksExtractPath
})
// NOTE: make build step is only necessary for luarocks 2.x
if (luaRocksVersion.match(/^2\./)) {
await exec.exec("make build", undefined, {
cwd: luaRocksExtractPath
})
}
await exec.exec("make install", undefined, {
cwd: luaRocksExtractPath
})
}
async function main() {
const luaRocksVersion = core.getInput('luaRocksVersion', { required: true })
const luaRocksInstallPath = path.join(process.cwd(), LUAROCKS_PREFIX)
const tempBuildPath = path.join(process.env["RUNNER_TEMP"], BUILD_PREFIX)
await io.mkdirP(tempBuildPath)
let luaPath = core.getInput("withLuaPath")
if (!luaPath) {
// NOTE: this is the default install path provided by gh-actions-lua
luaPath = path.join(process.cwd(), LUA_PREFIX)
}
core.addPath(path.join(luaRocksInstallPath, "bin"));
if (isWindows()) {
await installWindows(luaRocksVersion, tempBuildPath, luaRocksInstallPath, luaPath);
} else {
await installUnix(luaRocksVersion, tempBuildPath, luaRocksInstallPath, luaPath);
}
// Update environment to use luarocks directly
let lrBin = ""
await exec.exec("luarocks path --lr-bin", undefined, {
listeners: {
stdout: (data) => {
lrBin += data.toString()
}
}
})
await exec.exec("luarocks path --lr-bin", undefined, {
listeners: {
stdout: (data) => {
lrBin += data.toString()
}
}
})
if (lrBin != "") {
core.addPath(lrBin.trim());
}
let lrPath = ""
await exec.exec("luarocks path --lr-path", undefined, {
listeners: {
stdout: (data) => {
lrPath += data.toString()
}
}
})
lrPath = lrPath.trim()
let lrCpath = ""
await exec.exec("luarocks path --lr-cpath", undefined, {
listeners: {
stdout: (data) => {
lrCpath += data.toString()
}
}
})
lrCpath = lrCpath.trim()
if (lrPath != "") {
core.exportVariable("LUA_PATH", ";;" + lrPath)
}
if (lrCpath != "") {
core.exportVariable("LUA_CPATH", ";;" + lrCpath)
}
}
main().catch(err => {
core.setFailed(`Failed to install LuaRocks: ${err}`);
})