meltwater / drone-cache

A Drone plugin for caching current workspace files between builds to reduce your build times
https://underthehood.meltwater.com/blog/2019/04/10/making-drone-builds-10-times-faster/
Apache License 2.0
338 stars 81 forks source link

"No matches found for glob" using hashFiles with packages.lock.json #237

Closed timbze closed 1 year ago

timbze commented 1 year ago

Describe the bug It seems that hashFiles is not working in my case. hashFiles was implemented in #198 by @ste93cry (for reference).

Is there anything I'm doing wrong? (details below)

- name: Restore nuget cache
  image: meltwater/drone-cache:v1.4.0
  pull: always
  settings:
    debug: true
    backend: "filesystem"
    restore: true
    cache_key: myapp_{{ hashFiles "**/packages.lock.json" }}_{{ arch }}_{{ os }}
    archive_format: "gzip"
    mount:
      - ".nuget-cache"
  volumes:
    - name: cache
      path: /tmp/cache

Here's the log from the cache restore. Notice these almost at the end:

level=debug name=drone-cache ts=2023-02-01T21:02:04.207591822Z caller=metadata.go:120 component=plugin nomatchesfoundforglob=(MISSING)
level=info name=drone-cache ts=2023-02-01T21:02:04.207655621Z caller=restorer.go:54 component=plugin component=restorer msg="restoring directory" local=.nuget-cache remote=myapp/myapp__amd64_linux/.nuget-cache

logs_drone-cache.log

When I run find before the cache restore I get the files find . -type f -name packages.lock.json

./src/proj1/packages.lock.json
./src/proj2/packages.lock.json
./src/proj3/packages.lock.json
./src/proj4/packages.lock.json
./src/proj5/packages.lock.json
./src/proj6/packages.lock.json
./src/proj7/packages.lock.json
./src/proj8/packages.lock.json
./src/proj9/packages.lock.json
./src/proj10/packages.lock.json
./test/proj11.Tests/packages.lock.json
./test/proj12.Tests/packages.lock.json
./test/proj13.Tests/packages.lock.json

I am using drone-cache 1.4.0

bdebyl commented 1 year ago

Hello @timbze I believe this is incorrect usage of the hashFiles. This feature uses Golang's filepath.Glob for reference. You will need to change your value to "**/**/packages.lock.json" from "**/packages.lock.json" to include subdirectories of directories.

Example via Code

$ tree
.
|-- a
|   |-- e
|   |   `-- test.log
|   |-- f
|   |   `-- test.log
|   `-- g
|       `-- test.log
|-- b
|   |-- e
|   |   `-- test.log
|   |-- f
|   |   `-- test.log
|   `-- g
|       `-- test.log
|-- c
|   |-- e
|   |   `-- test.log
|   |-- f
|   |   `-- test.log
|   `-- g
|       `-- test.log
`-- main.go

13 directories, 10 files

$ go run ./main.go -path "**/test.log"
[] <nil>

$ go run ./main.go -path "**/**/test.log"
[a/e/test.log a/f/test.log a/g/test.log b/e/test.log b/f/test.log b/g/test.log c/e/test.log c/f/test.log c/g/test.log] <nil>
timbze commented 1 year ago

Amazing 😄 you wouldn't guess how much time I had wasted with this 🙈

Thank you