UNPKG

@jbrunton/gha-installer

Version:
76 lines (75 loc) 3.75 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); 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.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.Installer = void 0; const core = __importStar(require("@actions/core")); const cache = __importStar(require("@actions/tool-cache")); const fs = __importStar(require("fs")); class Installer { constructor(core, cache, fs, env, downloadService) { this._core = core; this._cache = cache; this._fs = fs; this._env = env; this._downloadService = downloadService; } installApp(app) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const downloadInfo = yield this._downloadService.getDownloadInfo(app); const binName = this._env.platform == 'win32' ? `${app.name}.exe` : app.name; // note: app.version and downloadInfo.version may be different: // if app.version is 'latest' then downloadInfo.version will be the concrete version let binPath = this._cache.find(binName, downloadInfo.version); if (!binPath) { this._core.info(`Downloading ${app.name} ${downloadInfo.version} from ${downloadInfo.url}`); const downloadPath = yield this._cache.downloadTool(downloadInfo.url); (_b = (_a = this._downloadService).onFileDownloaded) === null || _b === void 0 ? void 0 : _b.call(_a, downloadPath, downloadInfo, this._core); this._fs.chmodSync(downloadPath, '755'); binPath = yield this._cache.cacheFile(downloadPath, binName, binName, downloadInfo.version); } else { this._core.info(`${app.name} ${downloadInfo.version} already in tool cache`); } this._core.addPath(binPath); }); } installAll(apps) { return __awaiter(this, void 0, void 0, function* () { this._core.info('Installing ' + apps.map((app) => `${app.name}:${app.version}`).join(', ')); yield Promise.all(apps.map((app) => this.installApp(app))); }); } static create(downloadService) { return new Installer(core, cache, fs, process, downloadService); } } exports.Installer = Installer;