question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't store using hashFiles if files don't exist yet

See original GitHub issue

For example, in a Rust project, the target directory is almost never committed as it includes build artifacts. I’d like to cache it between builds, but using

name: Cache target dir
uses: actions/cache@v1
with:
  path: target
  key: ${{ runner.os }}-cargo-target-${{ hashFiles('target') }} # also tried variants of `target/**`...

triggers a failure that prevents the build from continuing:

##[error]The template is not valid. hashFiles('/home/runner/work/.../.../target') failed. Search pattern '/home/runner/work/.../.../target' doesn't match any file under '/home/runner/work/.../...'

which does make sense! After checking out, there is not yet a target directory. In fact, that’s what I aim to create (maybe) when I restore from the cache. So storing would work with this template, but restoring would not, since the key can’t be computed.

If I supply restore-keys, though, I still get the same error. It seems to me like something (maybe not in this codebase) is just dying early because the template isn’t fully computable, instead of trying to fall back on the restore-keys first.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
chrispatcommented, Nov 25, 2019

@rye perhaps we could update hashFiles with an additional parameter that you could set that would have it not fail if it didn’t find any files. I suppose the other option is to simply warn rather than fail, however, that would mean in your case that you would perpetually have a warning on your jobs that you could likely never get rid of.

2reactions
ryecommented, Nov 23, 2019

I do agree that the current error form makes things stricter, but I don’t think the strictness is helpful—a hashFiles error (due to files not existing) seems to be causing a parsing error, i.e. restore_keys is not even used at all; the cache restore just completely fails. My use case would be satisfied if restore_keys was used in such cases.

Of course, I could leave off the hashFiles in my key, but then I would basically have a persistent cache that never got updated if things changed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Hashing to prevent file duplicates and save storage
This article aims to show a method of preventing duplicate files and saving storage space by using hashing algorithms.
Read more >
How to associate a file to an hash code, and use it to find the ...
Locating the file using the hash would involve a simple key lookup in the database. Moving the file would involve updating the database....
Read more >
HTTP Spec: PUT without data transfer, since hash of data is ...
Client computes the ETag for the file/resource to upload. Client sends a PUT request to the server (location doesn't matter) with the header...
Read more >
Reasons Your Checksum Doesn't Match the Original
Whether you've downloaded a file, or need a helpful link for troubleshooting hashing issues, below we cover a couple of reasons your checksum ......
Read more >
An introduction to hashing and checksums in Linux - Red Hat
Always wondered how to make use of a checksum? This introduction shows you what they mean, and how to use the proper tools...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found