Allow to override build date with SOURCE_DATE_EPOCH#2246
Allow to override build date with SOURCE_DATE_EPOCH#2246bmwiedemann wants to merge 1 commit intospf13:mainfrom
Conversation
to make builds reproducible. See https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable. This patch was done while working on reproducible builds for openSUSE.
marckhouzam
left a comment
There was a problem hiding this comment.
Thanks for this.
Somehow Cobra already used this variable in man_docs.go but not in the other formats.
Would you mind also adding this check in md_docs.go?
It would also be nice to have a test to make sure the variable is respected.
| now := time.Now() | ||
| if epoch := os.Getenv("SOURCE_DATE_EPOCH"); epoch != "" { | ||
| unixEpoch, err := strconv.ParseInt(epoch, 10, 64) | ||
| if err == nil { |
There was a problem hiding this comment.
According to the spec, if the variable is poorly formatted, we should return an error.
Can you handle it like it is done here
https://github.com/spf13/cobra/blob/4f9ef8cdbbc88c5302be95e0e67fd78ebbfa9dd2/doc/man_docs.go#L129C4-L131C5
There was a problem hiding this comment.
I wanted to keep the code simpler, because in practice, the variable is either unset or valid and we have used this simplification in other places.
But if you insist, we can copy the approach from man_docs. Is code-duplication okay or should it moved out somehow somewhere (I'm not so familiar with golang)
There was a problem hiding this comment.
You could add a shared function doc/util.go
Allow to override build date with
SOURCE_DATE_EPOCHto make builds reproducible.
See https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable.
This patch was done while working on reproducible builds for openSUSE.