mirror of
https://github.com/DeLaGuardo/setup-clojure.git
synced 2024-12-28 09:28:13 +08:00
102 lines
4.7 KiB
JavaScript
102 lines
4.7 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 core = __importStar(require("@actions/core"));
|
|
const io = __importStar(require("@actions/io"));
|
|
const tc = __importStar(require("@actions/tool-cache"));
|
|
const fs = __importStar(require("fs"));
|
|
const path = __importStar(require("path"));
|
|
const os = __importStar(require("os"));
|
|
const utils = __importStar(require("./utils"));
|
|
let tempDirectory = process.env['RUNNER_TEMP'] || '';
|
|
const IS_WINDOWS = process.platform === 'win32';
|
|
if (!tempDirectory) {
|
|
let baseLocation;
|
|
if (IS_WINDOWS) {
|
|
baseLocation = process.env['USERPROFILE'] || 'C:\\';
|
|
}
|
|
else {
|
|
if (process.platform === 'darwin') {
|
|
baseLocation = '/Users';
|
|
}
|
|
else {
|
|
baseLocation = '/home';
|
|
}
|
|
}
|
|
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
|
}
|
|
function setup(version) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
let toolPath = tc.find('ClojureLeiningen', utils.getCacheVersionString(version), os.arch());
|
|
if (toolPath) {
|
|
core.debug(`Leiningen found in cache ${toolPath}`);
|
|
}
|
|
else {
|
|
let leiningenFile = yield tc.downloadTool(`https://raw.githubusercontent.com/technomancy/leiningen/${version}/bin/lein${IS_WINDOWS ? '.bat' : '-pkg'}`);
|
|
let leiningenLib = yield tc.downloadTool(`https://github.com/technomancy/leiningen/releases/download/${version}/leiningen-${version}-standalone.zip`);
|
|
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
|
|
const leiningenDir = yield installLeiningen(leiningenFile, leiningenLib, tempDir);
|
|
core.debug(`clojure tools deps installed to ${leiningenDir}`);
|
|
toolPath = yield tc.cacheDir(leiningenDir, 'ClojureLeiningen', utils.getCacheVersionString(version));
|
|
}
|
|
core.addPath(path.join(toolPath, 'bin'));
|
|
});
|
|
}
|
|
exports.setup = setup;
|
|
function installLeiningen(binScript, libFile, destinationFolder) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
yield io.mkdirP(destinationFolder);
|
|
const bin = path.normalize(binScript);
|
|
const lib = path.normalize(libFile);
|
|
const binStats = fs.statSync(bin);
|
|
const libStats = fs.statSync(lib);
|
|
if (binStats.isFile() && libStats.isFile()) {
|
|
const binDir = path.join(destinationFolder, 'leiningen', 'bin');
|
|
const libDir = path.join(destinationFolder, 'leiningen', 'libexec');
|
|
yield io.mkdirP(binDir);
|
|
yield io.mkdirP(libDir);
|
|
yield io.mv(bin, path.join(binDir, `lein${IS_WINDOWS ? '.bat' : ''}`));
|
|
fs.chmodSync(path.join(binDir, `lein${IS_WINDOWS ? '.bat' : ''}`), '0755');
|
|
yield io.mv(lib, path.join(libDir, `leiningen-standalone.jar`));
|
|
if (IS_WINDOWS) {
|
|
yield readWriteAsync(path.join(binDir, 'lein.bat'), '!LEIN_HOME!\self-installs\leiningen-!LEIN_VERSION!-standalone.jar', '..\libexec\leiningen-standalone.jar');
|
|
}
|
|
else {
|
|
yield readWriteAsync(path.join(binDir, 'lein'), '/usr/share/java/leiningen-$LEIN_VERSION-standalone.jar', '../libexec/leiningen-standalone.jar');
|
|
}
|
|
return path.join(destinationFolder, 'leiningen');
|
|
}
|
|
else {
|
|
throw new Error('Not a file');
|
|
}
|
|
});
|
|
}
|
|
function readWriteAsync(file, toReplace, replacement) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
fs.readFile(file, 'utf-8', function (err, data) {
|
|
if (err)
|
|
throw err;
|
|
var newValue = data.replace(toReplace, replacement);
|
|
fs.writeFile(file, newValue, 'utf-8', function (err) {
|
|
if (err)
|
|
throw err;
|
|
});
|
|
});
|
|
});
|
|
}
|