Skip to content

Commit

Permalink
fix: add install_args hash to cache key (#136)
Browse files Browse the repository at this point in the history
* fix: add install_args hash to cache key

* fix: sort tools before hashing
  • Loading branch information
risu729 authored Oct 26, 2024
1 parent 4d056cf commit f2a7466
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
13 changes: 13 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as io from '@actions/io'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as glob from '@actions/glob'
import * as crypto from 'crypto'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
Expand Down Expand Up @@ -56,6 +57,7 @@ async function setEnvVars(): Promise<void> {
async function restoreMiseCache(): Promise<void> {
core.startGroup('Restoring mise cache')
const version = core.getInput('version')
const installArgs = core.getInput('install_args')
const cachePath = miseDir()
const fileHash = await glob.hashFiles(
[
Expand All @@ -79,6 +81,17 @@ async function restoreMiseCache(): Promise<void> {
if (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('PRIMARY_KEY', primaryKey)
Expand Down

0 comments on commit f2a7466

Please sign in to comment.