|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 4 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 5 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 6 | + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } |
| 7 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 8 | + }); |
| 9 | +}; |
| 10 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 11 | + if (mod && mod.__esModule) return mod; |
| 12 | + var result = {}; |
| 13 | + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
| 14 | + result["default"] = mod; |
| 15 | + return result; |
| 16 | +}; |
| 17 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 18 | +const core = __importStar(require("@actions/core")); |
| 19 | +const tc = __importStar(require("@actions/tool-cache")); |
| 20 | +const exec = __importStar(require("@actions/exec")); |
| 21 | +const io = __importStar(require("@actions/io")); |
| 22 | +const path = __importStar(require("path")); |
| 23 | +const os = __importStar(require("os")); |
| 24 | +var ArchiveType; |
| 25 | +(function (ArchiveType) { |
| 26 | + ArchiveType["None"] = ""; |
| 27 | + ArchiveType["TarGz"] = ".tar.gz"; |
| 28 | + ArchiveType["Zip"] = ".zip"; |
| 29 | + ArchiveType["SevenZ"] = ".7z"; |
| 30 | +})(ArchiveType = exports.ArchiveType || (exports.ArchiveType = {})); |
| 31 | +class Configurator { |
| 32 | + constructor(name, url, pathInArchive) { |
| 33 | + this.name = name; |
| 34 | + this.url = url; |
| 35 | + this.pathInArchive = pathInArchive; |
| 36 | + } |
| 37 | + getArchiveType() { |
| 38 | + if (this.url.endsWith(ArchiveType.TarGz)) |
| 39 | + return ArchiveType.TarGz; |
| 40 | + if (this.url.endsWith(ArchiveType.Zip)) |
| 41 | + return ArchiveType.Zip; |
| 42 | + if (this.url.endsWith(ArchiveType.SevenZ)) |
| 43 | + return ArchiveType.SevenZ; |
| 44 | + return ArchiveType.None; |
| 45 | + } |
| 46 | + configure() { |
| 47 | + return __awaiter(this, void 0, void 0, function* () { |
| 48 | + console.log(`Downloading tool from ${this.url}...`); |
| 49 | + let downloadPath = null; |
| 50 | + let archivePath = null; |
| 51 | + const tempDir = path.join(os.tmpdir(), 'tmp', 'runner', 'temp'); |
| 52 | + yield io.mkdirP(tempDir); |
| 53 | + downloadPath = yield tc.downloadTool(this.url); |
| 54 | + switch (this.getArchiveType()) { |
| 55 | + case ArchiveType.None: |
| 56 | + return this.moveToPath(downloadPath); |
| 57 | + case ArchiveType.TarGz: |
| 58 | + archivePath = yield tc.extractTar(downloadPath, tempDir); |
| 59 | + return this.moveToPath(path.join(archivePath, this.pathInArchive)); |
| 60 | + case ArchiveType.Zip: |
| 61 | + archivePath = yield tc.extractZip(downloadPath, tempDir); |
| 62 | + return this.moveToPath(path.join(archivePath, this.pathInArchive)); |
| 63 | + case ArchiveType.SevenZ: |
| 64 | + archivePath = yield tc.extract7z(downloadPath, tempDir); |
| 65 | + return this.moveToPath(path.join(archivePath, this.pathInArchive)); |
| 66 | + } |
| 67 | + }); |
| 68 | + } |
| 69 | + moveToPath(downloadPath) { |
| 70 | + return __awaiter(this, void 0, void 0, function* () { |
| 71 | + let toolPath = binPath(); |
| 72 | + yield io.mkdirP(toolPath); |
| 73 | + yield io.mv(downloadPath, path.join(toolPath, this.name)); |
| 74 | + if (process.platform !== 'win32') { |
| 75 | + yield exec.exec("chmod", ["+x", path.join(toolPath, this.name)]); |
| 76 | + } |
| 77 | + core.addPath(toolPath); |
| 78 | + }); |
| 79 | + } |
| 80 | +} |
| 81 | +exports.Configurator = Configurator; |
| 82 | +const NameInput = "name"; |
| 83 | +const URLInput = "url"; |
| 84 | +const PathInArchiveInput = "pathInArchive"; |
| 85 | +function getConfig() { |
| 86 | + const n = core.getInput(NameInput); |
| 87 | + const u = core.getInput(URLInput); |
| 88 | + const p = core.getInput(PathInArchiveInput); |
| 89 | + return new Configurator(n, u, p); |
| 90 | +} |
| 91 | +exports.getConfig = getConfig; |
| 92 | +function binPath() { |
| 93 | + let baseLocation; |
| 94 | + if (process.platform === 'win32') { |
| 95 | + // On windows use the USERPROFILE env variable |
| 96 | + baseLocation = process.env['USERPROFILE'] || 'C:\\'; |
| 97 | + } |
| 98 | + else { |
| 99 | + if (process.platform === 'darwin') { |
| 100 | + baseLocation = '/Users'; |
| 101 | + } |
| 102 | + else { |
| 103 | + baseLocation = '/home'; |
| 104 | + } |
| 105 | + } |
| 106 | + return path.join(baseLocation, os.userInfo().username, "configurator", "bin"); |
| 107 | +} |
| 108 | +exports.binPath = binPath; |
0 commit comments