Conversation
ZimbiX
left a comment
There was a problem hiding this comment.
That would work too! I like that this is automatic, but yeah, it might be surprising to invalidate the cache. Is GITHUB_WORKSPACE set for all builds or just on AWS CodeBuild?
|
|
26be17b to
d83d8b8
Compare
Should you have to opt-in to this new cache key behavior? I think the report in #904 is the first one about this, in all the years the setup-ruby action have been around. No strong opinion from my side, I don't know how conservative we need to be with cache key behavior changes. |
From While it would invalidate all existing caches once, it’s not really a breaking change as it requires no action from the users. |
|
I think this has been discussed in the past, but I can't find it quickly right now. The main risk here is the cache would not work and break, which is worse than having no cache, because installing gems is likely to embed absolute paths. |
|
I asked ChatGPT to find some gems which could have that issue:
However there is something that looks problematic for all extensions built from source: That library runpath hardcodes the Ruby prefix and the $HOME, if that changes it would likely fail. So on one hand it seems several such issues have been solved, but also there are a number of them and since for most users they would never notice it there might still be plenty of such issues in practice. If we merged this, don't we risk getting reports about some extensions failing with the cache? I think we would, and in fact users wouldn't be able to reproduce locally, because no one changes their working dir between every run locally. One of my motto for setup-ruby is: be as close as possible as a local development workflow, so it's easy to reproduce issues locally and minimize behavior changes in setup-ruby. Having a changing CWD is a big violation of that, so if there any way to solve this in AWS CodeBuild I think that is the better fix by far: #904 (comment) |
Ruby prefix is determined by setup-ruby action, unless we are talking about the system provided ruby. Even for system provided ruby, I don’t see a reason that will change as long as Ruby version isn’t changing , because that is usually provided by either an OS image or a container image. If we are worried about location of ruby to change, we should have full path to RUBY_PREFIX as part of the cache key. Location of system libraries changing due to environment being different can be a concern, but I think that is out of the scope of this project, because that’s out of our control. We can only hope that the runner image is as stable as possible. In general, native gems may link with I think the only case thing would break is that if gem number one ships a “libone.so” and then gem number two compiles a “libtwo.so” that links to “libone.so”, but this can already be broken just by updating gem number one without recompiling gem number two so that’s just a bad design where gem number two is not self-contained, which can cause issue regardless of this PR or not. For any gem that is self-contained or only depends on the libruby and system libraries, there shouldn’t be any issue even if the cache restore directory changes.
For GitHub hosted runner or any runners that has a fixed location for $GITHUB_WORKSPACE, nothing would break as the logically meaning of CWD isn’t changing at all. This PR would only affect self-hosted runners with third party runtimes with dynamic $GITHUB_WORKSPACE. If we really don’t want to change this, I think the best workaround for CodeBuild users would be that they can just create their own hardcoded working directory at the beginning of the workflow, and use the working directory option of setup ruby with a hardcoded value. The downside is that the user experience would be very poor, that all the subsequent steps would require a hardcoded working directory, too. |
|
Also this change would affect other self-hosted runners which have varying CWD.
The case I was thinking about is some gem compiles a shared library say libfoo.so (if it's a static library like And it gets worse, because if the directories in |
|
@ZimbiX Could you test this PR ( I think it's too risky to have this by default, but I suppose it could be an option, and then we can document in |
|
As for nokogiri case mentioned above, using |
|
Yes, if that's done and the variant on macOS too it's probably fine but as we see it's not always done for such cases. I could also imagine something like I guess we could also be optimistic and just do this behavior by default, and if it proves problematic then introduce the option and have it false by default. But that might be considered breaking and anyway I want these two things before making my decision or spending more time discussing: |
|
@eregon I'm happy to report that this PR does work on our monolith (195 gems) with no errors upon cache restoration |
This is an alternative solution to the issue described in #904 and #905.
The problem statement is that when use aws codebuild as self-hosted runner, the
$GITHUB_WORKSPACEwould change on every single build, and currently the cache key containsprocess.cwd(), thus it will always invalidate the cache.The solution in this PR is to use a relative cwd computed from
$GITHUB_WORKSPACEinstead of the absolute cwd, so that it works consistently on github runner and other runners.Note: This change will invalidate all caches on all repositories once when updating to this version due to updating the cache key, but after that cache should work again.