Skip to content

Commit

Permalink
fix: consider lock.json in cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Feb 13, 2024
1 parent 32fe7ad commit 9446144
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -81991,6 +82004,14 @@ module.exports = require("fs");

/***/ }),

/***/ 3292:
/***/ ((module) => {

"use strict";
module.exports = require("fs/promises");

/***/ }),

/***/ 3685:
/***/ ((module) => {

Expand Down
15 changes: 15 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -81,13 +82,27 @@ export async function main(): Promise<void> {
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) {}

Check failure on line 95 in index.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Empty block statement

const hasher = crypto.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',
Expand Down

0 comments on commit 9446144

Please sign in to comment.