Skip to content

Allow customising project ID in cache key rather than it always including working directory - #905

Open
ZimbiX wants to merge 1 commit into
ruby:masterfrom
ZimbiX:remove-pwd-from-bundler-cache-key
Open

Allow customising project ID in cache key rather than it always including working directory#905
ZimbiX wants to merge 1 commit into
ruby:masterfrom
ZimbiX:remove-pwd-from-bundler-cache-key

Conversation

@ZimbiX

@ZimbiX ZimbiX commented Apr 21, 2026

Copy link
Copy Markdown

Resolves #904

I decided to go with something simple rather than using the Git repo remote URL which I'd first thought to use. The URL might not suit all use-cases - perhaps someone has multiple bundles in the one repo (hence you having added the workdir to distinguish). Instead, a simple customisable string value project-id would allow using the action multiple times in a job for different directories with a different project-id.

Testing

Tested and working in our GitHub Actions workflow using:

      # Fork of ruby/setup-ruby to support ephemeral workdir
      - uses: ZimbiX/setup-ruby@remove-pwd-from-bundler-cache-key
        with:
          ruby-version: 3.3.6
          bundler-cache: true
          project-id: better_caring

Logs:

Cache key: setup-ruby-bundler-cache-v6-ubuntu-22.04-x64-ruby-3.3.6-better_caring-with--without--only--Gemfile.lock-3f96ad38961e7a44e242400b976a8833512d7d013bd35c5f24b09672d2fd2667
Cache hit for: setup-ruby-bundler-cache-v6-ubuntu-22.04-x64-ruby-3.3.6-better_caring-with--without--only--Gemfile.lock-3f96ad38961e7a44e242400b976a8833512d7d013bd35c5f24b09672d2fd2667
Received 0 of 140644053 (0.0%), 0.0 MBs/sec
Received 0 of 140644053 (0.0%), 0.0 MBs/sec
Received 8388608 of 140644053 (6.0%), 2.7 MBs/sec
Received 46137344 of 140644053 (32.8%), 11.0 MBs/sec
Received 100663296 of 140644053 (71.6%), 19.2 MBs/sec
Received 136449749 of 140644053 (97.0%), 21.7 MBs/sec
Received 140644053 of 140644053 (100.0%), 20.8 MBs/sec
Cache Size: ~134 MB (140644053 B)
/usr/bin/tar -xf /codebuild/output/src2839699089/src/actions-runner/_work/_temp/e8390f69-4590-46ba-aa6f-789b62f5e608/cache.tzst -P -C /codebuild/output/src2839699089/src/actions-runner/_work/better_caring/better_caring --use-compress-program unzstd
Cache restored successfully
Found cache for key: setup-ruby-bundler-cache-v6-ubuntu-22.04-x64-ruby-3.3.6-better_caring-with--without--only--Gemfile.lock-3f96ad38961e7a44e242400b976a8833512d7d013bd35c5f24b09672d2fd2667
…ding working directory

To fix cache key consistency for builds with an ephemeral working directory
Comment thread bundler.js
async function computeBaseKey(engine, version, lockFile, cacheVersion) {
const cwd = process.cwd()
async function computeBaseKey(engine, version, lockFile, cacheVersion, specifiedProjectId) {
const projectId = specifiedProjectId || `wd-${process.cwd()}`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would ignore the user-supplied working-directory input: https://github.com/ruby/setup-ruby/blob/master/action.yml

More generally I think we don't need a project ID here, I'll take a look at #907 next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants