From 2069dff6c9b64e3b7bc7817a62057814b9d92284 Mon Sep 17 00:00:00 2001 From: dwenegar Date: Sun, 14 Mar 2021 09:13:25 +0900 Subject: [PATCH] refactor --- .prettierrc.json | 2 +- action.yml | 3 + dist/index.js | 263 ++++++++++++------------------- lib/constants.js | 1 + lib/input-helper.js | 4 +- lib/installer.js | 169 ++++++-------------- lib/setup-lua.js | 85 +++++----- package-lock.json | 366 ++++++++++++++++++++++++++++++++++++++++---- package.json | 9 +- src/constants.ts | 3 +- src/input-helper.ts | 4 +- src/inputs.ts | 1 + src/installer.ts | 160 ++++++------------- src/setup-lua.ts | 36 +++-- tsconfig.json | 4 +- 15 files changed, 616 insertions(+), 494 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index b1d097b..6b9d343 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -8,4 +8,4 @@ "bracketSpacing": false, "arrowParens": "avoid", "parser": "typescript" - } \ No newline at end of file + } diff --git a/action.yml b/action.yml index f8e6673..a09cbc8 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,9 @@ branding: icon: moon color: blue inputs: + repo-token: + description: 'The GITHUB_TOKEN secret' + required: false lua-version: description: 'Lua version to use.' required: false diff --git a/dist/index.js b/dist/index.js index ba3397e..0579268 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1084,6 +1084,7 @@ var InputNames; (function (InputNames) { InputNames["LuaVersion"] = "lua-version"; InputNames["LuarocksVersion"] = "luarocks-version"; + InputNames["RepoToken"] = "repo-token"; })(InputNames = exports.InputNames || (exports.InputNames = {})); @@ -1472,19 +1473,10 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupLua = void 0; const core = __importStar(__webpack_require__(470)); @@ -1493,43 +1485,47 @@ const installer_1 = __webpack_require__(749); const path_1 = __webpack_require__(622); const child_process_1 = __webpack_require__(129); const sys = __importStar(__webpack_require__(737)); -function setupLua() { - return __awaiter(this, void 0, void 0, function* () { - try { - const inputs = input_helper_1.getInputs(); - const installPrefix = path_1.join(process.cwd(), '.install'); - const luaInstallPath = path_1.join(installPrefix); - const luarocksInstallPath = path_1.join(installPrefix, 'luarocks'); - const luaVersion = inputs.luaVersion; - core.info(`Setup Lua version ${luaVersion}`); - const luaPath = yield installer_1.installLua(luaVersion, luaInstallPath); - const luaBinPath = path_1.join(luaPath, 'bin'); - core.addPath(luaBinPath); - core.info(`Added ${luaBinPath} to the path`); - const luarocksVersion = inputs.luarocksVersion; - if (luarocksVersion) { - core.info(`Setup Luarocks version ${luarocksVersion}`); - const luarocksPath = yield installer_1.installLuarocks(luarocksVersion, luarocksInstallPath, luaPath); - const platform = sys.getPlatform(); - const luarocksBinPath = platform === 'windows' ? luarocksPath : path_1.join(luarocksPath, 'bin'); - core.addPath(luarocksBinPath); - core.info(`Added ${luarocksBinPath} to the path`); - let luarocksSystemPath = child_process_1.execSync('luarocks path --lr-bin', { encoding: 'utf-8' }).trim(); - core.addPath(luarocksSystemPath); - core.info(`Added ${luarocksSystemPath} to the path`); - let luarocksLuaPath = child_process_1.execSync('luarocks path --lr-path', { encoding: 'utf-8' }).trim(); - core.exportVariable('LUA_PATH', ';;' + luarocksLuaPath); - core.info(`Set LUA_PATH to ${luarocksLuaPath}`); - let luarocksLuaCPath = child_process_1.execSync('luarocks path --lr-cpath', { encoding: 'utf-8' }).trim(); - core.exportVariable('LUA_CPATH', ';;' + luarocksLuaCPath); - core.info(`Set LUA_CPATH to ${luarocksLuaCPath}`); - core.info(`Successfully setup Luarocks ${luarocksVersion}`); - } - } - catch (error) { - core.setFailed(error.message); - } - }); +function exportVariable(name, value) { + core.exportVariable(name, value); + core.info(`Set ${name} to ${process.env[name]}`); +} +function addPath(value) { + core.addPath(value); + core.info(`Added ${value} to PATH`); +} +async function setupLua() { + try { + const inputs = input_helper_1.getInputs(); + const platform = sys.getPlatform(); + const installPrefix = path_1.join(process.cwd(), '.install'); + const luaInstallPath = path_1.join(installPrefix); + const luarocksInstallPath = path_1.join(installPrefix, 'luarocks'); + const luaVersion = inputs.luaVersion; + core.info(`Setup Lua version ${luaVersion}`); + const luaPath = await installer_1.installLua(inputs.repoToken, luaVersion, luaInstallPath); + const luaBinPath = path_1.join(luaPath, 'bin'); + addPath(luaBinPath); + if (platform == 'linux' || platform == 'darwin') { + exportVariable('LD_LIBRARY_PATH', luaBinPath); + } + const luarocksVersion = inputs.luarocksVersion; + if (luarocksVersion) { + core.info(`Setup Luarocks version ${luarocksVersion}`); + const luarocksPath = await installer_1.installLuarocks(inputs.repoToken, luarocksVersion, luarocksInstallPath, luaPath); + const luarocksBinPath = platform === 'windows' ? luarocksPath : path_1.join(luarocksPath, 'bin'); + addPath(luarocksBinPath); + let luarocksSystemPath = child_process_1.execSync('luarocks path --lr-bin', { encoding: 'utf-8' }).trim(); + addPath(luarocksSystemPath); + let luarocksLuaPath = child_process_1.execSync('luarocks path --lr-path', { encoding: 'utf-8' }).trim(); + exportVariable('LUA_PATH', luarocksLuaPath); + let luarocksLuaCPath = child_process_1.execSync('luarocks path --lr-cpath', { encoding: 'utf-8' }).trim(); + exportVariable('LUA_CPATH', luarocksLuaCPath); + core.info(`Successfully setup Luarocks ${luarocksVersion}`); + } + } + catch (error) { + core.setFailed(error.message); + } } exports.setupLua = setupLua; @@ -4999,146 +4995,77 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.installLuarocks = exports.installLua = void 0; const tc = __importStar(__webpack_require__(533)); const core = __importStar(__webpack_require__(470)); const exec = __importStar(__webpack_require__(986)); -const httpm = __importStar(__webpack_require__(539)); const path = __importStar(__webpack_require__(622)); const os = __importStar(__webpack_require__(87)); const sys = __importStar(__webpack_require__(737)); -function installLua(version, installPath) { - return __awaiter(this, void 0, void 0, function* () { - const arch = sys.getArch(); - const platform = sys.getPlatform(); - core.info(`Attempting to download Lua ${version}`); - const info = yield getLuaDownloadInfo(version, platform, arch); - if (!info) { - throw new Error(`Unable to find Lua version '${version}' for platform ${platform} and architecture ${arch}.`); - } - try { - core.info('Installing from archive'); - return yield installLuaVersion(info, installPath); - } - catch (err) { - throw new Error(`Failed to download version ${version}: ${err}`); - } - }); +async function extractArchive(archivePath, destPath) { + const archiveSuffix = sys.getArchiveSuffix(); + if (archiveSuffix === 'zip') { + return await tc.extractZip(archivePath, destPath); + } + return await tc.extractTar(archivePath, destPath); +} +function getLuaDownloadUrl(version) { + const platform = sys.getPlatform(); + const arch = sys.getArch(); + const archiveSuffix = sys.getArchiveSuffix(); + const targetAssetName = `lua-${version}-${platform}-${arch}.${archiveSuffix}`; + return `https://github.com/luadevkit/versions/releases/download/v${version}/${targetAssetName}`; +} +function getLuarocksDownloadUrl(version) { + const archiveSuffix = sys.getArchiveSuffix(); + const targetAssetName = `v${version}.${archiveSuffix}`; + return `https://github.com/luarocks/luarocks/archive/${targetAssetName}`; +} +async function installLua(authToken, version, installPath) { + try { + core.info(`Attempting to install Lua ${version}`); + const url = getLuaDownloadUrl(version); + core.info(`Downloading Lua ${version} from ${url}`); + const downloadPath = await tc.downloadTool(url, undefined, authToken); + return await extractArchive(downloadPath, path.join(installPath, 'lua')); + } + catch (err) { + throw new Error(`Failed to install Lua version ${version}: ${err}`); + } } exports.installLua = installLua; -function installLuarocks(version, installPath, luaPath) { - return __awaiter(this, void 0, void 0, function* () { - core.info(`Attempting to download Luarocks ${version}`); - const info = yield getLuarocksDownloadInfo(version); - if (!info) { - throw new Error(`Unable to find Luarocks version '${version}'.`); - } - try { - core.info('Installing from archive'); - return yield installLuarocksVersion(info, installPath, luaPath); - } - catch (err) { - throw new Error(`Failed to download version ${version}: ${err}`); - } - }); -} -exports.installLuarocks = installLuarocks; -function installLuaVersion(info, installPath) { - return __awaiter(this, void 0, void 0, function* () { - core.info(`Downloading Lua ${info.version} from ${info.url}`); - const downloadPath = yield tc.downloadTool(info.url); - const extractionPath = yield extractArchive(downloadPath, path.join(installPath, 'lua')); - core.info(`Extracted Lua to ${extractionPath}`); - return extractionPath; - }); +async function execIn(cmd, cwd) { + await exec.exec(cmd, undefined, { cwd: cwd }); } -function installLuarocksVersion(info, installPath, luaPath) { - return __awaiter(this, void 0, void 0, function* () { - core.info(`Downloading Luarocks ${info.version} from ${info.url}`); - const downloadPath = yield tc.downloadTool(info.url); - const extractionPath = yield extractArchive(downloadPath, os.tmpdir()); - core.info(`Extracted Luarocks to ${extractionPath}`); - const sourcePath = path.join(extractionPath, `luarocks-${info.version}`); +async function installLuarocks(authToken, version, installPath, luaPath) { + try { + core.info(`Attempting to install Luarocks ${version}`); + const url = getLuarocksDownloadUrl(version); + core.info(`Downloading Luarocks ${version} from ${url}`); + const downloadPath = await tc.downloadTool(url, undefined, authToken); + const extractionPath = await extractArchive(downloadPath, os.tmpdir()); + const sourcePath = path.join(extractionPath, `luarocks-${version}`); const platform = sys.getPlatform(); if (platform === 'windows') { - yield execIn(`.\\install.bat /P ${installPath} /SELFCONTAINED /LUA ${luaPath} /NOREG /NOADMIN /Q`, sourcePath); + await execIn(`.\\install.bat /P ${installPath} /SELFCONTAINED /LUA ${luaPath} /NOREG /NOADMIN /Q`, sourcePath); } else { - yield execIn(`./configure --prefix=${installPath} --with-lua=${luaPath}`, sourcePath); - yield execIn('make -s', sourcePath); - yield execIn('make -s install', sourcePath); + await execIn(`./configure --prefix=${installPath} --with-lua=${luaPath}`, sourcePath); + await execIn('make -s', sourcePath); + await execIn('make -s install', sourcePath); } return installPath; - }); -} -function extractArchive(archivePath, destPath) { - return __awaiter(this, void 0, void 0, function* () { - const archiveSuffix = sys.getArchiveSuffix(); - if (archiveSuffix === 'zip') { - return yield tc.extractZip(archivePath, destPath); - } - return yield tc.extractTar(archivePath, destPath); - }); -} -function getGitHubRelease(releaseUrl) { - return __awaiter(this, void 0, void 0, function* () { - const http = new httpm.HttpClient('setup-lua', [], { - allowRedirects: true, - maxRedirects: 3 - }); - const response = yield http.getJson(releaseUrl); - return response.result; - }); -} -function getLuaDownloadInfo(version, platform, arch) { - return __awaiter(this, void 0, void 0, function* () { - const releaseUrl = `https://api.github.com/repos/luadevkit/build/releases/tags/v${version}`; - const githubRelease = yield getGitHubRelease(releaseUrl); - if (!githubRelease) { - return; - } - const archiveSuffix = sys.getArchiveSuffix(); - const targetAssetName = `lua-${version}-${platform}-${arch}.${archiveSuffix}`; - for (const asset of githubRelease.assets) { - if (asset.name == targetAssetName) - return { - version: version, - fileName: asset.name, - url: asset.browser_download_url - }; - } - }); -} -function getLuarocksDownloadInfo(version) { - return __awaiter(this, void 0, void 0, function* () { - const archiveSuffix = sys.getArchiveSuffix(); - const targetAssetName = `v${version}.${archiveSuffix}`; - return { - version: version, - fileName: targetAssetName, - url: `https://github.com/luarocks/luarocks/archive/${targetAssetName}` - }; - }); -} -function execIn(cmd, cwd) { - return __awaiter(this, void 0, void 0, function* () { - yield exec.exec(cmd, undefined, { cwd: cwd }); - }); + } + catch (err) { + throw new Error(`Failed to install version ${version}: ${err}`); + } } +exports.installLuarocks = installLuarocks; /***/ }), @@ -5178,6 +5105,7 @@ const LUAROCKS_VERSION_ALIASES = { function getInputs() { const luaVersion = core_1.getInput(constants_1.InputNames.LuaVersion, { required: true }); const luarocksVersion = core_1.getInput(constants_1.InputNames.LuarocksVersion, { required: false }); + const repoToken = core_1.getInput(constants_1.InputNames.RepoToken, { required: true }); let resolvedLuaVersion = luaVersion; if (LUA_VERSION_ALIASES[luaVersion]) { resolvedLuaVersion = LUA_VERSION_ALIASES[luaVersion]; @@ -5188,7 +5116,8 @@ function getInputs() { } return { luaVersion: resolvedLuaVersion, - luarocksVersion: resolvedLuarocksVersion + luarocksVersion: resolvedLuarocksVersion, + repoToken: repoToken }; } exports.getInputs = getInputs; diff --git a/lib/constants.js b/lib/constants.js index 5a1020e..cbe999d 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -5,4 +5,5 @@ var InputNames; (function (InputNames) { InputNames["LuaVersion"] = "lua-version"; InputNames["LuarocksVersion"] = "luarocks-version"; + InputNames["RepoToken"] = "repo-token"; })(InputNames = exports.InputNames || (exports.InputNames = {})); diff --git a/lib/input-helper.js b/lib/input-helper.js index 1d14317..6235e1a 100644 --- a/lib/input-helper.js +++ b/lib/input-helper.js @@ -22,6 +22,7 @@ const LUAROCKS_VERSION_ALIASES = { function getInputs() { const luaVersion = core_1.getInput(constants_1.InputNames.LuaVersion, { required: true }); const luarocksVersion = core_1.getInput(constants_1.InputNames.LuarocksVersion, { required: false }); + const repoToken = core_1.getInput(constants_1.InputNames.RepoToken, { required: true }); let resolvedLuaVersion = luaVersion; if (LUA_VERSION_ALIASES[luaVersion]) { resolvedLuaVersion = LUA_VERSION_ALIASES[luaVersion]; @@ -32,7 +33,8 @@ function getInputs() { } return { luaVersion: resolvedLuaVersion, - luarocksVersion: resolvedLuarocksVersion + luarocksVersion: resolvedLuarocksVersion, + repoToken: repoToken }; } exports.getInputs = getInputs; diff --git a/lib/installer.js b/lib/installer.js index 9c25241..dddc807 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -14,143 +14,74 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.installLuarocks = exports.installLua = void 0; const tc = __importStar(require("@actions/tool-cache")); const core = __importStar(require("@actions/core")); const exec = __importStar(require("@actions/exec")); -const httpm = __importStar(require("@actions/http-client")); const path = __importStar(require("path")); const os = __importStar(require("os")); const sys = __importStar(require("./system")); -function installLua(version, installPath) { - return __awaiter(this, void 0, void 0, function* () { - const arch = sys.getArch(); - const platform = sys.getPlatform(); - core.info(`Attempting to download Lua ${version}`); - const info = yield getLuaDownloadInfo(version, platform, arch); - if (!info) { - throw new Error(`Unable to find Lua version '${version}' for platform ${platform} and architecture ${arch}.`); - } - try { - core.info('Installing from archive'); - return yield installLuaVersion(info, installPath); - } - catch (err) { - throw new Error(`Failed to download version ${version}: ${err}`); - } - }); +async function extractArchive(archivePath, destPath) { + const archiveSuffix = sys.getArchiveSuffix(); + if (archiveSuffix === 'zip') { + return await tc.extractZip(archivePath, destPath); + } + return await tc.extractTar(archivePath, destPath); } -exports.installLua = installLua; -function installLuarocks(version, installPath, luaPath) { - return __awaiter(this, void 0, void 0, function* () { - core.info(`Attempting to download Luarocks ${version}`); - const info = yield getLuarocksDownloadInfo(version); - if (!info) { - throw new Error(`Unable to find Luarocks version '${version}'.`); - } - try { - core.info('Installing from archive'); - return yield installLuarocksVersion(info, installPath, luaPath); - } - catch (err) { - throw new Error(`Failed to download version ${version}: ${err}`); - } - }); +function getLuaDownloadUrl(version) { + const platform = sys.getPlatform(); + const arch = sys.getArch(); + const archiveSuffix = sys.getArchiveSuffix(); + const targetAssetName = `lua-${version}-${platform}-${arch}.${archiveSuffix}`; + return `https://github.com/luadevkit/versions/releases/download/v${version}/${targetAssetName}`; } -exports.installLuarocks = installLuarocks; -function installLuaVersion(info, installPath) { - return __awaiter(this, void 0, void 0, function* () { - core.info(`Downloading Lua ${info.version} from ${info.url}`); - const downloadPath = yield tc.downloadTool(info.url); - const extractionPath = yield extractArchive(downloadPath, path.join(installPath, 'lua')); - core.info(`Extracted Lua to ${extractionPath}`); - return extractionPath; - }); +function getLuarocksDownloadUrl(version) { + const archiveSuffix = sys.getArchiveSuffix(); + const targetAssetName = `v${version}.${archiveSuffix}`; + return `https://github.com/luarocks/luarocks/archive/${targetAssetName}`; +} +async function installLua(authToken, version, installPath) { + try { + core.info(`Attempting to install Lua ${version}`); + const url = getLuaDownloadUrl(version); + core.info(`Downloading Lua ${version} from ${url}`); + const downloadPath = await tc.downloadTool(url, undefined, authToken); + return await extractArchive(downloadPath, path.join(installPath, 'lua')); + } + catch (err) { + throw new Error(`Failed to install Lua version ${version}: ${err}`); + } } -function installLuarocksVersion(info, installPath, luaPath) { - return __awaiter(this, void 0, void 0, function* () { - core.info(`Downloading Luarocks ${info.version} from ${info.url}`); - const downloadPath = yield tc.downloadTool(info.url); - const extractionPath = yield extractArchive(downloadPath, os.tmpdir()); - core.info(`Extracted Luarocks to ${extractionPath}`); - const sourcePath = path.join(extractionPath, `luarocks-${info.version}`); +exports.installLua = installLua; +async function execIn(cmd, cwd) { + await exec.exec(cmd, undefined, { cwd: cwd }); +} +async function installLuarocks(authToken, version, installPath, luaPath) { + try { + core.info(`Attempting to install Luarocks ${version}`); + const url = getLuarocksDownloadUrl(version); + core.info(`Downloading Luarocks ${version} from ${url}`); + const downloadPath = await tc.downloadTool(url, undefined, authToken); + const extractionPath = await extractArchive(downloadPath, os.tmpdir()); + const sourcePath = path.join(extractionPath, `luarocks-${version}`); const platform = sys.getPlatform(); if (platform === 'windows') { - yield execIn(`.\\install.bat /P ${installPath} /SELFCONTAINED /LUA ${luaPath} /NOREG /NOADMIN /Q`, sourcePath); + await execIn(`.\\install.bat /P ${installPath} /SELFCONTAINED /LUA ${luaPath} /NOREG /NOADMIN /Q`, sourcePath); } else { - yield execIn(`./configure --prefix=${installPath} --with-lua=${luaPath}`, sourcePath); - yield execIn('make -s', sourcePath); - yield execIn('make -s install', sourcePath); + await execIn(`./configure --prefix=${installPath} --with-lua=${luaPath}`, sourcePath); + await execIn('make -s', sourcePath); + await execIn('make -s install', sourcePath); } return installPath; - }); -} -function extractArchive(archivePath, destPath) { - return __awaiter(this, void 0, void 0, function* () { - const archiveSuffix = sys.getArchiveSuffix(); - if (archiveSuffix === 'zip') { - return yield tc.extractZip(archivePath, destPath); - } - return yield tc.extractTar(archivePath, destPath); - }); -} -function getGitHubRelease(releaseUrl) { - return __awaiter(this, void 0, void 0, function* () { - const http = new httpm.HttpClient('setup-lua', [], { - allowRedirects: true, - maxRedirects: 3 - }); - const response = yield http.getJson(releaseUrl); - return response.result; - }); -} -function getLuaDownloadInfo(version, platform, arch) { - return __awaiter(this, void 0, void 0, function* () { - const releaseUrl = `https://api.github.com/repos/luadevkit/build/releases/tags/v${version}`; - const githubRelease = yield getGitHubRelease(releaseUrl); - if (!githubRelease) { - return; - } - const archiveSuffix = sys.getArchiveSuffix(); - const targetAssetName = `lua-${version}-${platform}-${arch}.${archiveSuffix}`; - for (const asset of githubRelease.assets) { - if (asset.name == targetAssetName) - return { - version: version, - fileName: asset.name, - url: asset.browser_download_url - }; - } - }); -} -function getLuarocksDownloadInfo(version) { - return __awaiter(this, void 0, void 0, function* () { - const archiveSuffix = sys.getArchiveSuffix(); - const targetAssetName = `v${version}.${archiveSuffix}`; - return { - version: version, - fileName: targetAssetName, - url: `https://github.com/luarocks/luarocks/archive/${targetAssetName}` - }; - }); -} -function execIn(cmd, cwd) { - return __awaiter(this, void 0, void 0, function* () { - yield exec.exec(cmd, undefined, { cwd: cwd }); - }); + } + catch (err) { + throw new Error(`Failed to install version ${version}: ${err}`); + } } +exports.installLuarocks = installLuarocks; diff --git a/lib/setup-lua.js b/lib/setup-lua.js index 5847374..fec1291 100644 --- a/lib/setup-lua.js +++ b/lib/setup-lua.js @@ -14,19 +14,10 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupLua = void 0; const core = __importStar(require("@actions/core")); @@ -35,42 +26,46 @@ const installer_1 = require("./installer"); const path_1 = require("path"); const child_process_1 = require("child_process"); const sys = __importStar(require("./system")); -function setupLua() { - return __awaiter(this, void 0, void 0, function* () { - try { - const inputs = input_helper_1.getInputs(); - const installPrefix = path_1.join(process.cwd(), '.install'); - const luaInstallPath = path_1.join(installPrefix); - const luarocksInstallPath = path_1.join(installPrefix, 'luarocks'); - const luaVersion = inputs.luaVersion; - core.info(`Setup Lua version ${luaVersion}`); - const luaPath = yield installer_1.installLua(luaVersion, luaInstallPath); - const luaBinPath = path_1.join(luaPath, 'bin'); - core.addPath(luaBinPath); - core.info(`Added ${luaBinPath} to the path`); - const luarocksVersion = inputs.luarocksVersion; - if (luarocksVersion) { - core.info(`Setup Luarocks version ${luarocksVersion}`); - const luarocksPath = yield installer_1.installLuarocks(luarocksVersion, luarocksInstallPath, luaPath); - const platform = sys.getPlatform(); - const luarocksBinPath = platform === 'windows' ? luarocksPath : path_1.join(luarocksPath, 'bin'); - core.addPath(luarocksBinPath); - core.info(`Added ${luarocksBinPath} to the path`); - let luarocksSystemPath = child_process_1.execSync('luarocks path --lr-bin', { encoding: 'utf-8' }).trim(); - core.addPath(luarocksSystemPath); - core.info(`Added ${luarocksSystemPath} to the path`); - let luarocksLuaPath = child_process_1.execSync('luarocks path --lr-path', { encoding: 'utf-8' }).trim(); - core.exportVariable('LUA_PATH', ';;' + luarocksLuaPath); - core.info(`Set LUA_PATH to ${luarocksLuaPath}`); - let luarocksLuaCPath = child_process_1.execSync('luarocks path --lr-cpath', { encoding: 'utf-8' }).trim(); - core.exportVariable('LUA_CPATH', ';;' + luarocksLuaCPath); - core.info(`Set LUA_CPATH to ${luarocksLuaCPath}`); - core.info(`Successfully setup Luarocks ${luarocksVersion}`); - } +function exportVariable(name, value) { + core.exportVariable(name, value); + core.info(`Set ${name} to ${process.env[name]}`); +} +function addPath(value) { + core.addPath(value); + core.info(`Added ${value} to PATH`); +} +async function setupLua() { + try { + const inputs = input_helper_1.getInputs(); + const platform = sys.getPlatform(); + const installPrefix = path_1.join(process.cwd(), '.install'); + const luaInstallPath = path_1.join(installPrefix); + const luarocksInstallPath = path_1.join(installPrefix, 'luarocks'); + const luaVersion = inputs.luaVersion; + core.info(`Setup Lua version ${luaVersion}`); + const luaPath = await installer_1.installLua(inputs.repoToken, luaVersion, luaInstallPath); + const luaBinPath = path_1.join(luaPath, 'bin'); + addPath(luaBinPath); + if (platform == 'linux' || platform == 'darwin') { + exportVariable('LD_LIBRARY_PATH', luaBinPath); } - catch (error) { - core.setFailed(error.message); + const luarocksVersion = inputs.luarocksVersion; + if (luarocksVersion) { + core.info(`Setup Luarocks version ${luarocksVersion}`); + const luarocksPath = await installer_1.installLuarocks(inputs.repoToken, luarocksVersion, luarocksInstallPath, luaPath); + const luarocksBinPath = platform === 'windows' ? luarocksPath : path_1.join(luarocksPath, 'bin'); + addPath(luarocksBinPath); + let luarocksSystemPath = child_process_1.execSync('luarocks path --lr-bin', { encoding: 'utf-8' }).trim(); + addPath(luarocksSystemPath); + let luarocksLuaPath = child_process_1.execSync('luarocks path --lr-path', { encoding: 'utf-8' }).trim(); + exportVariable('LUA_PATH', luarocksLuaPath); + let luarocksLuaCPath = child_process_1.execSync('luarocks path --lr-cpath', { encoding: 'utf-8' }).trim(); + exportVariable('LUA_CPATH', luarocksLuaCPath); + core.info(`Successfully setup Luarocks ${luarocksVersion}`); } - }); + } + catch (error) { + core.setFailed(error.message); + } } exports.setupLua = setupLua; diff --git a/package-lock.json b/package-lock.json index 0987d78..e6eb12d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,15 +10,16 @@ "dependencies": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.4", - "@actions/http-client": "^1.0.8", + "@actions/github": "^4.0.0", + "@actions/http-client": "1.0.8", "@actions/io": "^1.0.2", "@actions/tool-cache": "^1.6.0" }, "devDependencies": { - "@types/node": "^12.0.4", + "@types/node": "^14.14.35", "@zeit/ncc": "^0.22.3", - "prettier": "^2.0.5", - "typescript": "^3.9.7" + "prettier": "^2.2.1", + "typescript": "^4.2.3" } }, "node_modules/@actions/core": { @@ -34,6 +35,17 @@ "@actions/io": "^1.0.1" } }, + "node_modules/@actions/github": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-4.0.0.tgz", + "integrity": "sha512-Ej/Y2E+VV6sR9X7pWL5F3VgEWrABaT292DRqRU6R4hnQjPtC/zD3nagxVdXWiRQvYDh8kHXo7IDmG42eJ/dOMA==", + "dependencies": { + "@actions/http-client": "^1.0.8", + "@octokit/core": "^3.0.0", + "@octokit/plugin-paginate-rest": "^2.2.3", + "@octokit/plugin-rest-endpoint-methods": "^4.0.0" + } + }, "node_modules/@actions/http-client": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz", @@ -48,11 +60,11 @@ "integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg==" }, "node_modules/@actions/tool-cache": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.6.0.tgz", - "integrity": "sha512-+fyEBImPD3m5I0o6DflCO0NHY180LPoX8Lo6y4Iez+V17kO8kfkH0VHxb8mUdmD6hn9dWA9Ch1JA20fXoIYUeQ==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.6.1.tgz", + "integrity": "sha512-F+vwEDwfqcHMKuSkj79pihOnsAMv23EkG76nMpc82UsnXwyQdyEsktGxrB0SNtm7pRqTXEIOoAPTgrSQclXYTg==", "dependencies": { - "@actions/core": "^1.2.3", + "@actions/core": "^1.2.6", "@actions/exec": "^1.0.0", "@actions/http-client": "^1.0.8", "@actions/io": "^1.0.1", @@ -60,25 +72,163 @@ "uuid": "^3.3.2" } }, + "node_modules/@octokit/auth-token": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.4.5.tgz", + "integrity": "sha512-BpGYsPgJt05M7/L/5FoE1PiAbdxXFZkX/3kDYcsvd1v6UhlnE5e96dTDr0ezX/EFwciQxf3cNV0loipsURU+WA==", + "dependencies": { + "@octokit/types": "^6.0.3" + } + }, + "node_modules/@octokit/core": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.3.1.tgz", + "integrity": "sha512-Dc5NNQOYjgZU5S1goN6A/E500yXOfDUFRGQB8/2Tl16AcfvS3H9PudyOe3ZNE/MaVyHPIfC0htReHMJb1tMrvw==", + "dependencies": { + "@octokit/auth-token": "^2.4.4", + "@octokit/graphql": "^4.5.8", + "@octokit/request": "^5.4.12", + "@octokit/request-error": "^2.0.5", + "@octokit/types": "^6.0.3", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + } + }, + "node_modules/@octokit/endpoint": { + "version": "6.0.11", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.11.tgz", + "integrity": "sha512-fUIPpx+pZyoLW4GCs3yMnlj2LfoXTWDUVPTC4V3MUEKZm48W+XYpeWSZCv+vYF1ZABUm2CqnDVf1sFtIYrj7KQ==", + "dependencies": { + "@octokit/types": "^6.0.3", + "is-plain-object": "^5.0.0", + "universal-user-agent": "^6.0.0" + } + }, + "node_modules/@octokit/graphql": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.6.1.tgz", + "integrity": "sha512-2lYlvf4YTDgZCTXTW4+OX+9WTLFtEUc6hGm4qM1nlZjzxj+arizM4aHWzBVBCxY9glh7GIs0WEuiSgbVzv8cmA==", + "dependencies": { + "@octokit/request": "^5.3.0", + "@octokit/types": "^6.0.3", + "universal-user-agent": "^6.0.0" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-5.3.2.tgz", + "integrity": "sha512-NxF1yfYOUO92rCx3dwvA2onF30Vdlg7YUkMVXkeptqpzA3tRLplThhFleV/UKWFgh7rpKu1yYRbvNDUtzSopKA==" + }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "2.13.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.13.3.tgz", + "integrity": "sha512-46lptzM9lTeSmIBt/sVP/FLSTPGx6DCzAdSX3PfeJ3mTf4h9sGC26WpaQzMEq/Z44cOcmx8VsOhO+uEgE3cjYg==", + "dependencies": { + "@octokit/types": "^6.11.0" + }, + "peerDependencies": { + "@octokit/core": ">=2" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "4.13.5", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-4.13.5.tgz", + "integrity": "sha512-kYKcWkFm4Ldk8bZai2RVEP1z97k1C/Ay2FN9FNTBg7JIyKoiiJjks4OtT6cuKeZX39tqa+C3J9xeYc6G+6g8uQ==", + "dependencies": { + "@octokit/types": "^6.12.2", + "deprecation": "^2.3.1" + }, + "peerDependencies": { + "@octokit/core": ">=3" + } + }, + "node_modules/@octokit/request": { + "version": "5.4.14", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.4.14.tgz", + "integrity": "sha512-VkmtacOIQp9daSnBmDI92xNIeLuSRDOIuplp/CJomkvzt7M18NXgG044Cx/LFKLgjKt9T2tZR6AtJayba9GTSA==", + "dependencies": { + "@octokit/endpoint": "^6.0.1", + "@octokit/request-error": "^2.0.0", + "@octokit/types": "^6.7.1", + "deprecation": "^2.0.0", + "is-plain-object": "^5.0.0", + "node-fetch": "^2.6.1", + "once": "^1.4.0", + "universal-user-agent": "^6.0.0" + } + }, + "node_modules/@octokit/request-error": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.0.5.tgz", + "integrity": "sha512-T/2wcCFyM7SkXzNoyVNWjyVlUwBvW3igM3Btr/eKYiPmucXTtkxt2RBsf6gn3LTzaLSLTQtNmvg+dGsOxQrjZg==", + "dependencies": { + "@octokit/types": "^6.0.3", + "deprecation": "^2.0.0", + "once": "^1.4.0" + } + }, + "node_modules/@octokit/types": { + "version": "6.12.2", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.12.2.tgz", + "integrity": "sha512-kCkiN8scbCmSq+gwdJV0iLgHc0O/GTPY1/cffo9kECu1MvatLPh9E+qFhfRIktKfHEA6ZYvv6S1B4Wnv3bi3pA==", + "dependencies": { + "@octokit/openapi-types": "^5.3.2" + } + }, "node_modules/@types/node": { - "version": "12.12.54", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.54.tgz", - "integrity": "sha512-ge4xZ3vSBornVYlDnk7yZ0gK6ChHf/CHB7Gl1I0Jhah8DDnEQqBzgohYG4FX4p81TNirSETOiSyn+y1r9/IR6w==", + "version": "14.14.35", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.35.tgz", + "integrity": "sha512-Lt+wj8NVPx0zUmUwumiVXapmaLUcAk3yPuHCFVXras9k5VT9TdhJqKqGVUQCD60OTMCl0qxJ57OiTL0Mic3Iag==", "dev": true }, "node_modules/@zeit/ncc": { "version": "0.22.3", "resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.22.3.tgz", "integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==", + "deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.", "dev": true, "bin": { "ncc": "dist/ncc/cli.js" } }, + "node_modules/before-after-hook": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.0.tgz", + "integrity": "sha512-jH6rKQIfroBbhEXVmI7XmXe3ix5S/PgJqpzdDPnR8JGLHWNYLsYZ6tK5iWOF/Ra3oqEX0NobXGlzbiylIzVphQ==" + }, + "node_modules/deprecation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" + }, + "node_modules/is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dependencies": { + "wrappy": "1" + } + }, "node_modules/prettier": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz", - "integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", + "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", "dev": true, "bin": { "prettier": "bin-prettier.js" @@ -104,9 +254,9 @@ } }, "node_modules/typescript": { - "version": "3.9.7", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", - "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", + "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -116,6 +266,11 @@ "node": ">=4.2.0" } }, + "node_modules/universal-user-agent": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz", + "integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==" + }, "node_modules/uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", @@ -123,6 +278,11 @@ "bin": { "uuid": "bin/uuid" } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" } }, "dependencies": { @@ -139,6 +299,17 @@ "@actions/io": "^1.0.1" } }, + "@actions/github": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-4.0.0.tgz", + "integrity": "sha512-Ej/Y2E+VV6sR9X7pWL5F3VgEWrABaT292DRqRU6R4hnQjPtC/zD3nagxVdXWiRQvYDh8kHXo7IDmG42eJ/dOMA==", + "requires": { + "@actions/http-client": "^1.0.8", + "@octokit/core": "^3.0.0", + "@octokit/plugin-paginate-rest": "^2.2.3", + "@octokit/plugin-rest-endpoint-methods": "^4.0.0" + } + }, "@actions/http-client": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz", @@ -153,11 +324,11 @@ "integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg==" }, "@actions/tool-cache": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.6.0.tgz", - "integrity": "sha512-+fyEBImPD3m5I0o6DflCO0NHY180LPoX8Lo6y4Iez+V17kO8kfkH0VHxb8mUdmD6hn9dWA9Ch1JA20fXoIYUeQ==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.6.1.tgz", + "integrity": "sha512-F+vwEDwfqcHMKuSkj79pihOnsAMv23EkG76nMpc82UsnXwyQdyEsktGxrB0SNtm7pRqTXEIOoAPTgrSQclXYTg==", "requires": { - "@actions/core": "^1.2.3", + "@actions/core": "^1.2.6", "@actions/exec": "^1.0.0", "@actions/http-client": "^1.0.8", "@actions/io": "^1.0.1", @@ -165,10 +336,107 @@ "uuid": "^3.3.2" } }, + "@octokit/auth-token": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.4.5.tgz", + "integrity": "sha512-BpGYsPgJt05M7/L/5FoE1PiAbdxXFZkX/3kDYcsvd1v6UhlnE5e96dTDr0ezX/EFwciQxf3cNV0loipsURU+WA==", + "requires": { + "@octokit/types": "^6.0.3" + } + }, + "@octokit/core": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.3.1.tgz", + "integrity": "sha512-Dc5NNQOYjgZU5S1goN6A/E500yXOfDUFRGQB8/2Tl16AcfvS3H9PudyOe3ZNE/MaVyHPIfC0htReHMJb1tMrvw==", + "requires": { + "@octokit/auth-token": "^2.4.4", + "@octokit/graphql": "^4.5.8", + "@octokit/request": "^5.4.12", + "@octokit/request-error": "^2.0.5", + "@octokit/types": "^6.0.3", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/endpoint": { + "version": "6.0.11", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.11.tgz", + "integrity": "sha512-fUIPpx+pZyoLW4GCs3yMnlj2LfoXTWDUVPTC4V3MUEKZm48W+XYpeWSZCv+vYF1ZABUm2CqnDVf1sFtIYrj7KQ==", + "requires": { + "@octokit/types": "^6.0.3", + "is-plain-object": "^5.0.0", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/graphql": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.6.1.tgz", + "integrity": "sha512-2lYlvf4YTDgZCTXTW4+OX+9WTLFtEUc6hGm4qM1nlZjzxj+arizM4aHWzBVBCxY9glh7GIs0WEuiSgbVzv8cmA==", + "requires": { + "@octokit/request": "^5.3.0", + "@octokit/types": "^6.0.3", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/openapi-types": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-5.3.2.tgz", + "integrity": "sha512-NxF1yfYOUO92rCx3dwvA2onF30Vdlg7YUkMVXkeptqpzA3tRLplThhFleV/UKWFgh7rpKu1yYRbvNDUtzSopKA==" + }, + "@octokit/plugin-paginate-rest": { + "version": "2.13.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.13.3.tgz", + "integrity": "sha512-46lptzM9lTeSmIBt/sVP/FLSTPGx6DCzAdSX3PfeJ3mTf4h9sGC26WpaQzMEq/Z44cOcmx8VsOhO+uEgE3cjYg==", + "requires": { + "@octokit/types": "^6.11.0" + } + }, + "@octokit/plugin-rest-endpoint-methods": { + "version": "4.13.5", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-4.13.5.tgz", + "integrity": "sha512-kYKcWkFm4Ldk8bZai2RVEP1z97k1C/Ay2FN9FNTBg7JIyKoiiJjks4OtT6cuKeZX39tqa+C3J9xeYc6G+6g8uQ==", + "requires": { + "@octokit/types": "^6.12.2", + "deprecation": "^2.3.1" + } + }, + "@octokit/request": { + "version": "5.4.14", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.4.14.tgz", + "integrity": "sha512-VkmtacOIQp9daSnBmDI92xNIeLuSRDOIuplp/CJomkvzt7M18NXgG044Cx/LFKLgjKt9T2tZR6AtJayba9GTSA==", + "requires": { + "@octokit/endpoint": "^6.0.1", + "@octokit/request-error": "^2.0.0", + "@octokit/types": "^6.7.1", + "deprecation": "^2.0.0", + "is-plain-object": "^5.0.0", + "node-fetch": "^2.6.1", + "once": "^1.4.0", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/request-error": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.0.5.tgz", + "integrity": "sha512-T/2wcCFyM7SkXzNoyVNWjyVlUwBvW3igM3Btr/eKYiPmucXTtkxt2RBsf6gn3LTzaLSLTQtNmvg+dGsOxQrjZg==", + "requires": { + "@octokit/types": "^6.0.3", + "deprecation": "^2.0.0", + "once": "^1.4.0" + } + }, + "@octokit/types": { + "version": "6.12.2", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.12.2.tgz", + "integrity": "sha512-kCkiN8scbCmSq+gwdJV0iLgHc0O/GTPY1/cffo9kECu1MvatLPh9E+qFhfRIktKfHEA6ZYvv6S1B4Wnv3bi3pA==", + "requires": { + "@octokit/openapi-types": "^5.3.2" + } + }, "@types/node": { - "version": "12.12.54", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.54.tgz", - "integrity": "sha512-ge4xZ3vSBornVYlDnk7yZ0gK6ChHf/CHB7Gl1I0Jhah8DDnEQqBzgohYG4FX4p81TNirSETOiSyn+y1r9/IR6w==", + "version": "14.14.35", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.35.tgz", + "integrity": "sha512-Lt+wj8NVPx0zUmUwumiVXapmaLUcAk3yPuHCFVXras9k5VT9TdhJqKqGVUQCD60OTMCl0qxJ57OiTL0Mic3Iag==", "dev": true }, "@zeit/ncc": { @@ -177,10 +445,38 @@ "integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==", "dev": true }, + "before-after-hook": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.0.tgz", + "integrity": "sha512-jH6rKQIfroBbhEXVmI7XmXe3ix5S/PgJqpzdDPnR8JGLHWNYLsYZ6tK5iWOF/Ra3oqEX0NobXGlzbiylIzVphQ==" + }, + "deprecation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" + }, + "is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" + }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, "prettier": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz", - "integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", + "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", "dev": true }, "semver": { @@ -194,15 +490,25 @@ "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" }, "typescript": { - "version": "3.9.7", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", - "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", + "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", "dev": true }, + "universal-user-agent": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz", + "integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==" + }, "uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" } } } diff --git a/package.json b/package.json index 929bcdb..9f8e64b 100644 --- a/package.json +++ b/package.json @@ -28,14 +28,15 @@ "dependencies": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.4", - "@actions/http-client": "^1.0.8", + "@actions/github": "^4.0.0", + "@actions/http-client": "1.0.8", "@actions/io": "^1.0.2", "@actions/tool-cache": "^1.6.0" }, "devDependencies": { - "@types/node": "^12.0.4", + "@types/node": "^14.14.35", "@zeit/ncc": "^0.22.3", - "prettier": "^2.0.5", - "typescript": "^3.9.7" + "prettier": "^2.2.1", + "typescript": "^4.2.3" } } diff --git a/src/constants.ts b/src/constants.ts index 6089591..67f2835 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,5 @@ export enum InputNames { LuaVersion = 'lua-version', - LuarocksVersion = 'luarocks-version' + LuarocksVersion = 'luarocks-version', + RepoToken = 'repo-token' } diff --git a/src/input-helper.ts b/src/input-helper.ts index b657269..f6d0780 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -23,6 +23,7 @@ const LUAROCKS_VERSION_ALIASES: {[index: string]: string} = { export function getInputs(): Inputs { const luaVersion = getInput(InputNames.LuaVersion, {required: true}); const luarocksVersion = getInput(InputNames.LuarocksVersion, {required: false}); + const repoToken = getInput(InputNames.RepoToken, {required: true}); let resolvedLuaVersion = luaVersion; if (LUA_VERSION_ALIASES[luaVersion]) { @@ -35,6 +36,7 @@ export function getInputs(): Inputs { return { luaVersion: resolvedLuaVersion, - luarocksVersion: resolvedLuarocksVersion + luarocksVersion: resolvedLuarocksVersion, + repoToken: repoToken }; } diff --git a/src/inputs.ts b/src/inputs.ts index b570d5a..5bf2435 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -1,4 +1,5 @@ export interface Inputs { luaVersion: string; luarocksVersion: string; + repoToken: string; } diff --git a/src/installer.ts b/src/installer.ts index 29562f1..95f312f 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -1,3 +1,4 @@ +import * as github from '@actions/github'; import * as tc from '@actions/tool-cache'; import * as core from '@actions/core'; import * as exec from '@actions/exec'; @@ -8,86 +9,6 @@ import * as os from 'os'; import * as sys from './system'; -interface ILuaReleaseAsset { - name: string; - browser_download_url: string; -} - -interface IGitHubRelease { - tag_name: string; - assets: ILuaReleaseAsset[]; -} - -interface IDownloadInfo { - version: string; - fileName: string; - url: string; -} - -export async function installLua(version: string, installPath: string) { - const arch: string = sys.getArch(); - const platform: string = sys.getPlatform(); - - core.info(`Attempting to download Lua ${version}`); - const info = await getLuaDownloadInfo(version, platform, arch); - if (!info) { - throw new Error(`Unable to find Lua version '${version}' for platform ${platform} and architecture ${arch}.`); - } - - try { - core.info('Installing from archive'); - return await installLuaVersion(info, installPath); - } catch (err) { - throw new Error(`Failed to download version ${version}: ${err}`); - } -} - -export async function installLuarocks(version: string, installPath: string, luaPath: string): Promise { - core.info(`Attempting to download Luarocks ${version}`); - const info = await getLuarocksDownloadInfo(version); - if (!info) { - throw new Error(`Unable to find Luarocks version '${version}'.`); - } - - try { - core.info('Installing from archive'); - return await installLuarocksVersion(info, installPath, luaPath); - } catch (err) { - throw new Error(`Failed to download version ${version}: ${err}`); - } -} - -async function installLuaVersion(info: IDownloadInfo, installPath: string): Promise { - core.info(`Downloading Lua ${info.version} from ${info.url}`); - const downloadPath = await tc.downloadTool(info.url); - - const extractionPath = await extractArchive(downloadPath, path.join(installPath, 'lua')); - core.info(`Extracted Lua to ${extractionPath}`); - - return extractionPath; -} - -async function installLuarocksVersion(info: IDownloadInfo, installPath: string, luaPath: string): Promise { - core.info(`Downloading Luarocks ${info.version} from ${info.url}`); - const downloadPath = await tc.downloadTool(info.url); - - const extractionPath = await extractArchive(downloadPath, os.tmpdir()); - core.info(`Extracted Luarocks to ${extractionPath}`); - - const sourcePath = path.join(extractionPath, `luarocks-${info.version}`); - - const platform = sys.getPlatform(); - if (platform === 'windows') { - await execIn(`.\\install.bat /P ${installPath} /SELFCONTAINED /LUA ${luaPath} /NOREG /NOADMIN /Q`, sourcePath); - } else { - await execIn(`./configure --prefix=${installPath} --with-lua=${luaPath}`, sourcePath); - await execIn('make -s', sourcePath); - await execIn('make -s install', sourcePath); - } - - return installPath; -} - async function extractArchive(archivePath: string, destPath: string): Promise { const archiveSuffix = sys.getArchiveSuffix(); if (archiveSuffix === 'zip') { @@ -96,44 +17,63 @@ async function extractArchive(archivePath: string, destPath: string): Promise { - const http: httpm.HttpClient = new httpm.HttpClient('setup-lua', [], { - allowRedirects: true, - maxRedirects: 3 - }); - const response = await http.getJson(releaseUrl); - return response.result; -} - -async function getLuaDownloadInfo(version: string, platform: string, arch: string): Promise { - const releaseUrl: string = `https://api.github.com/repos/luadevkit/build/releases/tags/v${version}`; - const githubRelease: IGitHubRelease | null = await getGitHubRelease(releaseUrl); - if (!githubRelease) { - return; - } - +function getLuaDownloadUrl(version: string): string { + const platform: string = sys.getPlatform(); + const arch: string = sys.getArch(); const archiveSuffix = sys.getArchiveSuffix(); const targetAssetName: string = `lua-${version}-${platform}-${arch}.${archiveSuffix}`; - for (const asset of githubRelease.assets) { - if (asset.name == targetAssetName) - return { - version: version, - fileName: asset.name, - url: asset.browser_download_url - }; - } + return `https://github.com/luadevkit/versions/releases/download/v${version}/${targetAssetName}`; } -async function getLuarocksDownloadInfo(version: string): Promise { +function getLuarocksDownloadUrl(version: string): string { const archiveSuffix = sys.getArchiveSuffix(); const targetAssetName: string = `v${version}.${archiveSuffix}`; - return { - version: version, - fileName: targetAssetName, - url: `https://github.com/luarocks/luarocks/archive/${targetAssetName}` - }; + return `https://github.com/luarocks/luarocks/archive/${targetAssetName}`; +} + +export async function installLua(authToken: string, version: string, installPath: string) { + try { + core.info(`Attempting to install Lua ${version}`); + const url: string = getLuaDownloadUrl(version); + + core.info(`Downloading Lua ${version} from ${url}`); + const downloadPath: string = await tc.downloadTool(url, undefined, authToken); + return await extractArchive(downloadPath, path.join(installPath, 'lua')); + } catch (err) { + throw new Error(`Failed to install Lua version ${version}: ${err}`); + } } async function execIn(cmd: string, cwd: string) { await exec.exec(cmd, undefined, {cwd: cwd}); } + +export async function installLuarocks( + authToken: string, + version: string, + installPath: string, + luaPath: string +): Promise { + try { + core.info(`Attempting to install Luarocks ${version}`); + const url: string = getLuarocksDownloadUrl(version); + + core.info(`Downloading Luarocks ${version} from ${url}`); + const downloadPath: string = await tc.downloadTool(url, undefined, authToken); + const extractionPath = await extractArchive(downloadPath, os.tmpdir()); + const sourcePath = path.join(extractionPath, `luarocks-${version}`); + + const platform = sys.getPlatform(); + if (platform === 'windows') { + await execIn(`.\\install.bat /P ${installPath} /SELFCONTAINED /LUA ${luaPath} /NOREG /NOADMIN /Q`, sourcePath); + } else { + await execIn(`./configure --prefix=${installPath} --with-lua=${luaPath}`, sourcePath); + await execIn('make -s', sourcePath); + await execIn('make -s install', sourcePath); + } + + return installPath; + } catch (err) { + throw new Error(`Failed to install version ${version}: ${err}`); + } +} diff --git a/src/setup-lua.ts b/src/setup-lua.ts index ffb6a08..139ea55 100644 --- a/src/setup-lua.ts +++ b/src/setup-lua.ts @@ -7,9 +7,20 @@ import {execSync} from 'child_process'; import * as sys from './system'; +function exportVariable(name: string, value: string) { + core.exportVariable(name, value); + core.info(`Set ${name} to ${process.env[name]}`); +} + +function addPath(value: string) { + core.addPath(value); + core.info(`Added ${value} to PATH`); +} + export async function setupLua() { try { const inputs = getInputs(); + const platform = sys.getPlatform(); const installPrefix = join(process.cwd(), '.install'); const luaInstallPath = join(installPrefix); @@ -18,32 +29,31 @@ export async function setupLua() { const luaVersion = inputs.luaVersion; core.info(`Setup Lua version ${luaVersion}`); - const luaPath = await installLua(luaVersion, luaInstallPath); + const luaPath = await installLua(inputs.repoToken, luaVersion, luaInstallPath); + const luaBinPath = join(luaPath, 'bin'); - core.addPath(luaBinPath); - core.info(`Added ${luaBinPath} to the path`); + addPath(luaBinPath); + + if (platform == 'linux' || platform == 'darwin') { + exportVariable('LD_LIBRARY_PATH', luaBinPath); + } const luarocksVersion = inputs.luarocksVersion; if (luarocksVersion) { core.info(`Setup Luarocks version ${luarocksVersion}`); - const luarocksPath = await installLuarocks(luarocksVersion, luarocksInstallPath, luaPath); + const luarocksPath = await installLuarocks(inputs.repoToken, luarocksVersion, luarocksInstallPath, luaPath); - const platform = sys.getPlatform(); const luarocksBinPath = platform === 'windows' ? luarocksPath : join(luarocksPath, 'bin'); - core.addPath(luarocksBinPath); - core.info(`Added ${luarocksBinPath} to the path`); + addPath(luarocksBinPath); let luarocksSystemPath = execSync('luarocks path --lr-bin', {encoding: 'utf-8'}).trim(); - core.addPath(luarocksSystemPath); - core.info(`Added ${luarocksSystemPath} to the path`); + addPath(luarocksSystemPath); let luarocksLuaPath = execSync('luarocks path --lr-path', {encoding: 'utf-8'}).trim(); - core.exportVariable('LUA_PATH', ';;' + luarocksLuaPath); - core.info(`Set LUA_PATH to ${luarocksLuaPath}`); + exportVariable('LUA_PATH', luarocksLuaPath); let luarocksLuaCPath = execSync('luarocks path --lr-cpath', {encoding: 'utf-8'}).trim(); - core.exportVariable('LUA_CPATH', ';;' + luarocksLuaCPath); - core.info(`Set LUA_CPATH to ${luarocksLuaCPath}`); + exportVariable('LUA_CPATH', luarocksLuaCPath); core.info(`Successfully setup Luarocks ${luarocksVersion}`); } diff --git a/tsconfig.json b/tsconfig.json index 4b14f72..ab5c9c4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "target": "es2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": [ "es6" @@ -61,4 +61,4 @@ "node_modules", "**/*.test.ts" ] -} \ No newline at end of file +}