Skip to content

Commit c98bc3a

Browse files
authored
Support ignoring job and matrix jobs as part of cache key (#512)
1 parent c5dea70 commit c98bc3a

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ See `extraFiles` for more details.
100100

101101
The content of `extraHashedContent` is taken into account in the hash for the coursier cache key.
102102

103+
### `ignoreJob`
104+
105+
*Optional*
106+
107+
Default: `false`
108+
109+
Set `true` if you don't want to use a job id as part of cache key.
110+
111+
### `ignoreMatrix`
112+
113+
*Optional*
114+
115+
Default: `false`
116+
117+
Set `true` if you don't want to use a matrix jobs as part of cache key.
118+
103119
## Outputs
104120

105121
* `cache-hit-coursier` - A boolean value to indicate a match was found for the coursier cache

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ inputs:
109109
description: >
110110
Extra content to take into account in the Ammonite cache key. Same format as extraHashedContent.
111111
default: ''
112+
ignoreJob:
113+
required: false
114+
description: >
115+
Set 'true' if you don't want to use a job id as part of cache key.
116+
default: 'false'
117+
ignoreMatrix:
118+
required: false
119+
description: >
120+
Set 'true' if you don't want to use a matrix jobs as part of cache key.
121+
default: 'false'
112122
outputs:
113123
cache-hit-coursier:
114124
description: 'A boolean value to indicate a match was found for the coursier cache'

src/restore.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ function readExtraKeys(variableName: string): string {
300300
return extraFilesStr
301301
}
302302

303+
function readExtraBoolean(variableName: string): boolean {
304+
return core.getBooleanInput(variableName, {required: false})
305+
}
306+
303307
async function run(): Promise<void> {
304308
let root = core.getInput('root')
305309
if (!root.endsWith('/')) {
@@ -345,9 +349,17 @@ async function run(): Promise<void> {
345349
const extraMillKey = readExtraKeys('extraMillKey')
346350
const extraAmmoniteKey = readExtraKeys('extraAmmoniteKey')
347351

348-
const job = readExtraKeys('job')
352+
const ignoreJobAsPartCacheKey = readExtraBoolean('ignoreJob')
353+
const ignoreMatrixAsPartCacheKey = readExtraBoolean('ignoreMatrix')
354+
355+
const job = ignoreJobAsPartCacheKey ? '' : readExtraKeys('job')
349356
let matrix = readExtraKeys('matrix')
350-
if (matrix === 'null' || matrix === 'undefined' || matrix === '{}') {
357+
if (
358+
matrix === 'null' ||
359+
matrix === 'undefined' ||
360+
matrix === '{}' ||
361+
ignoreMatrixAsPartCacheKey
362+
) {
351363
matrix = ''
352364
}
353365

0 commit comments

Comments
 (0)