Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
fix(buildchecker): do not consider cron builds (#38152)
Browse files Browse the repository at this point in the history
* check if a build source is scheduled
  • Loading branch information
burmudar authored and vovakulikov committed Jul 20, 2022
1 parent a688813 commit 1711d70
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions dev/buildchecker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func CheckBuilds(ctx context.Context, branch BranchLocker, teammates team.Teamma
// Scan for first build with a meaningful state
var firstFailedBuildIndex int
for i, b := range builds {
if isBuildScheduled(b) {
// a Scheduled build should not be considered as part of the set that determines whether
// main is locked.
// An exmaple of a scheduled build is the nightly release healthcheck build at:
// https://buildkite.com/sourcegraph/sourcegraph/settings/schedules/d0b2e4ea-e2df-4fb5-b90e-db88fddb1b76
continue
}
if isBuildPassed(b) {
fmt.Printf("most recent finished build %d passed\n", *b.Number)
results.Action, err = branch.Unlock(ctx)
Expand Down Expand Up @@ -103,6 +110,10 @@ func CheckBuilds(ctx context.Context, branch BranchLocker, teammates team.Teamma
return
}

func isBuildScheduled(build buildkite.Build) bool {
return build.Source != nil && *build.Source == "scheduled"
}

func isBuildPassed(build buildkite.Build) bool {
return build.State != nil && *build.State == "passed"
}
Expand Down
11 changes: 11 additions & 0 deletions dev/buildchecker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ func TestCheckBuilds(t *testing.T) {
State: buildkite.String("running"),
StartedAt: buildkite.NewTimestamp(time.Now()),
}
scheduledBuild := buildkite.Build{
Number: buildkite.Int(5),
Commit: buildkite.String("a"),
State: buildkite.String("failed"),
StartedAt: buildkite.NewTimestamp(time.Now()),
Source: buildkite.String("scheduled"),
}

tests := []struct {
name string
Expand All @@ -82,6 +89,10 @@ func TestCheckBuilds(t *testing.T) {
name: "should skip leading running builds to lock",
builds: append([]buildkite.Build{runningBuild}, failSet...),
wantLocked: true,
}, {
name: "should not locked because of scheduled build",
builds: []buildkite.Build{failSet[0], scheduledBuild},
wantLocked: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions dev/buildchecker/failures.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func findConsecutiveFailures(
var consecutiveFailures int
var build buildkite.Build
for buildsScanned, build = range builds {
if isBuildScheduled(build) {
// a Scheduled build should not be considered as part of the set that determines whether
// main is locked.
// An exmaple of a scheduled build is the nightly release healthcheck build at:
// https://buildkite.com/sourcegraph/sourcegraph/settings/schedules/d0b2e4ea-e2df-4fb5-b90e-db88fddb1b76
continue
}
if isBuildPassed(build) {
// If we find a passed build we are done
return
Expand Down

0 comments on commit 1711d70

Please sign in to comment.