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

Add the `hashFiles` template func to calculate the SHA256 hash of multiple files #198

Closed ste93cry closed 2 years ago

ste93cry commented 2 years ago

Fixes #196

Proposed Changes

Description

The checksum template function is able to compute the MD5 hash of just one file per time. Instead, similarly to what can be done in the GitHub Actions, it is sometimes useful to be able to get the hash of a series of files. In addition to this, it is also sometimes useful to be able to get the list of files according to a glob pattern. To avoid breaking changes and to also make it clearer that the function can work with a list of files, I've added a new hashFiles function.

Checklist

KucharczykL commented 2 years ago

Hi, I've found this PR when looking for docs about the checksum function to see if it supports multiple files and globs. It would be really nice to have this!

ste93cry commented 2 years ago

@hikerspath can you please review this?

bdebyl commented 2 years ago

@ste93cry Do you mind resolving the merge conflicts by pulling latest master into your working branch?

ste93cry commented 2 years ago

While we're at it, I was wondering if it makes sense to change the hashing algorithm to SHA256 like GitHub. WDYT?

bdebyl commented 2 years ago

@ste93cry I'll leave this entirely up to you. As it's just simple file hashes I don't see a problem sticking with md5, but I fully support either! Let me know if you want me to create a separate issue to change from md5 to sha2 or if you'd like to just implement the change to use sha2 with this PR.

Again, either way is fine by me and thanks for the good work :)

ste93cry commented 2 years ago

As it's just simple file hashes I don't see a problem sticking with md5

The main problem is that you may get the same hash for different files. More details can be found here

Let me know if you want me to create a separate issue to change from md5 to sha2 or if you'd like to just implement the change to use sha2 with this PR

Let's implement the changes here, they are minimal anyway so it won't take much more time to implement them

bdebyl commented 2 years ago

The main problem is that you may get the same hash for different files. More details can be found here

True, though random collisions are extremely rare though I can certainly see the rainbow-table, or similar, security concerns.

Let's implement the changes here, they are minimal anyway so it won't take much more time to implement them

Sounds great! Let me know if you want me to work on it, or if you'll be taking the charge on the code changes necessary for this change. In either case I'm happy to help!

ste93cry commented 2 years ago

@bdebyl changes are ready, do you mind reviewing them?

bdebyl commented 2 years ago

@ste93cry sorry for getting back to you so late, it looks good to me pending one more engineering team member review and then we can merge and stage it for v1.4.0!