From ead3831d7a64e71c65c3148b5b395273d5812199 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Thu, 25 Jun 2020 13:39:22 +0200 Subject: [PATCH] Cache artifacts directory by default --- action.yml | 7 ++++ lib/caching.js | 39 +++++++++++++++++++++ lib/setup-julia.js | 7 ++++ package-lock.json | 85 ++++++++++++++++++++++++++++++++++++++++++---- package.json | 3 ++ src/caching.ts | 25 ++++++++++++++ src/setup-julia.ts | 8 +++++ 7 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 lib/caching.js create mode 100644 src/caching.ts diff --git a/action.yml b/action.yml index 2238557..58f6e09 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,13 @@ inputs: description: 'Display InteractiveUtils.versioninfo() after installing' required: false default: 'false' + cache-artifacts: + description: 'Cache ~/.julia/artifacts. Will fail if no file matches **/Project.toml.' + required: false + default: 'true' +outputs: + artifacts-cache-id: + description: 'The cache id of the artifacts cache.' runs: using: 'node12' main: 'dist/index.js' diff --git a/lib/caching.js b/lib/caching.js new file mode 100644 index 0000000..90defd9 --- /dev/null +++ b/lib/caching.js @@ -0,0 +1,39 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + 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) : new P(function (resolve) { resolve(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 cache = __importStar(require("@actions/cache")); +const glob = __importStar(require("@actions/glob")); +const path = __importStar(require("path")); +// TODO: Change to hashFiles once https://github.com/actions/toolkit/issues/472 has been resolved +const md5File = __importStar(require("md5-file")); +const JULIA_HOME = path.join(`${process.env.HOME}`, '.julia'); +/** + * Cache the ~/.julia/artifacts directory. + */ +function cacheArtifacts() { + return __awaiter(this, void 0, void 0, function* () { + const projectFiles = yield (yield glob.create('**/Project.toml')).glob(); + let projectsHash = ''; + projectFiles.forEach((f) => { + projectsHash.concat('-', md5File.sync(f)); + }); + const paths = [path.join(JULIA_HOME, 'artifacts')]; + const key = `artifacts-${process.env.RUNNER_OS}-${projectsHash}`; + return cache.saveCache(paths, key); + }); +} +exports.cacheArtifacts = cacheArtifacts; diff --git a/lib/setup-julia.js b/lib/setup-julia.js index 25781d1..bf2632f 100644 --- a/lib/setup-julia.js +++ b/lib/setup-julia.js @@ -20,6 +20,7 @@ const exec = __importStar(require("@actions/exec")); const tc = __importStar(require("@actions/tool-cache")); const path = __importStar(require("path")); const installer = __importStar(require("./installer")); +const jlcache = __importStar(require("./caching")); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -49,6 +50,12 @@ function run() { if (core.getInput('show-versioninfo') == 'true') { exec.exec('julia', ['-e', 'using InteractiveUtils; versioninfo()']); } + // Create caches + if (core.getInput('cache-artifacts') == 'true') { + core.debug('caching artifacts directory...'); + const cacheId = yield jlcache.cacheArtifacts(); + core.setOutput('artifacts-cache-id', cacheId.toString()); + } } catch (error) { core.setFailed(error.message); diff --git a/package-lock.json b/package-lock.json index f66a0af..bb0552f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,48 @@ { "name": "setup-julia", - "version": "1.1.5", + "version": "1.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { + "@actions/cache": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-0.2.1.tgz", + "integrity": "sha512-CV2D9zp+d+nL7o6XK/I7vVh350JglPMp/jHi9ppRUkdBHPUeP0UHVUfygZaAs8WmxhhWY1MI0gWah+t0QYu3Fg==", + "requires": { + "@actions/core": "^1.2.4", + "@actions/exec": "^1.0.1", + "@actions/glob": "^0.1.0", + "@actions/http-client": "^1.0.8", + "@actions/io": "^1.0.1", + "semver": "^6.1.0", + "uuid": "^3.3.3" + }, + "dependencies": { + "@actions/core": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz", + "integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg==" + }, + "@actions/exec": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.4.tgz", + "integrity": "sha512-4DPChWow9yc9W3WqEbUj8Nr86xkpyE29ZzWjXucHItclLbEW6jr80Zx4nqv18QL6KK65+cifiQZXvnqgTV6oHw==", + "requires": { + "@actions/io": "^1.0.1" + } + }, + "@actions/io": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz", + "integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg==" + }, + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" + } + } + }, "@actions/core": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.0.0.tgz", @@ -14,6 +53,37 @@ "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.0.tgz", "integrity": "sha512-nquH0+XKng+Ll7rZfCojN7NWSbnGh+ltwUJhzfbLkmOJgxocGX2/yXcZLMyT9fa7+tByEow/NSTrBExNlEj9fw==" }, + "@actions/glob": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.1.0.tgz", + "integrity": "sha512-lx8SzyQ2FE9+UUvjqY1f28QbTJv+w8qP7kHHbfQRhphrlcx0Mdmm1tZdGJzfxv1jxREa/sLW4Oy8CbGQKCJySA==", + "requires": { + "@actions/core": "^1.2.0", + "minimatch": "^3.0.4" + }, + "dependencies": { + "@actions/core": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz", + "integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg==" + } + } + }, + "@actions/http-client": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz", + "integrity": "sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==", + "requires": { + "tunnel": "0.0.6" + }, + "dependencies": { + "tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" + } + } + }, "@actions/io": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.0.tgz", @@ -1738,8 +1808,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base": { "version": "0.11.2", @@ -1825,7 +1894,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2071,8 +2139,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "convert-source-map": { "version": "1.7.0", @@ -5315,6 +5382,11 @@ "object-visit": "^1.0.0" } }, + "md5-file": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/md5-file/-/md5-file-5.0.0.tgz", + "integrity": "sha512-xbEFXCYVWrSx/gEKS1VPlg84h/4L20znVIulKw6kMfmBUAZNAnF00eczz9ICMl+/hjQGo5KSXRxbL/47X3rmMw==" + }, "merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -5361,7 +5433,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } diff --git a/package.json b/package.json index 79c4ece..3856d18 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,13 @@ "author": "Sascha Mann ", "license": "MIT", "dependencies": { + "@actions/cache": "^0.2.1", "@actions/core": "^1.0.0", "@actions/exec": "^1.0.0", + "@actions/glob": "^0.1.0", "@actions/io": "^1.0.0", "@actions/tool-cache": "^1.0.0", + "md5-file": "^5.0.0", "semver": "^6.3.0" }, "devDependencies": { diff --git a/src/caching.ts b/src/caching.ts new file mode 100644 index 0000000..4b9d74d --- /dev/null +++ b/src/caching.ts @@ -0,0 +1,25 @@ +import * as cache from '@actions/cache' +import * as glob from '@actions/glob' + +import * as path from 'path' + +// TODO: Change to hashFiles once https://github.com/actions/toolkit/issues/472 has been resolved +import * as md5File from 'md5-file' + +const JULIA_HOME = path.join(`${process.env.HOME}`, '.julia') + +/** + * Cache the ~/.julia/artifacts directory. + */ +export async function cacheArtifacts(): Promise { + const projectFiles = await (await glob.create('**/Project.toml')).glob() + let projectsHash = '' + projectFiles.forEach((f) => { + projectsHash.concat('-', md5File.sync(f)) + }) + + const paths = [path.join(JULIA_HOME, 'artifacts')] + const key = `artifacts-${process.env.RUNNER_OS}-${projectsHash}` + + return cache.saveCache(paths, key) +} diff --git a/src/setup-julia.ts b/src/setup-julia.ts index 4dd38e9..ecdca09 100644 --- a/src/setup-julia.ts +++ b/src/setup-julia.ts @@ -5,6 +5,7 @@ import * as tc from '@actions/tool-cache' import * as path from 'path' import * as installer from './installer' +import * as jlcache from './caching' async function run() { try { @@ -39,6 +40,13 @@ async function run() { if (core.getInput('show-versioninfo') == 'true') { exec.exec('julia', ['-e', 'using InteractiveUtils; versioninfo()']) } + + // Create caches + if (core.getInput('cache-artifacts') == 'true') { + core.debug('caching artifacts directory...') + const cacheId = await jlcache.cacheArtifacts() + core.setOutput('artifacts-cache-id', cacheId.toString()) + } } catch (error) { core.setFailed(error.message) }