diff --git a/pkg/build/build.go b/pkg/build/build.go index e6a38cbaa..c26cf6472 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -1196,6 +1196,9 @@ func sourceDateEpoch(defaultTime time.Time) (time.Time, error) { // SHOULD exit with a non-zero error code. return defaultTime, fmt.Errorf("failed to parse SOURCE_DATE_EPOCH: %w", err) } + if sec < 315532800 { + return defaultTime, fmt.Errorf("SOURCE_DATE_EPOCH prior to 1980-01-01 12:00:00 not supported: %v", sec) + } return time.Unix(sec, 0).UTC(), nil } diff --git a/pkg/build/build_test.go b/pkg/build/build_test.go index f1ab61be4..a2a0e0898 100644 --- a/pkg/build/build_test.go +++ b/pkg/build/build_test.go @@ -343,10 +343,16 @@ func TestSourceDateEpoch(t *testing.T) { want: time.Unix(1234567890, 0), }, { - name: "0", + name: "Min time", + sourceDateEpoch: "315532800", + defaultTime: time.Unix(1234567890, 0), + want: time.Unix(315532800, 0), + }, + { + name: "Below min time", sourceDateEpoch: "0", defaultTime: time.Unix(1234567890, 0), - want: time.Unix(0, 0), + wantErr: true, }, { name: "1234567890", @@ -369,12 +375,12 @@ func TestSourceDateEpoch(t *testing.T) { got, err := sourceDateEpoch(tt.defaultTime) if err != nil { if !tt.wantErr { - t.Fatalf("SourceDateEpoch() error = %v, wantErr %v", err, tt.wantErr) + t.Fatalf("%s: SourceDateEpoch() error = %v, wantErr %v", tt.name, err, tt.wantErr) } return } if !got.Equal(tt.want) { - t.Errorf("SourceDateEpoch() = %v, want %v", got, tt.want) + t.Errorf("%s: SourceDateEpoch() = %v, want %v", tt.name, got, tt.want) } }) } diff --git a/pkg/build/options.go b/pkg/build/options.go index df1f929ed..feb3ae598 100644 --- a/pkg/build/options.go +++ b/pkg/build/options.go @@ -58,7 +58,7 @@ func WithBuildDate(s string) Option { return func(bc *Build) error { // default to 0 for reproducibility if s == "" { - bc.SourceDateEpoch = time.Unix(0, 0) + bc.SourceDateEpoch = time.Unix(315532800, 0) return nil } diff --git a/pkg/build/pipelines/git-checkout.yaml b/pkg/build/pipelines/git-checkout.yaml index ee425009c..c8ca967a1 100644 --- a/pkg/build/pipelines/git-checkout.yaml +++ b/pkg/build/pipelines/git-checkout.yaml @@ -62,7 +62,7 @@ pipeline: process_cherry_picks() { local cpicksf="$1" oifs="$IFS" count=0 local fetched_branches="" - local sdate=${SOURCE_DATE_EPOCH:-0} + local sdate=${SOURCE_DATE_EPOCH:-315532800} if [ "$sdate" -lt 315532800 ]; then msg "Setting commit date to Jan 1, 1980 (SOURCE_DATE_EPOCH found ${SOURCE_DATE_EPOCH})" sdate=315532800 diff --git a/pkg/build/sign_test.go b/pkg/build/sign_test.go index 4a5291f94..d91a63e9b 100644 --- a/pkg/build/sign_test.go +++ b/pkg/build/sign_test.go @@ -19,7 +19,7 @@ const MockName = "mockiavelli" func TestEmitSignature(t *testing.T) { ctx := slogtest.Context(t) - sde := time.Unix(12345678, 0) + sde := time.Unix(1234567890, 0) controlData := []byte("donkey") diff --git a/pkg/cli/scan.go b/pkg/cli/scan.go index eb6be59c4..a599a67d2 100644 --- a/pkg/cli/scan.go +++ b/pkg/cli/scan.go @@ -148,7 +148,7 @@ func scanCmd(ctx context.Context, file string, sc *scanConfig) error { bb := &build.Build{ WorkspaceDir: dir, - SourceDateEpoch: time.Unix(0, 0), + SourceDateEpoch: time.Unix(315532800, 0), Configuration: *cfg, }