-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add possibility to specify images to cache #575
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,12 @@ inputs: | |
are not supported, because partial cache restoration leads to a "snowball" | ||
effect. | ||
required: true | ||
included-images: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the proposed name. Just gotta document it in the README too. |
||
description: > | ||
If "all", all images will be included. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change the default to |
||
Otherwise, specify precisely all needed images to be included separated with spaces. | ||
required: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may be missing something, but I think this should be |
||
default: "all" | ||
read-only: | ||
description: If "true", disables saving the cache upon cache miss | ||
required: false | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ const loadDockerImages = async (): Promise<void> => { | |
|
||
const saveDockerImages = async (): Promise<void> => { | ||
const key = getInput("key", { required: true }); | ||
const includedImages = getInput("included-images", { required: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the rationale for specifying this argument as required. |
||
const includedImagesList = includedImages.split(" "); | ||
if (getState(CACHE_HIT) === "true") { | ||
info(`Cache hit occurred on the primary key ${key}, not saving cache.`); | ||
} else if (getInput("read-only") === "true") { | ||
|
@@ -42,7 +44,9 @@ const saveDockerImages = async (): Promise<void> => { | |
const images = await execBashCommand(LIST_COMMAND); | ||
const imagesList = images.split("\n"); | ||
const newImages = imagesList.filter( | ||
(image: string): boolean => !preexistingImages.includes(image) | ||
(image: string): boolean => | ||
!preexistingImages.includes(image) && | ||
includedImagesList.includes(image) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To pass CI/CR, you will need test coverage for the (currently unhandled) case where the default value is passed as well as the case where it is overridden by the user. I think users will find it counter-intuitive if pre-existing images are still filtered out when they specified explicitly what to cache. |
||
); | ||
if (newImages.length === 0) { | ||
info("No Docker images to save"); | ||
|
@@ -52,6 +56,8 @@ const saveDockerImages = async (): Promise<void> => { | |
"will be saved." | ||
); | ||
const newImagesArgs = newImages.join(" "); | ||
info("newImagesArgs"); | ||
info(newImagesArgs); | ||
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this left over from debugging? |
||
const cmd = `docker save --output ${DOCKER_IMAGES_PATH} ${newImagesArgs}`; | ||
await execBashCommand(cmd); | ||
await saveCache([DOCKER_IMAGES_PATH], key); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit (commit message): the scope should be "action" rather than "ci" since "ci" within this repository would refer to the CI pipeline for this action itself. (In fairness, this action is run as part of its own CI... he he.)