Skip to content

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

Merged
merged 4 commits into from
May 22, 2025

Conversation

ocaisa
Copy link
Contributor

@ocaisa ocaisa commented May 22, 2025

Fixes #39

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

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
@ocaisa
Copy link
Contributor Author

ocaisa commented May 22, 2025

Note cache key is now something like cvmfs-apt-cache-Ubuntu-24.04-x86_64

@ocaisa
Copy link
Contributor Author

ocaisa commented May 22, 2025

Closing and re-opening to verify cache is being picked up

@ocaisa ocaisa closed this May 22, 2025
@ocaisa ocaisa reopened this May 22, 2025
@ocaisa
Copy link
Contributor Author

ocaisa commented May 22, 2025

Seems to be working, I see Cache hit for: cvmfs-apt-cache-Ubuntu-22.04-x86_64 in the latest workflows

Copy link
Collaborator

@vvolkl vvolkl left a 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 }}
Copy link
Contributor Author

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 ./

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sort of works:

https://github.com/EESSI/github-action-eessi/actions/runs/15181630719/job/42692167272?pr=32#step:3:57

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Collaborator

@wdconinc wdconinc left a 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.

Copy link
Collaborator

@vvolkl vvolkl left a 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!

@vvolkl vvolkl merged commit f93ba85 into cvmfs-contrib:main May 22, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not getting GitHub Action cache hits
3 participants