-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to update Docker cache key based on the number of times th… (
#64) * Add option to update Docker cache key based on the number of times the docker should be pulled from the docker registry * Update description of update_times_a_day input in action.yml * Exit quickly when UPDATE_TIMES_A_DAY not provided * add not in check of UPDATE_TIMES_A_DAY
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = core => { | ||
const { RUNNER_OS, UPDATE_TIMES_A_DAY } = process.env; | ||
|
||
if (!UPDATE_TIMES_A_DAY) { | ||
return; | ||
} | ||
|
||
// calculate the docker-key cache value | ||
const times = Number(UPDATE_TIMES_A_DAY); | ||
|
||
if (!Number.isInteger(times) || times <= 0 || times >= 25) { | ||
core.error(`"update_times_a_day" should be a whole number in range [1..24]`); | ||
process.exit(2); | ||
} | ||
|
||
const date = new Date(); | ||
const uniqNum = Math.ceil(((date.getHours() + 1) / 24) * times); | ||
const uniqValue = `${date.toLocaleDateString('en-US').replaceAll('/', '-')}-${uniqNum}`; | ||
const dockerKey = `${RUNNER_OS}-gitstream-docker-${uniqValue}`; | ||
core.exportVariable('DOCKER_KEY', dockerKey); | ||
}; |