-
Notifications
You must be signed in to change notification settings - Fork 53
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
Implement copy and copy-immutable strategies #20
Conversation
6aa5293
to
64bc070
Compare
src/post.ts
Outdated
|
||
switch (options.strategy) { | ||
case Strategy.CopyImmutable: | ||
if (await exists(cachePath)) { | ||
log.info(`Cache already exists, skipping`) | ||
return | ||
} | ||
await cp(targetPath, cachePath, { copySourceDirectory: true, recursive: true }) | ||
break | ||
case Strategy.Copy: | ||
await rmRF(cachePath) | ||
await cp(targetPath, cachePath, { copySourceDirectory: true, recursive: true }) | ||
break | ||
case Strategy.Move: | ||
await mv(targetPath, cachePath, { force: true }) | ||
break | ||
} | ||
|
||
log.info(`Cache saved to ${cachePath} with ${options.strategy} strategy`) |
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.
Nice touch adding some feedback about what's happening. We should make it consistent, tho.
In the last log it is saying CACHE SAVED even if it just said CACHE EXISTS SO WE SKIPPING.
I would suggest to add a log line inside each case. For the copy-immutable
one you would log either SKIPPED or SAVED based on the condition you have there already.
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.
@stefanmaric on line 18, it returns immediately, so it should not print the CACHE SAVED line.
I can add a log line to each one however it will be a bit redundant (3x same log)?
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.
Thank you @oNaiPs ! Need this change so much, makes a lot of sense for my use case. I hope @stefanmaric will have some time to approve this :)
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.
Yesterday I got error EXDEV: cross-device link not permitted
when adding action-local-cache
to my project. Many thank you to @oNaiPs, you fixes saved my life! 👍
Thanks for following up @oNaiPs! ❤️
Once the PR has been approved, Github will allow me to run the CI based on your branch. |
278a3ca
to
eb347d7
Compare
@stefanmaric please check the outstanding comment, the others have been addressed |
eb347d7
to
7e660ee
Compare
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.
Looking pretty good! Thanks for your contribution @oNaiPs ❤️
@oNaiPs tests are failing for all strategies at the cache check steps. Test cases look good to me. Logs for the action look good as well. Implementation looks good as well. So I'm clueless at this point. We would have to debug more but I'm busy at the moment. Would you be able to setup a worker of your own to debug? |
@oNaiPs actually, I think the test conditions are wrong. test $(cat ./demo-output.txt) != "demo-results" && echo "Wrong cached contents $(cat ./demo-output.txt)" && exit 1 That will always return exit code 1, regardless if the two other commands execute or not. test 'a' != 'b' && echo BAD && exit 1
# prints BAD
echo $? # prints 1
test 'a' != 'a' && echo BAD && exit 1
echo $? # prints 1 To fix this, I would make the inverse. In POSIX/Bash/etc logical operators don't behave in the same way as they do in C-like languages, so this won't work: test 'a' = 'a' || echo BAD && exit 1
# exit with code 1 Wrapping in parentheses (a sub-shell) is necessary: test $(cat ./demo-output.txt) = "demo-results" || (echo "Wrong cached contents $(cat ./demo-output.txt)" && exit 1) I'm not entirely sure this will work within Github Actions because even tho the code of the command is being set to |
@stefanmaric let me look into it and come back to you |
7e660ee
to
d3348ec
Compare
@stefanmaric should be fixed now (force-pushed to same commit)!
I setup a self-hosted runner and tests are now passing. |
All green now @oNaiPs! Merging now. Will be releasing a new version shortly. Thanks again for your contribution. |
Any updates on the release of this feature? I tried using it in v2 before noticing the |
I wanted to release it as a minor but we needed to validate there were no breaking changes before that. We were busy so we couldn't run our internal tests before. It is all set now: https://github.com/MasterworksIO/action-local-cache/releases/tag/2.1.0 Thanks again @oNaiPs for your contributions! |
Follow-up to #19.
Adds a new
strategy
key that allows user to specify how cache is copied/moved.Default strategy is called
move
, which was already implemented.Copy strategy does a recursive copy to/from the cache directory on job end/start.
Copy-immutable strategy works the same way, but does not refresh cache if it already exists.
Fixes #15
TODO @stefanmaric any way we can run the actions before merging?