Skip to content

Commit

Permalink
Allow to override build date with SOURCE_DATE_EPOCH
Browse files Browse the repository at this point in the history
in order 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.
  • Loading branch information
bmwiedemann authored and Bernhard M. Wiedemann committed Oct 11, 2023
1 parent 9f54e0f commit fbeaad1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -100,6 +101,14 @@ func Clean() error {

func flags() string {
timestamp := time.Now().Format(time.RFC3339)
source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH")
if source_date_epoch != "" {
sde, err := strconv.ParseInt(source_date_epoch, 10, 64)
if err != nil {
panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err))
}
timestamp = time.Unix(sde, 0).UTC().Format(time.RFC3339)
}
hash := hash()
tag := tag()
if tag == "" {
Expand Down

0 comments on commit fbeaad1

Please sign in to comment.