cache icon indicating copy to clipboard operation
cache copied to clipboard

Debug logs show hashFiles generates a hash; hash gets truncated when actually saving

Open gspetro-NOAA opened this issue 2 months ago • 1 comments

I am trying to cache a file with the following step:

      - name: Cache machine stats
        id: cache-stats
        uses: actions/cache@v4
        with:
          path: ${{ github.workspace }}/data/stats.json
          key: hist-stats-${{ hashFiles('**/data/stats.json') }}

I already ran the checkout action, the file exists, and when I run the action with the debug option on, the logs show that the file name should be: hist-stats-b97af91963eaed082bd76ddcb2e2eb7dd314fc74b1a09bc908365a0053c00b5d. However, when the cache is finally uploaded, it says Cache saved with key: hist-stats- (no hash), and when I check the caches, only hist-stats- appears. I can't for the life of me figure out why this would be and would appreciate any pointers.

You can see the PR/code that is triggering the action here: https://github.com/ufs-community/ufs-weather-model/pull/2924

I'm sorry if the issue is due to something obvious--I'm rather new to this, and I'm not seeing anything online that helps/applies to my situation.

gspetro-NOAA avatar Oct 14 '25 03:10 gspetro-NOAA

Hi @gspetro-NOAA

I took a look at the debug logs for the Cache machine stats step. At lines 50-57 the debug logs reveal that the hash is calculated to be '', which results in the cache-key being hist-stats-. This occurs because there are no files that match the pattern.

Based on the documentation for hashFiles, it is expected to return an empty string when no files match the provided pattern(s).

The hist-stats-b97af91963eaed082bd76ddcb2e2eb7dd314fc74b1a09bc908365a0053c00b5d key in the Post Cache machine stats step is the cache-key that will be used when uploading the cache, but given that this file is being created during the workflow and not available when trying to restore the cache, it doesn't seem possible that the generated cache would be able to be retrieved.

One potential option would be to have a step that gets the data/stats.json file into the workspace before trying to retrieve cache. This would depend on your particular use case, so might not be feasible.

mrkiffie avatar Nov 04 '25 07:11 mrkiffie