fix: add install_args hash to cache key (#136)

* fix: add install_args hash to cache key

* fix: sort tools before hashing
This commit is contained in:
Risu 2024-10-26 20:25:44 +09:00 committed by GitHub
parent 4d056cf31b
commit f2a7466821
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

13
dist/index.js generated vendored
View file

@ -62425,6 +62425,7 @@ const io = __importStar(__nccwpck_require__(4994));
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const exec = __importStar(__nccwpck_require__(5236)); const exec = __importStar(__nccwpck_require__(5236));
const glob = __importStar(__nccwpck_require__(7206)); const glob = __importStar(__nccwpck_require__(7206));
const crypto = __importStar(__nccwpck_require__(6982));
const fs = __importStar(__nccwpck_require__(9896)); const fs = __importStar(__nccwpck_require__(9896));
const os = __importStar(__nccwpck_require__(857)); const os = __importStar(__nccwpck_require__(857));
const path = __importStar(__nccwpck_require__(6928)); const path = __importStar(__nccwpck_require__(6928));
@ -62476,6 +62477,7 @@ async function setEnvVars() {
async function restoreMiseCache() { async function restoreMiseCache() {
core.startGroup('Restoring mise cache'); core.startGroup('Restoring mise cache');
const version = core.getInput('version'); const version = core.getInput('version');
const installArgs = core.getInput('install_args');
const cachePath = (0, utils_1.miseDir)(); const cachePath = (0, utils_1.miseDir)();
const fileHash = await glob.hashFiles([ const fileHash = await glob.hashFiles([
`**/.config/mise/config.toml`, `**/.config/mise/config.toml`,
@ -62497,6 +62499,17 @@ async function restoreMiseCache() {
if (version) { if (version) {
primaryKey = `${primaryKey}-${version}`; primaryKey = `${primaryKey}-${version}`;
} }
if (installArgs) {
const tools = installArgs
.split(' ')
.filter(arg => !arg.startsWith('-'))
.sort()
.join(' ');
if (tools) {
const toolsHash = crypto.createHash('sha256').update(tools).digest('hex');
primaryKey = `${primaryKey}-${toolsHash}`;
}
}
core.saveState('CACHE', core.getBooleanInput('cache_save')); core.saveState('CACHE', core.getBooleanInput('cache_save'));
core.saveState('PRIMARY_KEY', primaryKey); core.saveState('PRIMARY_KEY', primaryKey);
core.saveState('MISE_DIR', cachePath); core.saveState('MISE_DIR', cachePath);

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -3,6 +3,7 @@ import * as io from '@actions/io'
import * as core from '@actions/core' import * as core from '@actions/core'
import * as exec from '@actions/exec' import * as exec from '@actions/exec'
import * as glob from '@actions/glob' import * as glob from '@actions/glob'
import * as crypto from 'crypto'
import * as fs from 'fs' import * as fs from 'fs'
import * as os from 'os' import * as os from 'os'
import * as path from 'path' import * as path from 'path'
@ -56,6 +57,7 @@ async function setEnvVars(): Promise<void> {
async function restoreMiseCache(): Promise<void> { async function restoreMiseCache(): Promise<void> {
core.startGroup('Restoring mise cache') core.startGroup('Restoring mise cache')
const version = core.getInput('version') const version = core.getInput('version')
const installArgs = core.getInput('install_args')
const cachePath = miseDir() const cachePath = miseDir()
const fileHash = await glob.hashFiles( const fileHash = await glob.hashFiles(
[ [
@ -79,6 +81,17 @@ async function restoreMiseCache(): Promise<void> {
if (version) { if (version) {
primaryKey = `${primaryKey}-${version}` primaryKey = `${primaryKey}-${version}`
} }
if (installArgs) {
const tools = installArgs
.split(' ')
.filter(arg => !arg.startsWith('-'))
.sort()
.join(' ')
if (tools) {
const toolsHash = crypto.createHash('sha256').update(tools).digest('hex')
primaryKey = `${primaryKey}-${toolsHash}`
}
}
core.saveState('CACHE', core.getBooleanInput('cache_save')) core.saveState('CACHE', core.getBooleanInput('cache_save'))
core.saveState('PRIMARY_KEY', primaryKey) core.saveState('PRIMARY_KEY', primaryKey)