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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,21 @@ runs:
echo "release=${DISTRIB_RELEASE}" >> $GITHUB_OUTPUT
echo "codename=${DISTRIB_CODENAME}" >> $GITHUB_OUTPUT
echo "description=${DISTRIB_DESCRIPTION}" >> $GITHUB_OUTPUT
echo "id-release=${DISTRIB_ID}-${DISTRIB_DESCRIPTION}" >> $GITHUB_OUTPUT
echo "id-release=${DISTRIB_ID}-${DISTRIB_RELEASE}" >> $GITHUB_OUTPUT
echo "arch=$(uname -m)" >> $GITHUB_OUTPUT
elif [ "$RUNNER_OS" == "macOS" ]; then
echo "id-release=macOS-$(sw_vers -productVersion)" >> $GITHUB_OUTPUT
echo "arch=$(uname -m)" >> $GITHUB_OUTPUT
fi
# Create an envvar that stores information about the action version used
ACTION_VERSION=$(basename "$GITHUB_ACTION_PATH")
ACTION_NAME=$(basename $(dirname "$GITHUB_ACTION_PATH"))
ACTION_OWNER=$(basename $(dirname $(dirname "$GITHUB_ACTION_PATH")))
echo "cvmfs_action_version=${ACTION_OWNER}_${ACTION_NAME}_${ACTION_VERSION}" >> $GITHUB_OUTPUT
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

path: |
${{ inputs.apt_cache }}
- run: |
Expand Down