mirror of
https://github.com/DeLaGuardo/setup-clojure.git
synced 2024-12-26 07:53:20 +08:00
Add tools deps install
This commit is contained in:
parent
80cd371e47
commit
427cb542dc
26
.github/workflows/workflow.yml
vendored
Normal file
26
.github/workflows/workflow.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
name: Tests
|
||||
on: [push]
|
||||
jobs:
|
||||
run:
|
||||
name: Run
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: Set Node.js 12.x
|
||||
uses: actions/setup-node@master
|
||||
with:
|
||||
version: 12.x
|
||||
|
||||
- name: npm install
|
||||
run: npm install
|
||||
|
||||
- name: Lint
|
||||
run: npm run format-check
|
||||
|
||||
- name: npm test
|
||||
run: npm test
|
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# Explicitly not ignoring node_modules so that they are included in package downloaded by runner
|
||||
!node_modules/
|
||||
__tests__/runner/*
|
||||
|
||||
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
.DS_Store
|
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 GitHub, Inc. and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
81
__tests__/tdeps.test.ts
Normal file
81
__tests__/tdeps.test.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import io = require('@actions/io');
|
||||
import os = require('os');
|
||||
import fs = require('fs');
|
||||
import path = require('path');
|
||||
|
||||
const toolDir = path.join(__dirname, 'runner', 'tools');
|
||||
const tempDir = path.join(__dirname, 'runner', 'temp');
|
||||
|
||||
process.env['RUNNER_TOOL_CACHE'] = toolDir;
|
||||
process.env['RUNNER_TEMP'] = tempDir;
|
||||
import * as tdeps from '../src/tdeps';
|
||||
|
||||
describe('tdeps tests', () => {
|
||||
beforeAll(async () => {
|
||||
await io.rmRF(toolDir);
|
||||
await io.rmRF(tempDir);
|
||||
}, 300000);
|
||||
|
||||
afterAll(async () => {
|
||||
try {
|
||||
await io.rmRF(toolDir);
|
||||
await io.rmRF(tempDir);
|
||||
} catch {
|
||||
console.log('Failed to remove test directories');
|
||||
}
|
||||
}, 100000);
|
||||
|
||||
it('Throws if invalid version', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
await tdeps.setup('1000');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
|
||||
it('Install clojure tools deps with normal version', async () => {
|
||||
await tdeps.setup('1.10.1.469');
|
||||
const clojureDir = path.join(
|
||||
toolDir,
|
||||
'ClojureToolsDeps',
|
||||
'1.10.1-469',
|
||||
os.arch()
|
||||
);
|
||||
|
||||
expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(clojureDir, 'bin', 'clojure'))).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('Uses version of clojure tools-deps installed in cache', async () => {
|
||||
const clojureDir: string = path.join(
|
||||
toolDir,
|
||||
'ClojureToolsDeps',
|
||||
'1.10.1-469',
|
||||
os.arch()
|
||||
);
|
||||
await io.mkdirP(clojureDir);
|
||||
fs.writeFileSync(`${clojureDir}.complete`, 'hello');
|
||||
await tdeps.setup('1.10.1.469');
|
||||
return;
|
||||
});
|
||||
|
||||
it('Doesnt use version of clojure that was only partially installed in cache', async () => {
|
||||
const clojureDir: string = path.join(
|
||||
toolDir,
|
||||
'ClojureToolsDeps',
|
||||
'1.10.1-469',
|
||||
os.arch()
|
||||
);
|
||||
await io.mkdirP(clojureDir);
|
||||
let thrown = false;
|
||||
try {
|
||||
await tdeps.setup('1000');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
return;
|
||||
});
|
||||
});
|
16
action.yml
Normal file
16
action.yml
Normal file
@ -0,0 +1,16 @@
|
||||
name: 'Setup Clojure'
|
||||
description: 'Setup your runner with Clojure build tools'
|
||||
author: 'DeLaGuardo'
|
||||
branding:
|
||||
icon: 'gift'
|
||||
color: 'blue'
|
||||
inputs:
|
||||
liningen:
|
||||
description: 'The Leiningen version to make available on the path.'
|
||||
boot:
|
||||
description: 'The boot-clj version to make available on the path.'
|
||||
tools-deps:
|
||||
description: 'The tools deps version to make available on the path.'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/setup-clojure.js'
|
11
jest.config.js
Normal file
11
jest.config.js
Normal file
@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
17
lib/boot.js
Normal file
17
lib/boot.js
Normal file
@ -0,0 +1,17 @@
|
||||
"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());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function setup(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
throw new Error('Not yet available');
|
||||
});
|
||||
}
|
||||
exports.setup = setup;
|
146
lib/installer.js
Normal file
146
lib/installer.js
Normal file
@ -0,0 +1,146 @@
|
||||
"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 });
|
||||
let tempDirectory = process.env['RUNNER_TEMP'] || '';
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const io = __importStar(require("@actions/io"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const tc = __importStar(require("@actions/tool-cache"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const os = __importStar(require("os"));
|
||||
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');
|
||||
}
|
||||
let platform = '';
|
||||
if (IS_WINDOWS) {
|
||||
platform = 'windows';
|
||||
}
|
||||
else {
|
||||
if (process.platform === 'darwin') {
|
||||
platform = 'darwin';
|
||||
}
|
||||
else {
|
||||
platform = 'linux';
|
||||
}
|
||||
}
|
||||
function getGraalVM(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let toolPath = tc.find('GraalVM', getCacheVersionString(version), os.arch());
|
||||
let compressedFileExtension = '';
|
||||
if (toolPath) {
|
||||
core.debug(`GraalVM found in cache ${toolPath}`);
|
||||
}
|
||||
else {
|
||||
core.debug('Downloading GraalVM from https://github.com/oracle/graal/releases');
|
||||
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
|
||||
let graalvmFile = yield tc.downloadTool(`https://github.com/oracle/graal/releases/download/vm-${version}/graalvm-ce-${platform}-amd64-${version}${compressedFileExtension}`);
|
||||
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
|
||||
const graalvmDir = yield unzipGraalVMDownload(graalvmFile, compressedFileExtension, tempDir);
|
||||
core.debug(`graalvm extracted to ${graalvmDir}`);
|
||||
toolPath = yield tc.cacheDir(graalvmDir, 'GraalVM', getCacheVersionString(version));
|
||||
}
|
||||
let extendedJavaHome = 'JAVA_HOME_' + version;
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.exportVariable(extendedJavaHome, toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
});
|
||||
}
|
||||
exports.getGraalVM = getGraalVM;
|
||||
function getCacheVersionString(version) {
|
||||
const versionArray = version.split('.');
|
||||
const major = versionArray[0];
|
||||
const minor = versionArray.length > 1 ? versionArray[1] : '0';
|
||||
const patch = versionArray.length > 2 ? versionArray.slice(2).join('-') : '0';
|
||||
return `${major}.${minor}.${patch}`;
|
||||
}
|
||||
function extractFiles(file, fileEnding, destinationFolder) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const stats = fs.statSync(file);
|
||||
if (!stats) {
|
||||
throw new Error(`Failed to extract ${file} - it doesn't exist`);
|
||||
}
|
||||
else if (stats.isDirectory()) {
|
||||
throw new Error(`Failed to extract ${file} - it is a directory`);
|
||||
}
|
||||
if ('.tar.gz' === fileEnding) {
|
||||
yield tc.extractTar(file, destinationFolder);
|
||||
}
|
||||
else if ('.zip' === fileEnding) {
|
||||
yield tc.extractZip(file, destinationFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
function unpackJars(fsPath, javaBinPath) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (fs.existsSync(fsPath)) {
|
||||
if (fs.lstatSync(fsPath).isDirectory()) {
|
||||
for (const file in fs.readdirSync(fsPath)) {
|
||||
const curPath = path.join(fsPath, file);
|
||||
yield unpackJars(curPath, javaBinPath);
|
||||
}
|
||||
}
|
||||
else if (path.extname(fsPath).toLowerCase() === '.pack') {
|
||||
// Unpack the pack file synchonously
|
||||
const p = path.parse(fsPath);
|
||||
const toolName = IS_WINDOWS ? 'unpack200.exe' : 'unpack200';
|
||||
const args = IS_WINDOWS ? '-r -v -l ""' : '';
|
||||
const name = path.join(p.dir, p.name);
|
||||
yield exec.exec(`"${path.join(javaBinPath, toolName)}"`, [
|
||||
`${args} "${name}.pack" "${name}.jar"`
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function unzipGraalVMDownload(repoRoot, fileEnding, destinationFolder) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield io.mkdirP(destinationFolder);
|
||||
const graalvmFile = path.normalize(repoRoot);
|
||||
const stats = fs.statSync(graalvmFile);
|
||||
if (stats.isFile()) {
|
||||
yield extractFiles(graalvmFile, fileEnding, destinationFolder);
|
||||
const graalvmFolder = fs.readdirSync(destinationFolder)[0];
|
||||
if (process.platform === 'darwin') {
|
||||
for (const f of fs.readdirSync(path.join(destinationFolder, graalvmFolder, 'Contents', 'Home'))) {
|
||||
yield io.cp(path.join(destinationFolder, graalvmFolder, 'Contents', 'Home', f), path.join(destinationFolder, graalvmFolder, f), { recursive: true });
|
||||
}
|
||||
yield io.rmRF(path.join(destinationFolder, graalvmFolder, 'Contents'));
|
||||
}
|
||||
const graalvmDirectory = path.join(destinationFolder, graalvmFolder);
|
||||
yield unpackJars(graalvmDirectory, path.join(graalvmDirectory, 'bin'));
|
||||
return graalvmDirectory;
|
||||
}
|
||||
else {
|
||||
throw new Error(`Jdk argument ${graalvmFile} is not a file`);
|
||||
}
|
||||
});
|
||||
}
|
17
lib/leiningen.js
Normal file
17
lib/leiningen.js
Normal file
@ -0,0 +1,17 @@
|
||||
"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());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function setup(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
throw new Error('Not yet available');
|
||||
});
|
||||
}
|
||||
exports.setup = setup;
|
47
lib/setup-clojure.js
Normal file
47
lib/setup-clojure.js
Normal file
@ -0,0 +1,47 @@
|
||||
"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 lein = __importStar(require("./leiningen"));
|
||||
const boot = __importStar(require("./boot"));
|
||||
const tdeps = __importStar(require("./tdeps"));
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const Lein = core.getInput('lein');
|
||||
const Boot = core.getInput('boot');
|
||||
const Tdeps = core.getInput('tools-deps');
|
||||
if (Lein) {
|
||||
lein.setup(Lein);
|
||||
}
|
||||
if (Boot) {
|
||||
boot.setup(Boot);
|
||||
}
|
||||
if (Tdeps) {
|
||||
tdeps.setup(Tdeps);
|
||||
}
|
||||
if (!Boot && !Lein && !Tdeps) {
|
||||
throw new Error('You must specify at least one clojure tool.');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
run();
|
104
lib/tdeps.js
Normal file
104
lib/tdeps.js
Normal file
@ -0,0 +1,104 @@
|
||||
"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 (IS_WINDOWS) {
|
||||
throw new Error('Windows is not supported yet.');
|
||||
}
|
||||
if (!tempDirectory) {
|
||||
let baseLocation;
|
||||
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('ClojureToolsDeps', utils.getCacheVersionString(version), os.arch());
|
||||
if (toolPath) {
|
||||
core.debug(`Clojure CLI found in cache ${toolPath}`);
|
||||
}
|
||||
else {
|
||||
let clojureToolsFile = yield tc.downloadTool(`https://download.clojure.org/install/clojure-tools-${version}.tar.gz`);
|
||||
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
|
||||
const clojureToolsDir = yield installClojureToolsDeps(clojureToolsFile, tempDir, version);
|
||||
core.debug(`clojure tools deps installed to ${clojureToolsDir}`);
|
||||
toolPath = yield tc.cacheDir(clojureToolsDir, 'ClojureToolsDeps', utils.getCacheVersionString(version));
|
||||
}
|
||||
const installDir = path.join(toolPath, 'lib', 'clojure');
|
||||
core.exportVariable('CLOJURE_INSTALL_DIR', installDir);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
});
|
||||
}
|
||||
exports.setup = setup;
|
||||
function installClojureToolsDeps(installScript, destinationFolder, version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield io.mkdirP(destinationFolder);
|
||||
const file = path.normalize(installScript);
|
||||
const stats = fs.statSync(file);
|
||||
if (stats.isFile()) {
|
||||
const binDir = path.join(destinationFolder, 'clojure', 'bin');
|
||||
const libDir = path.join(destinationFolder, 'clojure', 'lib');
|
||||
const manDir = path.join(destinationFolder, 'clojure', 'share', 'man', 'man1');
|
||||
const clojureLibDir = path.join(libDir, 'clojure');
|
||||
const clojureLibexecDir = path.join(clojureLibDir, 'libexec');
|
||||
yield tc.extractTar(file, destinationFolder);
|
||||
const sourceDir = path.join(destinationFolder, 'clojure-tools');
|
||||
yield io.mkdirP(binDir);
|
||||
yield io.mkdirP(manDir);
|
||||
yield io.mkdirP(clojureLibexecDir);
|
||||
yield io.mv(path.join(sourceDir, 'deps.edn'), clojureLibDir);
|
||||
yield io.mv(path.join(sourceDir, 'example-deps.edn'), clojureLibDir);
|
||||
yield io.mv(path.join(sourceDir, `clojure-tools-${version}.jar`), clojureLibexecDir);
|
||||
yield readWriteAsync(path.join(sourceDir, 'clojure'), '"$CLOJURE_INSTALL_DIR"');
|
||||
yield io.mv(path.join(sourceDir, 'clj'), binDir);
|
||||
yield io.mv(path.join(sourceDir, 'clojure'), binDir);
|
||||
yield io.mv(path.join(sourceDir, 'clojure.1'), manDir);
|
||||
yield io.mv(path.join(sourceDir, 'clj.1'), manDir);
|
||||
return `${destinationFolder}/clojure`;
|
||||
}
|
||||
else {
|
||||
throw new Error(`Not a file`);
|
||||
}
|
||||
});
|
||||
}
|
||||
function readWriteAsync(file, 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(/PREFIX/gim, replacement);
|
||||
fs.writeFile(file, newValue, 'utf-8', function (err) {
|
||||
if (err)
|
||||
throw err;
|
||||
console.log('filelistAsync complete');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
10
lib/utils.js
Normal file
10
lib/utils.js
Normal file
@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function getCacheVersionString(version) {
|
||||
const versionArray = version.split('.');
|
||||
const major = versionArray[0];
|
||||
const minor = versionArray.length > 1 ? versionArray[1] : '0';
|
||||
const patch = versionArray.length > 2 ? versionArray.slice(2).join('-') : '0';
|
||||
return `${major}.${minor}.${patch}`;
|
||||
}
|
||||
exports.getCacheVersionString = getCacheVersionString;
|
5409
package-lock.json
generated
Normal file
5409
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
package.json
Normal file
48
package.json
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "setup-clojure",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "setup clojure action",
|
||||
"main": "lib/setup-clojure.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/DeLaGuardo/setup-clojure.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"node",
|
||||
"setup"
|
||||
],
|
||||
"author": "DeLaGuardo",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.1.3",
|
||||
"@actions/exec": "^1.0.1",
|
||||
"@actions/io": "^1.0.1",
|
||||
"@actions/tool-cache": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.13",
|
||||
"@types/node": "^12.0.4",
|
||||
"@types/semver": "^6.0.0",
|
||||
"husky": "^3.0.0",
|
||||
"jest": "^24.8.0",
|
||||
"jest-circus": "^24.7.1",
|
||||
"prettier": "^1.17.1",
|
||||
"ts-jest": "^24.0.2",
|
||||
"typescript": "^3.5.1"
|
||||
},
|
||||
"husky": {
|
||||
"skipCI": true,
|
||||
"hooks": {
|
||||
"pre-commit": "npm run build && npm run format",
|
||||
"post-commit": "npm prune --production && git add node_modules/* && git commit -m \"Husky commit correct node modules\""
|
||||
}
|
||||
}
|
||||
}
|
3
src/boot.ts
Normal file
3
src/boot.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export async function setup(version: string): Promise<void> {
|
||||
throw new Error('Not yet available');
|
||||
}
|
3
src/leiningen.ts
Normal file
3
src/leiningen.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export async function setup(version: string): Promise<void> {
|
||||
throw new Error('Not yet available');
|
||||
}
|
32
src/setup-clojure.ts
Normal file
32
src/setup-clojure.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as lein from './leiningen';
|
||||
import * as boot from './boot';
|
||||
import * as tdeps from './tdeps';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const Lein = core.getInput('lein');
|
||||
const Boot = core.getInput('boot');
|
||||
const Tdeps = core.getInput('tools-deps');
|
||||
|
||||
if (Lein) {
|
||||
lein.setup(Lein);
|
||||
}
|
||||
|
||||
if (Boot) {
|
||||
boot.setup(Boot);
|
||||
}
|
||||
|
||||
if (Tdeps) {
|
||||
tdeps.setup(Tdeps);
|
||||
}
|
||||
|
||||
if (!Boot && !Lein && !Tdeps) {
|
||||
throw new Error('You must specify at least one clojure tool.');
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
128
src/tdeps.ts
Normal file
128
src/tdeps.ts
Normal file
@ -0,0 +1,128 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as utils from './utils';
|
||||
|
||||
let tempDirectory = process.env['RUNNER_TEMP'] || '';
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
|
||||
if (IS_WINDOWS) {
|
||||
throw new Error('Windows is not supported yet.');
|
||||
}
|
||||
|
||||
if (!tempDirectory) {
|
||||
let baseLocation;
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
baseLocation = '/Users';
|
||||
} else {
|
||||
baseLocation = '/home';
|
||||
}
|
||||
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
||||
}
|
||||
|
||||
export async function setup(version: string): Promise<void> {
|
||||
let toolPath = tc.find(
|
||||
'ClojureToolsDeps',
|
||||
utils.getCacheVersionString(version),
|
||||
os.arch()
|
||||
);
|
||||
|
||||
if (toolPath) {
|
||||
core.debug(`Clojure CLI found in cache ${toolPath}`);
|
||||
} else {
|
||||
let clojureToolsFile = await tc.downloadTool(
|
||||
`https://download.clojure.org/install/clojure-tools-${version}.tar.gz`
|
||||
);
|
||||
let tempDir: string = path.join(
|
||||
tempDirectory,
|
||||
'temp_' + Math.floor(Math.random() * 2000000000)
|
||||
);
|
||||
const clojureToolsDir = await installClojureToolsDeps(
|
||||
clojureToolsFile,
|
||||
tempDir,
|
||||
version
|
||||
);
|
||||
core.debug(`clojure tools deps installed to ${clojureToolsDir}`);
|
||||
toolPath = await tc.cacheDir(
|
||||
clojureToolsDir,
|
||||
'ClojureToolsDeps',
|
||||
utils.getCacheVersionString(version)
|
||||
);
|
||||
}
|
||||
|
||||
const installDir = path.join(toolPath, 'lib', 'clojure');
|
||||
core.exportVariable('CLOJURE_INSTALL_DIR', installDir);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
}
|
||||
|
||||
async function installClojureToolsDeps(
|
||||
installScript: string,
|
||||
destinationFolder: string,
|
||||
version: string
|
||||
): Promise<string> {
|
||||
await io.mkdirP(destinationFolder);
|
||||
|
||||
const file = path.normalize(installScript);
|
||||
const stats = fs.statSync(file);
|
||||
if (stats.isFile()) {
|
||||
const binDir = path.join(destinationFolder, 'clojure', 'bin');
|
||||
const libDir = path.join(destinationFolder, 'clojure', 'lib');
|
||||
const manDir = path.join(
|
||||
destinationFolder,
|
||||
'clojure',
|
||||
'share',
|
||||
'man',
|
||||
'man1'
|
||||
);
|
||||
const clojureLibDir = path.join(libDir, 'clojure');
|
||||
const clojureLibexecDir = path.join(clojureLibDir, 'libexec');
|
||||
|
||||
await tc.extractTar(file, destinationFolder);
|
||||
|
||||
const sourceDir = path.join(destinationFolder, 'clojure-tools');
|
||||
|
||||
await io.mkdirP(binDir);
|
||||
await io.mkdirP(manDir);
|
||||
await io.mkdirP(clojureLibexecDir);
|
||||
|
||||
await io.mv(path.join(sourceDir, 'deps.edn'), clojureLibDir);
|
||||
await io.mv(path.join(sourceDir, 'example-deps.edn'), clojureLibDir);
|
||||
await io.mv(
|
||||
path.join(sourceDir, `clojure-tools-${version}.jar`),
|
||||
clojureLibexecDir
|
||||
);
|
||||
await readWriteAsync(
|
||||
path.join(sourceDir, 'clojure'),
|
||||
'"$CLOJURE_INSTALL_DIR"'
|
||||
);
|
||||
await io.mv(path.join(sourceDir, 'clj'), binDir);
|
||||
await io.mv(path.join(sourceDir, 'clojure'), binDir);
|
||||
await io.mv(path.join(sourceDir, 'clojure.1'), manDir);
|
||||
await io.mv(path.join(sourceDir, 'clj.1'), manDir);
|
||||
|
||||
return `${destinationFolder}/clojure`;
|
||||
} else {
|
||||
throw new Error(`Not a file`);
|
||||
}
|
||||
}
|
||||
|
||||
async function readWriteAsync(
|
||||
file: string,
|
||||
replacement: string
|
||||
): Promise<void> {
|
||||
fs.readFile(file, 'utf-8', function(err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var newValue = data.replace(/PREFIX/gim, replacement);
|
||||
|
||||
fs.writeFile(file, newValue, 'utf-8', function(err) {
|
||||
if (err) throw err;
|
||||
console.log('filelistAsync complete');
|
||||
});
|
||||
});
|
||||
}
|
7
src/utils.ts
Normal file
7
src/utils.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export function getCacheVersionString(version: string) {
|
||||
const versionArray = version.split('.');
|
||||
const major = versionArray[0];
|
||||
const minor = versionArray.length > 1 ? versionArray[1] : '0';
|
||||
const patch = versionArray.length > 2 ? versionArray.slice(2).join('-') : '0';
|
||||
return `${major}.${minor}.${patch}`;
|
||||
}
|
63
tsconfig.json
Normal file
63
tsconfig.json
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es6", /* 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'. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user