~fgaz/builds.sr.ht

7f1998a01ae2035ec2827d0c489fd42e514c17ed — Simon Ser 1 year, 7 months ago 2689f2a
worker: stop using a special exit status for complete-build

Use a file instead. This should be much less fragile.

Fixes ssh connection failures (they return 255) from making the
build succeed (and skip subsequent tasks). See for instance [1].

[1]: https://builds.sr.ht/~emersion/job/792004
1 files changed, 23 insertions(+), 20 deletions(-)

M worker/tasks.go
M worker/tasks.go => worker/tasks.go +23 -20
@@ 16,7 16,6 @@ import (
	"regexp"
	"strconv"
	"strings"
	"syscall"
	"text/template"
	"time"



@@ 194,7 193,8 @@ func (ctx *JobContext) SendEnv() error {
	envpath := path.Join(ctx.ImageConfig.Homedir, ".buildenv")
	env := `#!/bin/sh
complete-build() {
	exit 255
	echo 1 > ~/.complete-build
	exit 0
}
`
	if ctx.Manifest.Environment == nil {


@@ 585,29 585,22 @@ func (ctx *JobContext) RunTasks() error {
		go io.Copy(logfd, tty)

		if err = ssh.Wait(); err != nil {
			exiterr, ok := err.(*exec.ExitError)
			if !ok {
				goto fail
			}
			status, ok := exiterr.Sys().(syscall.WaitStatus)
			if !ok {
				goto fail
			}
			if status.ExitStatus() == 255 {
				ctx.Job.SetTaskStatus(name, "success")
				for i++; i < len(ctx.Manifest.Tasks); i++ {
					for name, _ = range ctx.Manifest.Tasks[i] {
						break
					}
					ctx.Job.SetTaskStatus(name, "skipped")
				}
				break
			}
			err = errors.Wrap(err, "Running task on guest")
			goto fail
		}

		ctx.Job.SetTaskStatus(name, "success")

		if ctx.isMarkedAsCompleted() {
			for i++; i < len(ctx.Manifest.Tasks); i++ {
				for name, _ = range ctx.Manifest.Tasks[i] {
					break
				}
				ctx.Job.SetTaskStatus(name, "skipped")
			}
			break
		}

		continue
	fail:
		ctx.Job.SetTaskStatus(name, "failed")


@@ 616,6 609,16 @@ func (ctx *JobContext) RunTasks() error {
	return nil
}

func (ctx *JobContext) isMarkedAsCompleted() bool {
	rc, err := ctx.Download(".complete-build")
	if err != nil {
		return false
	}
	b, _ := ioutil.ReadAll(rc)
	rc.Close()
	return strings.TrimSpace(string(b)) == "1"
}

func (ctx *JobContext) UploadArtifacts() error {
	if len(ctx.Manifest.Artifacts) == 0 {
		return nil