Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to override build date with SOURCE_DATE_EPOCH #2246

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bmwiedemann
Copy link

Allow to override build date with SOURCE_DATE_EPOCH
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.

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.
@github-actions github-actions bot added the area/docs-generation Generation of docs via Cobra label Mar 4, 2025
Copy link
Collaborator

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a shared function doc/util.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs-generation Generation of docs via Cobra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants