wire
wire copied to clipboard
Add an option to include a hash/checksum of the source files
Describe the solution you'd like
I would like an option that adds a field to the generated go code, the value of which is a hash of the source files consumed by wire to generate the go code. Something like:
const __WireGenSourceHash = `
SHA256(wire.go)= d9e5810b60740bf4cc0f1f7494cff955b3c67f5eb4a32cc8f4e23c93b91ac670
`
What I would like to achieve is a git pre-commit hook that would prevent committing when wire.go
and wire_gen.go
no longer match.
Describe alternatives you've considered
I've considered something like //go:generate sha256sum wire.go > wire_gen.sha
, but nothing I've thought of is as foolproof as having Wire generate the hash itself.
Additional context
I imagine there are other scenarios that would benefit from a verifiable signature of the files that were used to generate wire_gen.go
.
I generated this SHA via openssl dgst -sha256 wire.go
on macOS.
What I would like to achieve is a git pre-commit hook that would prevent committing when wire.go and wire_gen.go no longer match
Can you use wire diff
for this instead? Here's an example in the shell script that our Travis job over on the go-cloud
repo runs, for a similar purpose (except it causes the checks to fail instead of being a git pre-commit hook).
https://github.com/google/go-cloud/blob/master/internal/testing/runchecks.sh#L57
I want the pre-commit hook to be runnable without Wire installed. Linux, macOS, and Windows all come OOTB with a hash tool or two, so a pre-commit hook based on this could work without requiring the dev to do anything but clone my project and install the hook.
What is the dev expected to do if the pre-commit hook fails? It seems like they'd need to install Wire to fix the problem anyway, no?
Also, note that the "expected" contents of wire_gen.go
could change when wire.go
changes, but also when you get a new version of wire
itself.