Skip to content

Commit 19ae400

Browse files
authored
Orchestrator mode: locking project report failure status (#1481)
* projects that fail to aquire lock should have failed status
1 parent 00125e7 commit 19ae400

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

cli/cmd/digger/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ func gitHubCI(lock core_locking.Lock, policyChecker core_policy.Checker, backend
201201

202202
jobs := []orchestrator.Job{orchestrator.JsonToJob(job)}
203203

204-
_, _, err = digger.RunJobs(jobs, &githubPrService, &githubPrService, lock, reporter, planStorage, policyChecker, commentUpdater, backendApi, inputs.Id, true, commentId64, currentDir)
205-
if err != nil {
204+
allAppliesSuccess, _, err := digger.RunJobs(jobs, &githubPrService, &githubPrService, lock, reporter, planStorage, policyChecker, commentUpdater, backendApi, inputs.Id, true, commentId64, currentDir)
205+
if !allAppliesSuccess || err != nil {
206206
serializedBatch, reportingError := backendApi.ReportProjectJobStatus(repoName, job.ProjectName, inputs.Id, "failed", time.Now(), nil)
207207
if reportingError != nil {
208208
reportErrorAndExit(githubActor, fmt.Sprintf("Failed run commands. %s", err), 5)

cli/pkg/digger/digger.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ func RunJobs(
115115
if reportErr != nil {
116116
log.Printf("error reporting project Run err: %v.\n", reportErr)
117117
}
118-
return false, false, fmt.Errorf("error while running command: %v", err)
118+
appliesPerProject[job.ProjectName] = false
119+
if executorResult != nil {
120+
exectorResults[i] = *executorResult
121+
}
122+
log.Printf("Project %v command %v failed, skipping job", job.ProjectName, command)
123+
break
119124
}
120125
exectorResults[i] = *executorResult
121126

cli/pkg/locking/locking.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (projectLock *PullRequestLock) Lock() (bool, error) {
7676
comment := "Project " + projectLock.projectId() + " locked by another PR #" + transactionIdStr + " (failed to acquire lock " + projectLock.ProjectNamespace + "). The locking plan must be applied or discarded before future plans can execute"
7777

7878
reportLockingFailed(projectLock.Reporter, comment)
79-
return false, nil
79+
return false, fmt.Errorf(comment)
8080
}
8181
}
8282
lockAcquired, err := projectLock.InternalLock.Lock(projectLock.PrNumber, lockId)
@@ -147,7 +147,7 @@ func (projectLock *PullRequestLock) verifyNoHangingLocks() (bool, error) {
147147
transactionIdStr := strconv.Itoa(*transactionId)
148148
comment := "Project " + projectLock.projectId() + " locked by another PR #" + transactionIdStr + "(failed to acquire lock " + projectLock.ProjectName + "). The locking plan must be applied or discarded before future plans can execute"
149149
reportLockingFailed(projectLock.Reporter, comment)
150-
return false, nil
150+
return false, fmt.Errorf(comment)
151151
}
152152
return true, nil
153153
}

cli/pkg/locking/locking_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ func TestLockingTwiceThrowsError(t *testing.T) {
3333
}
3434
state2, err2 := pl2.Lock()
3535
assert.False(t, state2)
36-
// No error because the lock was not acquired
37-
assert.NoError(t, err2)
36+
assert.Error(t, err2)
3837
}
3938

4039
func TestGetLock(t *testing.T) {

0 commit comments

Comments
 (0)