summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Lee <cplee@nektos.com>2019-03-02 16:53:24 +0100
committerGitHub <noreply@github.com>2019-03-02 16:53:24 +0100
commitb18239ff773a4c677af4ceedc4c70b4c657b6046 (patch)
tree178880a260169f7177baba6d4f9a9efc56eb92ca
parentskip integration test (diff)
parentAdd an extra test (diff)
downloadforgejo-act-b18239ff773a4c677af4ceedc4c70b4c657b6046.tar.xz
forgejo-act-b18239ff773a4c677af4ceedc4c70b4c657b6046.zip
Merge pull request #46 from sosedoff/capture-build-error
Handle docker image build failures
-rw-r--r--Makefile3
-rw-r--r--actions/runner_test.go3
-rw-r--r--actions/testdata/buildfail-action/Dockerfile2
-rw-r--r--actions/testdata/buildfail.workflow8
-rw-r--r--container/docker_build.go3
-rw-r--r--container/docker_common.go45
6 files changed, 45 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 2866dcc..35fcfe2 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,9 @@ export GITHUB_TOKEN = $(shell cat ~/.config/github/token)
default: check
+test:
+ go test -cover -short ./...
+
check:
$(ACT) -ra check
diff --git a/actions/runner_test.go b/actions/runner_test.go
index 92ef52c..46c969f 100644
--- a/actions/runner_test.go
+++ b/actions/runner_test.go
@@ -21,6 +21,7 @@ func TestRunEvent(t *testing.T) {
{"basic.workflow", "push", ""},
{"pipe.workflow", "push", ""},
{"fail.workflow", "push", "exit with `FAILURE`: 1"},
+ {"buildfail.workflow", "push", "COPY failed"},
{"regex.workflow", "push", "exit with `NEUTRAL`: 78"},
{"gitref.workflow", "push", ""},
{"env.workflow", "push", ""},
@@ -42,7 +43,7 @@ func TestRunEvent(t *testing.T) {
if table.errorMessage == "" {
assert.NilError(t, err, table.workflowPath)
} else {
- assert.Error(t, err, table.errorMessage)
+ assert.ErrorContains(t, err, table.errorMessage)
}
}
}
diff --git a/actions/testdata/buildfail-action/Dockerfile b/actions/testdata/buildfail-action/Dockerfile
new file mode 100644
index 0000000..3a4b7b1
--- /dev/null
+++ b/actions/testdata/buildfail-action/Dockerfile
@@ -0,0 +1,2 @@
+FROM alpine:3.8
+COPY foobar /foo/bar \ No newline at end of file
diff --git a/actions/testdata/buildfail.workflow b/actions/testdata/buildfail.workflow
new file mode 100644
index 0000000..51eae00
--- /dev/null
+++ b/actions/testdata/buildfail.workflow
@@ -0,0 +1,8 @@
+workflow "test" {
+ on = "push"
+ resolves = ["test-action"]
+}
+
+action "test-action" {
+ uses = "./buildfail-action"
+} \ No newline at end of file
diff --git a/container/docker_build.go b/container/docker_build.go
index f885add..8fac5f4 100644
--- a/container/docker_build.go
+++ b/container/docker_build.go
@@ -51,7 +51,8 @@ func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
input.Logger.Debugf("Creating image from context dir '%s' with tag '%s'", input.ContextDir, input.ImageTag)
resp, err := cli.ImageBuild(input.Ctx, buildContext, options)
- input.logDockerResponse(resp.Body, err != nil)
+
+ err = input.logDockerResponse(resp.Body, err != nil)
if err != nil {
return err
}
diff --git a/container/docker_common.go b/container/docker_common.go
index 6665cdc..1a33eb0 100644
--- a/container/docker_common.go
+++ b/container/docker_common.go
@@ -4,6 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
+ "errors"
"fmt"
"io"
"os"
@@ -64,42 +65,52 @@ func (i *DockerExecutorInput) writeLog(isError bool, format string, args ...inte
}
-func (i *DockerExecutorInput) logDockerResponse(dockerResponse io.ReadCloser, isError bool) {
+func (i *DockerExecutorInput) logDockerResponse(dockerResponse io.ReadCloser, isError bool) error {
if dockerResponse == nil {
- return
+ return nil
}
defer dockerResponse.Close()
scanner := bufio.NewScanner(dockerResponse)
msg := dockerMessage{}
+
for scanner.Scan() {
line := scanner.Bytes()
+
msg.ID = ""
msg.Stream = ""
msg.Error = ""
msg.ErrorDetail.Message = ""
msg.Status = ""
msg.Progress = ""
- if err := json.Unmarshal(line, &msg); err == nil {
- if msg.Error != "" {
- i.writeLog(isError, "%s", msg.Error)
- return
- }
- if msg.Status != "" {
- if msg.Progress != "" {
- i.writeLog(isError, "%s :: %s :: %s\n", msg.Status, msg.ID, msg.Progress)
- } else {
- i.writeLog(isError, "%s :: %s\n", msg.Status, msg.ID)
- }
- } else if msg.Stream != "" {
- i.writeLog(isError, msg.Stream)
+ if err := json.Unmarshal(line, &msg); err != nil {
+ i.writeLog(false, "Unable to unmarshal line [%s] ==> %v", string(line), err)
+ continue
+ }
+
+ if msg.Error != "" {
+ i.writeLog(isError, "%s", msg.Error)
+ return errors.New(msg.Error)
+ }
+
+ if msg.ErrorDetail.Message != "" {
+ i.writeLog(isError, "%s", msg.ErrorDetail.Message)
+ return errors.New(msg.Error)
+ }
+
+ if msg.Status != "" {
+ if msg.Progress != "" {
+ i.writeLog(isError, "%s :: %s :: %s\n", msg.Status, msg.ID, msg.Progress)
} else {
- i.writeLog(false, "Unable to handle line: %s", string(line))
+ i.writeLog(isError, "%s :: %s\n", msg.Status, msg.ID)
}
+ } else if msg.Stream != "" {
+ i.writeLog(isError, msg.Stream)
} else {
- i.writeLog(false, "Unable to unmarshal line [%s] ==> %v", string(line), err)
+ i.writeLog(false, "Unable to handle line: %s", string(line))
}
}
+ return nil
}