actions / actions/cache

Consider supporting caches relative to home dir

Open
#1,400 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5.6k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

Thanks!

First, thanks for all the hard work and for a very useful action!

Intro

My tests run on macOS, Ubuntu, and Windows GitHub runners, so I was excited to explore the enableCrossOsArchive feature.

I'm finding it great except for one thing.

The natural location of my project's downloaded dependencies is relative to the home dir and includes, for example, an .m2 repository.

Cross-OS caching files relative to the home dir turns out to be awkward.

Details

As far as I understand it, the current cache action always saves and restores relative to the workspace dir.

I did some poking around on a GitHub Ubuntu runner.
My workspace dir is /home/runner/work/my-repo-name/my-repo-name,
and my home dir is /home/runner.
So if I am creating my cache with a path of ~/.m2 on Ubuntu, files will get archived as, for an example, ../../../.m2/repository/com/jcraft/jsch.agentproxy.usocket-jna/0.0.9/jsch.agentproxy.usocket-jna-0.0.9.pom.

This is all fine and dandy on Ubuntu and macOS because they share the same basic directory structure. But on Windows, the directory layout is different.

I did some poking around on a GitHub Windows runner.
My workspace dir is D:\a\my-repo-name\my-repo-name,
and my home dir is C:\Users\runneradmin.

So if I restore a Ubuntu runner created cache on a Windows runner, my cache will be restored to ../../.. which is D:\, but I really want to restore to my Windows home dir.

My Current Hack

I can run a step after restoring the cache to fix things up, but this is brittle and awkward:

    - name: Cache fixup for Windows
      if: ${{ matrix.os == 'windows' }}
      run: |
        mv ../../../.m2 ${USERPROFILE}
      shell: bash

Other Alternatives

I could figure out how to have my project dependencies downloaded to my workspace dir.
But this is also awkward, unnatural, and prone to human error.

Your Current Docs...

Do warn:

Avoid using directory pointers such as ${{ github.workspace }} or ~ (home) which eventually evaluate to an absolute path that does not match across OSs.

But I think it would be great to be able to cross-OS cache relative to ~.

What I'd Really Like

Is a way to save and restore a cache relative to the home dir.

One way to do this might be to introduce a new base-path input which would act as an optional override for the hard-coded workspace dir.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the cross-OS cache handling and the referenced packages/cache/src/internal/tar.ts location in the GitHub Actions toolkit. Reproduce caching ~/.m2 across Ubuntu, macOS, and Windows, then define the behavior for an optional home-relative base path. Done means the behavior is tested and the new input is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, typescript
Domain
ci-cd
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.