Skip to content

Commit

Permalink
Support ignoring job and matrix jobs as part of cache key (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihostage authored Nov 9, 2023
1 parent c5dea70 commit c98bc3a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ See `extraFiles` for more details.

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

### `ignoreJob`

*Optional*

Default: `false`

Set `true` if you don't want to use a job id as part of cache key.

### `ignoreMatrix`

*Optional*

Default: `false`

Set `true` if you don't want to use a matrix jobs as part of cache key.

## Outputs

* `cache-hit-coursier` - A boolean value to indicate a match was found for the coursier cache
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ inputs:
description: >
Extra content to take into account in the Ammonite cache key. Same format as extraHashedContent.
default: ''
ignoreJob:
required: false
description: >
Set 'true' if you don't want to use a job id as part of cache key.
default: 'false'
ignoreMatrix:
required: false
description: >
Set 'true' if you don't want to use a matrix jobs as part of cache key.
default: 'false'
outputs:
cache-hit-coursier:
description: 'A boolean value to indicate a match was found for the coursier cache'
Expand Down
16 changes: 14 additions & 2 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ function readExtraKeys(variableName: string): string {
return extraFilesStr
}

function readExtraBoolean(variableName: string): boolean {
return core.getBooleanInput(variableName, {required: false})
}

async function run(): Promise<void> {
let root = core.getInput('root')
if (!root.endsWith('/')) {
Expand Down Expand Up @@ -345,9 +349,17 @@ async function run(): Promise<void> {
const extraMillKey = readExtraKeys('extraMillKey')
const extraAmmoniteKey = readExtraKeys('extraAmmoniteKey')

const job = readExtraKeys('job')
const ignoreJobAsPartCacheKey = readExtraBoolean('ignoreJob')
const ignoreMatrixAsPartCacheKey = readExtraBoolean('ignoreMatrix')

const job = ignoreJobAsPartCacheKey ? '' : readExtraKeys('job')
let matrix = readExtraKeys('matrix')
if (matrix === 'null' || matrix === 'undefined' || matrix === '{}') {
if (
matrix === 'null' ||
matrix === 'undefined' ||
matrix === '{}' ||
ignoreMatrixAsPartCacheKey
) {
matrix = ''
}

Expand Down

0 comments on commit c98bc3a

Please sign in to comment.