From d34f36f7b459d995fea3bdb0c0483017134d8adc Mon Sep 17 00:00:00 2001 From: Kirill Chernyshov Date: Mon, 7 Oct 2019 13:57:39 +0200 Subject: [PATCH] fix --- .github/workflows/workflow.yml | 2 +- __tests__/leiningen.test.ts | 113 ++++++++-------- lib/leiningen.js | 40 ++---- lib/setup-clojure.js | 10 +- package-lock.json | 228 --------------------------------- src/leiningen.ts | 144 +++++++++------------ src/setup-clojure.ts | 44 +++---- 7 files changed, 156 insertions(+), 425 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 20e6495..3d93975 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -6,7 +6,7 @@ jobs: runs-on: ${{ matrix.operating-system }} strategy: matrix: - operating-system: [ubuntu-latest, macOS-latest, windows-latest] + operating-system: [ubuntu-latest, macOS-latest] steps: - name: Checkout uses: actions/checkout@master diff --git a/__tests__/leiningen.test.ts b/__tests__/leiningen.test.ts index f8b19fe..9a9ed6a 100644 --- a/__tests__/leiningen.test.ts +++ b/__tests__/leiningen.test.ts @@ -1,12 +1,12 @@ import io = require('@actions/io'); import exec = require('@actions/exec'); +import core = require('@actions/core'); import os = require('os'); import fs = require('fs'); import path = require('path'); const toolDir = path.join(__dirname, 'runner', 'tools', 'leiningen'); const tempDir = path.join(__dirname, 'runner', 'temp', 'leiningen'); -const IS_WINDOWS = process.platform === 'win32'; process.env['RUNNER_TOOL_CACHE'] = toolDir; process.env['RUNNER_TEMP'] = tempDir; @@ -27,64 +27,63 @@ describe('leiningen tests', () => { } }, 100000); - it('Throws if invalid version', async () => { - let thrown = false; - try { - await leiningen.setup('1000'); - } catch { - thrown = true; - } - expect(thrown).toBe(true); - }); + it('Throws if invalid version', async () => { + let thrown = false; + try { + await leiningen.setup('1000'); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); - it('Install leiningen with normal version', async () => { - await leiningen.setup('2.9.1'); - const clojureDir = path.join( - toolDir, - 'ClojureLeiningen', - '2.9.1', - os.arch() - ); + it('Install leiningen with normal version', async () => { + await leiningen.setup('2.9.1'); + const clojureDir = path.join( + toolDir, + 'ClojureLeiningen', + '2.9.1', + os.arch() + ); - expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true); - if (IS_WINDOWS) { - expect(fs.existsSync(path.join(clojureDir, 'bin', 'lein.bat'))).toBe( - true - ); - await exec.exec('lein'); - } else { - expect(fs.existsSync(path.join(clojureDir, 'bin', 'lein'))).toBe(true); - } - }, 100000); + expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true); + expect(fs.existsSync(path.join(clojureDir, 'bin', 'lein'))).toBe(true); - it('Uses version of leiningen installed in cache', async () => { - const clojureDir: string = path.join( - toolDir, - 'ClojureLeiningen', - '2.9.1', - os.arch() - ); - await io.mkdirP(clojureDir); - fs.writeFileSync(`${clojureDir}.complete`, 'hello'); - await leiningen.setup('2.9.1'); - return; - }); + const leinPath: string = await io.which('lein', true) + core.debug(`Leiningen path: ${leinPath}`); - it('Doesnt use version of clojure that was only partially installed in cache', async () => { - const clojureDir: string = path.join( - toolDir, - 'ClojureLeiningen', - '2.9.1', - os.arch() - ); - await io.mkdirP(clojureDir); - let thrown = false; - try { - await leiningen.setup('1000'); - } catch { - thrown = true; - } - expect(thrown).toBe(true); - return; - }); + await exec.exec('echo $LEIN_HOME'); + await exec.exec('lein'); + }, 100000); + + it('Uses version of leiningen installed in cache', async () => { + const clojureDir: string = path.join( + toolDir, + 'ClojureLeiningen', + '2.9.1', + os.arch() + ); + await io.mkdirP(clojureDir); + fs.writeFileSync(`${clojureDir}.complete`, 'hello'); + await leiningen.setup('2.9.1'); + return; + }); + + it('Doesnt use version of clojure that was only partially installed in cache', async () => { + const clojureDir: string = path.join( + toolDir, + 'ClojureLeiningen', + '2.9.1', + os.arch() + ); + await io.mkdirP(clojureDir); + let thrown = false; + try { + await leiningen.setup('1000'); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + return; + }); }); diff --git a/lib/leiningen.js b/lib/leiningen.js index a108b71..70c7c22 100644 --- a/lib/leiningen.js +++ b/lib/leiningen.js @@ -19,24 +19,19 @@ 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 exec = __importStar(require("@actions/exec")); 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:\\'; + if (process.platform === 'darwin') { + baseLocation = '/Users'; } else { - if (process.platform === 'darwin') { - baseLocation = '/Users'; - } - else { - baseLocation = '/home'; - } + baseLocation = '/home'; } tempDirectory = path.join(baseLocation, 'actions', 'temp'); } @@ -47,39 +42,32 @@ function setup(version) { 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 leiningenFile = yield tc.downloadTool(`https://raw.githubusercontent.com/technomancy/leiningen/${version}/bin/lein`); let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000)); - const leiningenDir = yield installLeiningen(leiningenFile, leiningenLib, tempDir); + const leiningenDir = yield installLeiningen(leiningenFile, tempDir); core.debug(`clojure tools deps installed to ${leiningenDir}`); toolPath = yield tc.cacheDir(leiningenDir, 'ClojureLeiningen', utils.getCacheVersionString(version)); } - core.exportVariable('LEIN_LIB_DIR', toolPath); + core.exportVariable('LEIN_HOME', toolPath); core.addPath(path.join(toolPath, 'bin')); }); } exports.setup = setup; -function installLeiningen(binScript, libFile, destinationFolder) { +function installLeiningen(binScript, 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()) { + if (binStats.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', '!LEIN_LIB_DIR!\libexec\leiningen-standalone.jar'); - } - else { - yield readWriteAsync(path.join(binDir, 'lein'), '/usr/share/java/leiningen-$LEIN_VERSION-standalone.jar', '$LEIN_LIB_DIR/libexec/leiningen-standalone.jar'); - } + yield io.mv(bin, path.join(binDir, `lein`)); + fs.chmodSync(path.join(binDir, `lein`), '0755'); + core.exportVariable('LEIN_HOME', path.join(destinationFolder, 'leiningen')); + core.addPath(path.join(destinationFolder, 'leiningen', 'bin')); + yield exec.exec('lein -h'); return path.join(destinationFolder, 'leiningen'); } else { diff --git a/lib/setup-clojure.js b/lib/setup-clojure.js index 822a086..44db02e 100644 --- a/lib/setup-clojure.js +++ b/lib/setup-clojure.js @@ -27,6 +27,9 @@ function run() { const Lein = core.getInput('lein'); const Boot = core.getInput('boot'); const Tdeps = core.getInput('tools-deps'); + if (IS_WINDOWS) { + throw new Error('Windows is not supported yet.'); + } if (Lein) { lein.setup(Lein); } @@ -34,12 +37,7 @@ function run() { boot.setup(Boot); } if (Tdeps) { - if (IS_WINDOWS) { - throw new Error('Windows is not supported yet'); - } - else { - tdeps.setup(Tdeps); - } + tdeps.setup(Tdeps); } if (!Boot && !Lein && !Tdeps) { throw new Error('You must specify at least one clojure tool.'); diff --git a/package-lock.json b/package-lock.json index ee7a0c3..64a2bee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -545,12 +545,6 @@ "integrity": "sha512-P57oKTJ/vYivL2BCfxCC5tQjlS8qW31pbOL6qt99Yrjm95YdHgNZwjrTTjMBh+C2/y6PXIX4oz253+jUzxKKfQ==", "dev": true }, - "@types/normalize-package-data": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", - "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==", - "dev": true - }, "@types/semver": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-6.0.2.tgz", @@ -657,15 +651,6 @@ "normalize-path": "^2.1.1" } }, - "argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, - "requires": { - "sprintf-js": "~1.0.2" - } - }, "arr-diff": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-4.0.0.tgz", @@ -1016,30 +1001,6 @@ "unset-value": "^1.0.0" } }, - "caller-callsite": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/caller-callsite/-/caller-callsite-2.0.0.tgz", - "integrity": "sha1-hH4PzgoiN1CpoCfFSzNzGtMVQTQ=", - "dev": true, - "requires": { - "callsites": "^2.0.0" - } - }, - "caller-path": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-2.0.0.tgz", - "integrity": "sha1-Ro+DBE42mrIBD6xfBs7uFbsssfQ=", - "dev": true, - "requires": { - "caller-callsite": "^2.0.0" - } - }, - "callsites": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz", - "integrity": "sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA=", - "dev": true - }, "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", @@ -1192,18 +1153,6 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, - "cosmiconfig": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz", - "integrity": "sha512-H65gsXo1SKjf8zmrJ67eJk8aIRKV5ff2D4uKZIBZShbhGSpEmsQOPW/SKMKYhSTrqR7ufy6RP69rPogdaPh/kA==", - "dev": true, - "requires": { - "import-fresh": "^2.0.0", - "is-directory": "^0.3.1", - "js-yaml": "^3.13.1", - "parse-json": "^4.0.0" - } - }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -1467,12 +1416,6 @@ } } }, - "esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true - }, "estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", @@ -1709,16 +1652,6 @@ } } }, - "find-up": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", - "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "dev": true, - "requires": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - } - }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -2317,12 +2250,6 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, - "get-stdin": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-7.0.0.tgz", - "integrity": "sha512-zRKcywvrXlXsA0v0i9Io4KDRaAw7+a1ZpjRwl9Wox8PFlVCCHra7E9c4kqXCoCM9nR5tBkaTTZRBoCm60bFqTQ==", - "dev": true - }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", @@ -2486,25 +2413,6 @@ "sshpk": "^1.7.0" } }, - "husky": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/husky/-/husky-3.0.8.tgz", - "integrity": "sha512-HFOsgcyrX3qe/rBuqyTt+P4Gxn5P0seJmr215LAZ/vnwK3jWB3r0ck7swbzGRUbufCf9w/lgHPVbF/YXQALgfQ==", - "dev": true, - "requires": { - "chalk": "^2.4.2", - "cosmiconfig": "^5.2.1", - "execa": "^1.0.0", - "get-stdin": "^7.0.0", - "is-ci": "^2.0.0", - "opencollective-postinstall": "^2.0.2", - "pkg-dir": "^4.2.0", - "please-upgrade-node": "^3.2.0", - "read-pkg": "^5.1.1", - "run-node": "^1.0.0", - "slash": "^3.0.0" - } - }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -2514,16 +2422,6 @@ "safer-buffer": ">= 2.1.2 < 3" } }, - "import-fresh": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-2.0.0.tgz", - "integrity": "sha1-2BNVwVYS04bGH53dOSLUMEgipUY=", - "dev": true, - "requires": { - "caller-path": "^2.0.0", - "resolve-from": "^3.0.0" - } - }, "import-local": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/import-local/-/import-local-2.0.0.tgz", @@ -2702,12 +2600,6 @@ } } }, - "is-directory": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz", - "integrity": "sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=", - "dev": true - }, "is-extendable": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", @@ -3381,16 +3273,6 @@ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "dev": true }, - "js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", - "dev": true, - "requires": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" - } - }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -3516,12 +3398,6 @@ "type-check": "~0.3.2" } }, - "lines-and-columns": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", - "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=", - "dev": true - }, "load-json-file": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", @@ -3534,15 +3410,6 @@ "strip-bom": "^3.0.0" } }, - "locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "dev": true, - "requires": { - "p-locate": "^4.1.0" - } - }, "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", @@ -3932,12 +3799,6 @@ "wrappy": "1" } }, - "opencollective-postinstall": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz", - "integrity": "sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw==", - "dev": true - }, "optimist": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", @@ -4002,15 +3863,6 @@ "p-try": "^2.0.0" } }, - "p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "dev": true, - "requires": { - "p-limit": "^2.2.0" - } - }, "p-reduce": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-reduce/-/p-reduce-1.0.0.tgz", @@ -4045,12 +3897,6 @@ "integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=", "dev": true }, - "path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true - }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -4099,24 +3945,6 @@ "node-modules-regexp": "^1.0.0" } }, - "pkg-dir": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", - "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", - "dev": true, - "requires": { - "find-up": "^4.0.0" - } - }, - "please-upgrade-node": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz", - "integrity": "sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==", - "dev": true, - "requires": { - "semver-compare": "^1.0.0" - } - }, "pn": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pn/-/pn-1.1.0.tgz", @@ -4197,32 +4025,6 @@ "integrity": "sha512-BXUMf9sIOPXXZWqr7+c5SeOKJykyVr2u0UDzEf4LNGc6taGkQe1A9DFD07umCIXz45RLr9oAAwZbAJ0Pkknfaw==", "dev": true }, - "read-pkg": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", - "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", - "dev": true, - "requires": { - "@types/normalize-package-data": "^2.4.0", - "normalize-package-data": "^2.5.0", - "parse-json": "^5.0.0", - "type-fest": "^0.6.0" - }, - "dependencies": { - "parse-json": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.0.0.tgz", - "integrity": "sha512-OOY5b7PAEFV0E2Fir1KOkxchnZNCdowAJgQ5NuxjpBKTRP3pQhwkrkxqQjeoKJ+fO7bCpmIZaogI4eZGDMEGOw==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "error-ex": "^1.3.1", - "json-parse-better-errors": "^1.0.1", - "lines-and-columns": "^1.1.6" - } - } - } - }, "read-pkg-up": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-4.0.0.tgz", @@ -4446,12 +4248,6 @@ "integrity": "sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==", "dev": true }, - "run-node": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/run-node/-/run-node-1.0.0.tgz", - "integrity": "sha512-kc120TBlQ3mih1LSzdAJXo4xn/GWS2ec0l3S+syHDXP9uRr0JAT8Qd3mdMuyjqCzeZktgP3try92cEgf9Nks8A==", - "dev": true - }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -4501,12 +4297,6 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" }, - "semver-compare": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", - "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=", - "dev": true - }, "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", @@ -4569,12 +4359,6 @@ "integrity": "sha512-SbEG75TzH8G7eVXFSN5f9EExILKfly7SUvVY5DhhYLvfhKqhDFY0OzevWa/zwak0RLRfWS5AvfMWpd9gJvr5Yg==", "dev": true }, - "slash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true - }, "snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", @@ -4764,12 +4548,6 @@ "extend-shallow": "^3.0.0" } }, - "sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true - }, "sshpk": { "version": "1.16.1", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", @@ -5075,12 +4853,6 @@ "prelude-ls": "~1.1.2" } }, - "type-fest": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", - "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", - "dev": true - }, "typed-rest-client": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.5.0.tgz", diff --git a/src/leiningen.ts b/src/leiningen.ts index 1b58e32..2a6b92e 100644 --- a/src/leiningen.ts +++ b/src/leiningen.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; +import * as exec from '@actions/exec'; import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; @@ -8,116 +9,89 @@ import * as utils from './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 { + let baseLocation; if (process.platform === 'darwin') { - baseLocation = '/Users'; + baseLocation = '/Users'; } else { - baseLocation = '/home'; + baseLocation = '/home'; } - } - tempDirectory = path.join(baseLocation, 'actions', 'temp'); + tempDirectory = path.join(baseLocation, 'actions', 'temp'); } export async function setup(version: string): Promise { - let toolPath = tc.find( - 'ClojureLeiningen', - utils.getCacheVersionString(version), - os.arch() - ); + let toolPath = tc.find( + 'ClojureLeiningen', + utils.getCacheVersionString(version), + os.arch() + ); - if (toolPath) { - core.debug(`Leiningen found in cache ${toolPath}`); - } else { - let leiningenFile = await tc.downloadTool( - `https://raw.githubusercontent.com/technomancy/leiningen/${version}/bin/lein${ - IS_WINDOWS ? '.bat' : '-pkg' - }` - ); - let leiningenLib = await tc.downloadTool( - `https://github.com/technomancy/leiningen/releases/download/${version}/leiningen-${version}-standalone.zip` - ); - let tempDir: string = path.join( - tempDirectory, - 'temp_' + Math.floor(Math.random() * 2000000000) - ); - const leiningenDir = await installLeiningen( - leiningenFile, - leiningenLib, - tempDir - ); - core.debug(`clojure tools deps installed to ${leiningenDir}`); - toolPath = await tc.cacheDir( - leiningenDir, - 'ClojureLeiningen', - utils.getCacheVersionString(version) - ); - } + if (toolPath) { + core.debug(`Leiningen found in cache ${toolPath}`); + } else { + let leiningenFile = await tc.downloadTool( + `https://raw.githubusercontent.com/technomancy/leiningen/${version}/bin/lein` + ); + let tempDir: string = path.join( + tempDirectory, + 'temp_' + Math.floor(Math.random() * 2000000000) + ); + const leiningenDir = await installLeiningen( + leiningenFile, + tempDir + ); + core.debug(`clojure tools deps installed to ${leiningenDir}`); + toolPath = await tc.cacheDir( + leiningenDir, + 'ClojureLeiningen', + utils.getCacheVersionString(version) + ); + } - core.exportVariable('LEIN_LIB_DIR', toolPath); - core.addPath(path.join(toolPath, 'bin')); + core.exportVariable('LEIN_HOME', toolPath); + core.addPath(path.join(toolPath, 'bin')); } async function installLeiningen( - binScript: string, - libFile: string, - destinationFolder: string + binScript: string, + destinationFolder: string ): Promise { - await io.mkdirP(destinationFolder); + await 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'); + const bin = path.normalize(binScript); + const binStats = fs.statSync(bin); + if (binStats.isFile()) { + const binDir = path.join(destinationFolder, 'leiningen', 'bin'); + const libDir = path.join(destinationFolder, 'leiningen', 'libexec'); - await io.mkdirP(binDir); - await io.mkdirP(libDir); + await io.mkdirP(binDir); + await io.mkdirP(libDir); - await io.mv(bin, path.join(binDir, `lein${IS_WINDOWS ? '.bat' : ''}`)); - fs.chmodSync(path.join(binDir, `lein${IS_WINDOWS ? '.bat' : ''}`), '0755'); + await io.mv(bin, path.join(binDir, `lein`)); + fs.chmodSync(path.join(binDir, `lein`), '0755'); - await io.mv(lib, path.join(libDir, `leiningen-standalone.jar`)); + core.exportVariable('LEIN_HOME', path.join(destinationFolder, 'leiningen')); + core.addPath(path.join(destinationFolder, 'leiningen', 'bin')); + await exec.exec('lein -h'); - if (IS_WINDOWS) { - await readWriteAsync( - path.join(binDir, 'lein.bat'), - '!LEIN_HOME!\self-installs\leiningen-!LEIN_VERSION!-standalone.jar', - '!LEIN_LIB_DIR!\libexec\leiningen-standalone.jar' - ); + return path.join(destinationFolder, 'leiningen'); } else { - await readWriteAsync( - path.join(binDir, 'lein'), - '/usr/share/java/leiningen-$LEIN_VERSION-standalone.jar', - '$LEIN_LIB_DIR/libexec/leiningen-standalone.jar' - ); + throw new Error('Not a file'); } - - return path.join(destinationFolder, 'leiningen'); - } else { - throw new Error('Not a file'); - } } async function readWriteAsync( - file: string, - toReplace: string, - replacement: string + file: string, + toReplace: string, + replacement: string ): Promise { - fs.readFile(file, 'utf-8', function(err, data) { - if (err) throw err; + fs.readFile(file, 'utf-8', function(err, data) { + if (err) throw err; - var newValue = data.replace(toReplace, replacement); + var newValue = data.replace(toReplace, replacement); - fs.writeFile(file, newValue, 'utf-8', function(err) { - if (err) throw err; + fs.writeFile(file, newValue, 'utf-8', function(err) { + if (err) throw err; + }); }); - }); } diff --git a/src/setup-clojure.ts b/src/setup-clojure.ts index 7eb4642..074b834 100644 --- a/src/setup-clojure.ts +++ b/src/setup-clojure.ts @@ -6,33 +6,33 @@ import * as tdeps from './tdeps'; const IS_WINDOWS = process.platform === 'win32'; async function run() { - try { - const Lein = core.getInput('lein'); - const Boot = core.getInput('boot'); - const Tdeps = core.getInput('tools-deps'); + try { + const Lein = core.getInput('lein'); + const Boot = core.getInput('boot'); + const Tdeps = core.getInput('tools-deps'); - if (Lein) { - lein.setup(Lein); - } + if (IS_WINDOWS) { + throw new Error('Windows is not supported yet.'); + } - if (Boot) { - boot.setup(Boot); - } + if (Lein) { + lein.setup(Lein); + } - if (Tdeps) { - if (IS_WINDOWS) { - throw new Error('Windows is not supported yet'); - } else { - tdeps.setup(Tdeps); - } - } + if (Boot) { + boot.setup(Boot); + } - if (!Boot && !Lein && !Tdeps) { - throw new Error('You must specify at least one clojure tool.'); + 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); } - } catch (error) { - core.setFailed(error.message); - } } run();