actions / cache

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

Optionally suppress the warning about non-existing directory to be cached #1241

Open doublep opened 1 year ago

doublep commented 1 year ago

Situation: actions/cache is reused by a higher-level action that caches certain directory using it. This directory may or may not exist by the end of a workflow, and it not existing is not an error.

However, actions/cache then prints the following in the output:

Warning: Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.

While not a major concern, it still would be nice to avoid warnings in normal situations. As far as I see from the source code, there is no way to suppress this message. Can you add one so that outer action (or workflow) can decide between "such situation shouldn't happen, issue a warning" (as now) and "such situation is normal and completely possible, simply ignore it"?

antazoey commented 8 months ago

We am hitting this in our custom action and it is causing confusion for our users.

My suggestion for Cache action authors is to:

  1. Make a allow_missing_archive , like the author says, to suppress the warning

workaround: create empty directories for the cache paths if they do not exist at the end of the workflow:

    - name: Ensure cache directories exist
      shell: bash
      run: |
        # This helps avoid caching warnings even when these are not used.
        if [ ! -d "${{ github.workspace }}/.build" ]; then
          mkdir "${{ github.workspace }}/.build"
          echo ".build directory created."
        fi
gaby commented 2 months ago

I don't understand why this action doesn't just create the directory ?

antazoey commented 2 months ago

I don't understand why this action doesn't just create the directory ?

because it is a bit odd to cache something that doesn't exist. In my case, it may or may not exist, so it's helpful for me to ignore this warning because it is no big deal that the directory was never made.