-
Notifications
You must be signed in to change notification settings - Fork 12
Make cache key reproducible for other repositories #40
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
Conversation
Existing cache key includes spaces due to use of `description` from `lsb-release` and relies on hashing a file (`action.yml`) that is unlikely to exist for repositories using the action
Note cache key is now something like |
Closing and re-opening to verify cache is being picked up |
Seems to be working, I see |
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.
Thanks Alan, great, if that works, I'm happy to merge.
To me it seems that this is actually a bug in the github actions cache, right? It should just evaluate the string, and if there's an empty env var appended that shouldn't matter.
I do think that we want to add the version of the action to the cache key though, even if hardcoded. Otherwise I think that there may be cache inconsistencies on update.
shell: bash | ||
- uses: actions/cache@v4 | ||
with: | ||
key: cvmfs-apt-cache-${{ steps.lsb-release.outputs.id-release }}-${{ steps.lsb-release.outputs.arch }}-${{ hashFiles('action.yml') }} | ||
key: cvmfs-apt-cache-${{ steps.lsb-release.outputs.id-release }}-${{ steps.lsb-release.outputs.arch }}-${{ steps.lsb-release.outputs.cvmfs_action_version }} |
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.
@vvolkl I think this will work but it is tricky to test properly, the cache in this case is called
cvmfs-apt-cache-Ubuntu-22.04-x86_64-.
because the actions is ./
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.
I'll see if I can trigger it in my own project CI
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.
It sort of works:
where I use the latest commit here
cvmfs-contrib/github-action-cvmfs@c4a951db239043c0d77b7e1a6ae83ce71ef80d97
and see
cvmfs-apt-cache-Ubuntu-24.04-x86_64-c4a951db239043c0d77b7e1a6ae83ce71ef80d97
I don't understand how I only see the commit though
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.
Ok, that is fixed now and I see
cvmfs-apt-cache-Ubuntu-24.04-aarch64-cvmfs-contrib_github-action-cvmfs_987d52a1a6c90e0a3304453c3f606fa45f376bd0
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.
Depending on tagging or using commits then you will get a different value for the cache name
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.
It really seemed to be related to hashing a file (action.yml
) that didn't exist in the repo using the Action, leading to cache misses
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.
Hmm, maybe there is an easier solution, the file should exist under $GITHUB_ACTION_PATH
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.
In that case, there are some reports about the github.action_path handlebar variable (which I assume is the same as the env var) pointing to non-existing files in self-hosted runners. actions/runner#716
Not sure if that's of potential concern. I don't even know if this action works on self-hosted runners right now.
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.
Reading https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#hashfiles , I don't think you can use hashfiles
with $GITHUB_ACTION_PATH/action.yml
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.
In that case, there are some reports about the github.action_path handlebar variable (which I assume is the same as the env var) pointing to non-existing files in self-hosted runners. actions/runner#716
Not sure if that's of potential concern. I don't even know if this action works on self-hosted runners right now.
The workaround there is to use the environment variable instead, and the current approach (accidentally) already does that
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.
Thanks for contributing this improvement. This looks good to me. Leaving up to @vvolkl to review and merge.
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.
LGTM, Thanks for the fix!
Fixes #39
Existing cache key includes spaces due to use of
description
fromlsb-release
and relies on hashing a file (action.yml
) that is unlikely to exist for repositories using the action