actions / cache

Cache dependencies and build outputs in GitHub Actions
MIT License
4.48k stars 1.2k forks source link

Excluded sub directory not working #494

Closed mustaphazorgati closed 1 year ago

mustaphazorgati commented 3 years ago

Hey there! The README.md provides an example where an excluded sub-path is provided. Unfortunately that sub-path still ends up in the cache. Here is a modified example using the local maven repository.

- name: Cache multiple paths
  uses: actions/cache@v2
  with:
    path: |
      ~/.m2
      !~/.m2/pro/taskana
    key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

Reading out on the next (cached) build the files in ~/.m2/pro/taskana are contained in the cache. The following adjustment didn't work either:

- name: Cache multiple paths
  uses: actions/cache@v2
  with:
    path: |
      ~/.m2
      !~/.m2/pro/taskana/**
    key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

Is this a bug or am I having the wrong expectations? Our current workaround is to delete that subfolder in a dedicated step. It works, but is kinda annoying.

mustaphazorgati commented 3 years ago

@dhadka I've seen you answering a lof of issues recently. Sorry for asking you directly, but can you have a look at this?

dhadka commented 3 years ago

@mustaphazorgati Thanks for reporting this (and sorry I didn't see this earlier). I was able to reproduce this issue. I filed a bug over in the actions/toolkit repo that hosts the underlying logic for search patterns.

mustaphazorgati commented 3 years ago

Thank you @dhadka for your quick response! Just an FYI for other readers: The provided reproduction of the issue is found here. @dhadka link shows a workflow where the Post cache test step is not executed ;)

Adnn commented 3 years ago

Any update on this issue? (This is making the cache difficult to use in complex workflows)

bigdaz commented 2 years ago

@dhadka Since it doesn't appear that this issue will be resolved any time soon, I suggest that you update the example in the README. The current example is misleading since it won't work as expected.

Changing ~/cache to ~/cache/* should be a functional example. ~/cache/* matches all subdirectories, and then !~/cache/exclude will exclude that particular subdirectory.

- name: Cache multiple paths
  uses: actions/cache@v2
  with:
    path: |
      ~/cache/*
      !~/cache/exclude
    key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
robinp commented 2 years ago

FYI guys I added some code pointers to the underlying https://github.com/actions/toolkit/issues/713#issuecomment-1030692990 - for me it seems passing an extra option to avoid matching directiories in the globber would solve this.

Phantsure commented 2 years ago

This issue still exists?

aparna-ravindra commented 1 year ago

While the issue still exists, the readme file has changed since then and this example is not part of it anymore. Closing this issue in favour of the issue created in the toolkit repo here to fix the problem.

Jimimaku commented 1 year ago

Hey there! The README.md provides an example where an excluded sub-path is provided. Unfortunately that sub-path still ends up in the cache. Here is a modified example using the local maven repository.

- name: Cache multiple paths
  uses: actions/cache@v2
  with:
    path: |
      ~/.m2
      !~/.m2/pro/taskana
    key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

Reading out on the next (cached) build the files in ~/.m2/pro/taskana are contained in the cache. The following adjustment didn't work either:

- name: Cache multiple paths
  uses: actions/cache@v2
  with:
    path: |
      ~/.m2
      !~/.m2/pro/taskana/**
    key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

Is this a bug or am I having the wrong expectations? Our current workaround is to delete that subfolder in a dedicated step. It works, but is kinda annoying.