install-cadius-action/dist/index.js

61 lines
2.9 KiB
JavaScript

"use strict";
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());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const os = __importStar(require("os"));
const util = __importStar(require("util"));
const path = __importStar(require("path"));
const toolCache = __importStar(require("@actions/tool-cache"));
const core = __importStar(require("@actions/core"));
function getDownloadURL(version) {
switch (os.type()) {
case 'Linux':
return util.format('https://github.com/digarok/cadius/releases/download/%s/cadius-ubuntu-latest-%s.zip', version, version);
case 'Darwin':
return util.format('https://github.com/digarok/cadius/releases/download/%s/cadius-macos-latest-%s.zip', version, version);
case 'Windows_NT':
default:
return util.format('https://github.com/digarok/cadius/releases/download/%s/cadius-windows-latest-%s.zip', version, version);
}
}
function downloadCadius(version) {
return __awaiter(this, void 0, void 0, function* () {
let cachedToolpath = toolCache.find('cadius', version);
if (!cachedToolpath) {
let downloadPath;
try {
downloadPath = yield toolCache.downloadTool(getDownloadURL(version));
}
catch (exception) {
console.log(exception);
throw new Error(util.format("Failed to download Cadius from location ", getDownloadURL(version)));
}
const extractedPath = yield toolCache.extractZip(downloadPath);
cachedToolpath = yield toolCache.cacheDir(path.join(extractedPath, 'cadius'), 'cadius', version);
}
core.addPath(cachedToolpath);
});
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
let version = core.getInput('version', { 'required': true });
yield downloadCadius(version);
console.log(`Cadius version: '${version}' has been downloaded and added to path`);
});
}
run().catch(core.setFailed);