From 9446144b5147935d316d3fad6fe3a6f47669e2c0 Mon Sep 17 00:00:00 2001 From: Yohe-Am <56622350+Yohe-Am@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:21:37 +0000 Subject: [PATCH] fix: consider lock.json in cache key --- index.js | 21 +++++++++++++++++++++ index.ts | 15 +++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/index.js b/index.js index d01d3c1..ca5397e 100644 --- a/index.js +++ b/index.js @@ -81698,6 +81698,7 @@ const cache = __importStar(__nccwpck_require__(7799)); const exec = __importStar(__nccwpck_require__(1514)); const path = __importStar(__nccwpck_require__(1017)); const os = __importStar(__nccwpck_require__(2037)); +const fs = __importStar(__nccwpck_require__(3292)); const node_fetch_1 = __importDefault(__nccwpck_require__(467)); const crypto_1 = __importDefault(__nccwpck_require__(6113)); // TODO: auto-manage these versions @@ -81746,11 +81747,23 @@ async function main() { const configPath = (await exec.getExecOutput('ghjk', ['print', 'ghjkfile-path'], { silent: true })).stdout.trim(); + const ghjkDirPath = (await exec.getExecOutput('ghjk', ['print', 'ghjkfile-path'], { + silent: true + })).stdout.trim(); + const lockfilePath = path.resolve(ghjkDirPath, 'lock.json'); + let lockJson = undefined; + try { + lockJson = await fs.readFile(lockfilePath, { encoding: 'utf8' }); + } + catch (_err) { } const hasher = crypto_1.default.createHash('sha1'); hasher.update(ghjkVersion); hasher.update(configPath); // TODO: consider ignoring config to avoid misses just for one dep change hasher.update(configStr); + if (lockJson) { + hasher.update(lockJson); + } const hashedEnvs = [ 'GHJK', 'DENO', @@ -81991,6 +82004,14 @@ module.exports = require("fs"); /***/ }), +/***/ 3292: +/***/ ((module) => { + +"use strict"; +module.exports = require("fs/promises"); + +/***/ }), + /***/ 3685: /***/ ((module) => { diff --git a/index.ts b/index.ts index c1e51b1..2a9f1d5 100644 --- a/index.ts +++ b/index.ts @@ -4,6 +4,7 @@ import * as cache from '@actions/cache' import * as exec from '@actions/exec' import * as path from 'path' import * as os from 'os' +import * as fs from 'fs/promises' import fetch from 'node-fetch' import crypto from 'crypto' @@ -81,6 +82,17 @@ export async function main(): Promise { silent: true }) ).stdout.trim() + const ghjkDirPath = ( + await exec.getExecOutput('ghjk', ['print', 'ghjkfile-path'], { + silent: true + }) + ).stdout.trim() + + const lockfilePath = path.resolve(ghjkDirPath, 'lock.json') + let lockJson = undefined + try { + lockJson = await fs.readFile(lockfilePath, { encoding: 'utf8' }) + } catch (_err) {} const hasher = crypto.createHash('sha1') @@ -88,6 +100,9 @@ export async function main(): Promise { hasher.update(configPath) // TODO: consider ignoring config to avoid misses just for one dep change hasher.update(configStr) + if (lockJson) { + hasher.update(lockJson) + } const hashedEnvs = [ 'GHJK',