Use linux-install script

This commit is contained in:
Kirill Chernyshov 2021-12-01 18:29:45 +01:00
parent 0c3aaf47fb
commit b43e1c94d9
No known key found for this signature in database
GPG Key ID: 83C196363AF97C4C
6 changed files with 1377 additions and 447 deletions

82
dist/index.js vendored
View File

@ -4052,9 +4052,12 @@ function setup(version) {
core.info(`Clojure CLI found in cache ${toolPath}`); core.info(`Clojure CLI found in cache ${toolPath}`);
} }
else { else {
const clojureToolsFile = yield tc.downloadTool(`https://download.clojure.org/install/clojure-tools${version === 'latest' ? '' : `-${version}`}.tar.gz`);
const tempDir = path.join(tempDirectory, `temp_${Math.floor(Math.random() * 2000000000)}`); const tempDir = path.join(tempDirectory, `temp_${Math.floor(Math.random() * 2000000000)}`);
const clojureToolsDir = yield installClojureToolsDeps(clojureToolsFile, tempDir); const clojureInstallScript = yield tc.downloadTool(`https://download.clojure.org/install/linux-install${version === 'latest' ? '' : `-${version}`}.sh`);
if (utils.isMacOS()) {
yield MacOSDeps(clojureInstallScript);
}
const clojureToolsDir = yield runLinuxInstall(clojureInstallScript, tempDir);
core.debug(`clojure tools deps installed to ${clojureToolsDir}`); core.debug(`clojure tools deps installed to ${clojureToolsDir}`);
toolPath = yield tc.cacheDir(clojureToolsDir, 'ClojureToolsDeps', utils.getCacheVersionString(version)); toolPath = yield tc.cacheDir(clojureToolsDir, 'ClojureToolsDeps', utils.getCacheVersionString(version));
} }
@ -4064,6 +4067,28 @@ function setup(version) {
}); });
} }
exports.setup = setup; exports.setup = setup;
function runLinuxInstall(installScript, destinationFolder) {
return __awaiter(this, void 0, void 0, function* () {
yield io.mkdirP(destinationFolder);
const file = path.normalize(installScript);
yield exec.exec('bash', [file, '--prefix', destinationFolder]);
return destinationFolder;
});
}
function MacOSDeps(file) {
return __awaiter(this, void 0, void 0, function* () {
fs.readFile(file, 'utf-8', function (err, data) {
if (err)
throw err;
const newValue = data.replace(/install -D/gim, '$(brew --prefix coreutils)/bin/ginstall -D');
fs.writeFile(file, newValue, 'utf-8', function (e) {
if (e)
throw e;
});
});
yield exec.exec(`brew install coreutils`);
});
}
function setupWindows(version) { function setupWindows(version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const url = `download.clojure.org/install/win-install-${version}.ps1`; const url = `download.clojure.org/install/win-install-${version}.ps1`;
@ -4073,53 +4098,6 @@ function setupWindows(version) {
}); });
} }
exports.setupWindows = setupWindows; exports.setupWindows = setupWindows;
function installClojureToolsDeps(installScript, destinationFolder) {
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 Promise.all(fs
.readdirSync(sourceDir)
.filter(f => f.endsWith('jar') || f.endsWith('edn'))
.map((f) => __awaiter(this, void 0, void 0, function* () {
return yield io.mv(path.join(sourceDir, f), f.endsWith('jar') ? clojureLibexecDir : clojureLibDir);
})));
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 path.join(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;
const newValue = data.replace(/PREFIX/gim, replacement);
fs.writeFile(file, newValue, 'utf-8', function (e) {
if (e)
throw e;
});
});
});
}
/***/ }), /***/ }),
@ -5373,7 +5351,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.isWindows = exports.getTempDir = exports.getCacheVersionString = void 0; exports.isMacOS = exports.isWindows = exports.getTempDir = exports.getCacheVersionString = void 0;
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const version_1 = __webpack_require__(775); const version_1 = __webpack_require__(775);
function getCacheVersionString(version) { function getCacheVersionString(version) {
@ -5411,6 +5389,10 @@ function isWindows() {
return process.platform === 'win32'; return process.platform === 'win32';
} }
exports.isWindows = isWindows; exports.isWindows = isWindows;
function isMacOS() {
return process.platform === 'darwin';
}
exports.isMacOS = isMacOS;
/***/ }), /***/ }),

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

1631
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -32,17 +32,17 @@
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.3", "@types/jest": "^27.0.3",
"@types/node": "^16.11.9", "@types/node": "^16.11.11",
"@types/semver": "^7.3.9", "@types/semver": "^7.3.9",
"@typescript-eslint/parser": "^5.4.0", "@typescript-eslint/parser": "^5.5.0",
"@zeit/ncc": "^0.22.3", "@zeit/ncc": "^0.22.3",
"eslint": "^8.3.0", "eslint": "^8.3.0",
"eslint-plugin-github": "^4.3.5", "eslint-plugin-github": "^4.3.5",
"eslint-plugin-jest": "^25.2.4", "eslint-plugin-jest": "^25.3.0",
"jest": "^27.3.1", "jest": "^27.4.3",
"jest-circus": "^27.3.1", "jest-circus": "^27.4.2",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "2.4.1", "prettier": "2.5.0",
"ts-jest": "^27.0.7", "ts-jest": "^27.0.7",
"typescript": "^4.5.2" "typescript": "^4.5.2"
} }

View File

@ -19,19 +19,21 @@ export async function setup(version: string): Promise<void> {
if (toolPath && version !== 'latest') { if (toolPath && version !== 'latest') {
core.info(`Clojure CLI found in cache ${toolPath}`) core.info(`Clojure CLI found in cache ${toolPath}`)
} else { } else {
const clojureToolsFile = await tc.downloadTool(
`https://download.clojure.org/install/clojure-tools${
version === 'latest' ? '' : `-${version}`
}.tar.gz`
)
const tempDir: string = path.join( const tempDir: string = path.join(
tempDirectory, tempDirectory,
`temp_${Math.floor(Math.random() * 2000000000)}` `temp_${Math.floor(Math.random() * 2000000000)}`
) )
const clojureToolsDir = await installClojureToolsDeps( const clojureInstallScript = await tc.downloadTool(
clojureToolsFile, `https://download.clojure.org/install/linux-install${
tempDir version === 'latest' ? '' : `-${version}`
}.sh`
) )
if (utils.isMacOS()) {
await MacOSDeps(clojureInstallScript)
}
const clojureToolsDir = await runLinuxInstall(clojureInstallScript, tempDir)
core.debug(`clojure tools deps installed to ${clojureToolsDir}`) core.debug(`clojure tools deps installed to ${clojureToolsDir}`)
toolPath = await tc.cacheDir( toolPath = await tc.cacheDir(
clojureToolsDir, clojureToolsDir,
@ -45,80 +47,37 @@ export async function setup(version: string): Promise<void> {
core.addPath(path.join(toolPath, 'bin')) core.addPath(path.join(toolPath, 'bin'))
} }
export async function setupWindows(version: string): Promise<void> { async function runLinuxInstall(
const url = `download.clojure.org/install/win-install-${version}.ps1`
exec.exec(`powershell -c "iwr -useb ${url} | iex"`, [], {
input: Buffer.from('1')
})
}
async function installClojureToolsDeps(
installScript: string, installScript: string,
destinationFolder: string destinationFolder: string
): Promise<string> { ): Promise<string> {
await io.mkdirP(destinationFolder) await io.mkdirP(destinationFolder)
const file = path.normalize(installScript) const file = path.normalize(installScript)
const stats = fs.statSync(file) await exec.exec('bash', [file, '--prefix', destinationFolder])
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) return destinationFolder
const sourceDir = path.join(destinationFolder, 'clojure-tools')
await io.mkdirP(binDir)
await io.mkdirP(manDir)
await io.mkdirP(clojureLibexecDir)
await Promise.all(
fs
.readdirSync(sourceDir)
.filter(f => f.endsWith('jar') || f.endsWith('edn'))
.map(
async (f): Promise<void> =>
await io.mv(
path.join(sourceDir, f),
f.endsWith('jar') ? clojureLibexecDir : clojureLibDir
)
)
)
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 path.join(destinationFolder, 'clojure')
} else {
throw new Error(`Not a file`)
}
} }
async function readWriteAsync( async function MacOSDeps(file: string): Promise<void> {
file: string,
replacement: string
): Promise<void> {
fs.readFile(file, 'utf-8', function (err, data) { fs.readFile(file, 'utf-8', function (err, data) {
if (err) throw err if (err) throw err
const newValue = data.replace(/PREFIX/gim, replacement) const newValue = data.replace(
/install -D/gim,
'$(brew --prefix coreutils)/bin/ginstall -D'
)
fs.writeFile(file, newValue, 'utf-8', function (e) { fs.writeFile(file, newValue, 'utf-8', function (e) {
if (e) throw e if (e) throw e
}) })
}) })
await exec.exec(`brew install coreutils`)
}
export async function setupWindows(version: string): Promise<void> {
const url = `download.clojure.org/install/win-install-${version}.ps1`
exec.exec(`powershell -c "iwr -useb ${url} | iex"`, [], {
input: Buffer.from('1')
})
} }

View File

@ -33,3 +33,7 @@ export function getTempDir(): string {
export function isWindows(): boolean { export function isWindows(): boolean {
return process.platform === 'win32' return process.platform === 'win32'
} }
export function isMacOS(): boolean {
return process.platform === 'darwin'
}