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

build: valid SOURCE_DATE_EPOCH #1520

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions pkg/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ func TestSourceDateEpoch(t *testing.T) {
want: time.Unix(1234567890, 0),
},
{
name: "0",
sourceDateEpoch: "0",
name: "Min time",
sourceDateEpoch: "315532800",
defaultTime: time.Unix(1234567890, 0),
want: time.Unix(0, 0),
want: time.Unix(315532800, 0),
xnox marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "1234567890",
Expand All @@ -369,12 +369,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)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/build/pipelines/git-checkout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
Loading