Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit 29e0942

Browse files
authored
Don't exit prematurely on receiving ExitInstruction from the cloud (#125)
* Don't exit prematurely on receiving ExitInstruction from the cloud * .cirrus.yml: bump resources for the Release (Dry Run) too
1 parent 41373a3 commit 29e0942

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

.cirrus.yml

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ task:
7070
- test-freebsd
7171
container:
7272
image: golang:latest
73+
cpu: 4
74+
memory: 12G
7375
install_script: curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
7476
release_script: ./bin/goreleaser build --snapshot
7577
binaries_artifacts:

internal/executor/executor.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ type Executor struct {
4545
preCreatedWorkingDir string
4646
}
4747

48+
var (
49+
ErrStepExit = errors.New("executor step requested to terminate execution")
50+
ErrStepFailed = errors.New("executor step failed")
51+
)
52+
4853
func NewExecutor(
4954
taskId int64,
5055
clientToken,
@@ -133,7 +138,11 @@ func (executor *Executor) RunBuild() {
133138
}
134139

135140
log.Printf("Executing %s...", command.Name)
136-
if !executor.performStep(environment, command) {
141+
if err := executor.performStep(environment, command); err != nil {
142+
if errors.Is(err, ErrStepExit) {
143+
return
144+
}
145+
137146
failedAtLeastOnce = true
138147
}
139148
log.Printf("%s finished!", command.Name)
@@ -204,14 +213,14 @@ func getExpandedScriptEnvironment(executor *Executor, responseEnvironment map[st
204213
return result
205214
}
206215

207-
func (executor *Executor) performStep(env map[string]string, currentStep *api.Command) bool {
216+
func (executor *Executor) performStep(env map[string]string, currentStep *api.Command) error {
208217
success := false
209218
signaledToExit := false
210219
start := time.Now()
211220

212221
switch instruction := currentStep.Instruction.(type) {
213222
case *api.Command_ExitInstruction:
214-
os.Exit(0)
223+
return ErrStepExit
215224
case *api.Command_CloneInstruction:
216225
success = executor.CloneRepository(env)
217226
case *api.Command_FileInstruction:
@@ -269,7 +278,12 @@ func (executor *Executor) performStep(env map[string]string, currentStep *api.Co
269278
time.Sleep(10 * time.Second)
270279
_, err = client.CirrusClient.ReportSingleCommand(context.Background(), &reportRequest)
271280
}
272-
return success
281+
282+
if !success {
283+
return ErrStepFailed
284+
}
285+
286+
return nil
273287
}
274288

275289
func (executor *Executor) ExecuteScriptsStreamLogsAndWait(

0 commit comments

Comments
 (0)