summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Lee <cplee@nektos.com>2020-02-24 21:48:12 +0100
committerCasey Lee <cplee@nektos.com>2020-02-24 21:48:12 +0100
commit037e08a3a77eb3d89d765213617e97e9691d83e3 (patch)
treedd00e6a9d808ea40aff04c46a431e0c7a3b2e20d
parentunit tests pass (diff)
downloadforgejo-act-037e08a3a77eb3d89d765213617e97e9691d83e3.tar.xz
forgejo-act-037e08a3a77eb3d89d765213617e97e9691d83e3.zip
integration test
-rw-r--r--.github/workflows/lint/Dockerfile (renamed from .github/workflows/check/Dockerfile)0
-rw-r--r--.github/workflows/lint/action.yml (renamed from .github/workflows/check/action.yml)4
-rw-r--r--.github/workflows/lint/entrypoint.sh (renamed from .github/workflows/check/entrypoint.sh)1
-rw-r--r--.github/workflows/push.yml9
-rw-r--r--.github/workflows/tag.yml2
-rw-r--r--pkg/common/git.go2
-rw-r--r--pkg/common/line_writer.go7
-rw-r--r--pkg/common/line_writer_test.go3
-rw-r--r--pkg/runner/command.go85
-rw-r--r--pkg/runner/command_test.go13
-rw-r--r--pkg/runner/run_context.go19
-rw-r--r--pkg/runner/step_context.go18
12 files changed, 92 insertions, 71 deletions
diff --git a/.github/workflows/check/Dockerfile b/.github/workflows/lint/Dockerfile
index 5c67ab2..5c67ab2 100644
--- a/.github/workflows/check/Dockerfile
+++ b/.github/workflows/lint/Dockerfile
diff --git a/.github/workflows/check/action.yml b/.github/workflows/lint/action.yml
index 5222118..2f30087 100644
--- a/.github/workflows/check/action.yml
+++ b/.github/workflows/lint/action.yml
@@ -1,5 +1,5 @@
-name: Check
-description: Run static analysis and unit tests
+name: Lint
+description: Run static analysis
branding:
icon: check-circle
color: green
diff --git a/.github/workflows/check/entrypoint.sh b/.github/workflows/lint/entrypoint.sh
index bbfc168..304b1b9 100644
--- a/.github/workflows/check/entrypoint.sh
+++ b/.github/workflows/lint/entrypoint.sh
@@ -1,4 +1,3 @@
#!/bin/sh
set -e
golangci-lint run
-go test -cover -short ./...
diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index 87d51e0..0db5137 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -6,5 +6,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- - uses: ./.github/workflows/check
- - uses: ./.github/workflows/integration
+ - uses: ./.github/workflows/lint
+ - uses: actions/setup-go@v1
+ with:
+ go-version: 1.13
+ - run: go test -cover ./...
+ env:
+ CGO_ENABLED: 0
diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml
index f64b244..6c1f4ef 100644
--- a/.github/workflows/tag.yml
+++ b/.github/workflows/tag.yml
@@ -9,8 +9,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- - uses: ./.github/workflows/check
- #- uses: ./.github/workflows/integration
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
diff --git a/pkg/common/git.go b/pkg/common/git.go
index 159141f..c7a059c 100644
--- a/pkg/common/git.go
+++ b/pkg/common/git.go
@@ -254,7 +254,7 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor {
Force: true,
})
if err != nil {
- logger.Errorf("Unable to checkout %s: %v", refName, err)
+ logger.Errorf("Unable to checkout %s: %v", *hash, err)
return err
}
diff --git a/pkg/common/line_writer.go b/pkg/common/line_writer.go
index 4d1661b..2035199 100644
--- a/pkg/common/line_writer.go
+++ b/pkg/common/line_writer.go
@@ -6,7 +6,7 @@ import (
)
// LineHandler is a callback function for handling a line
-type LineHandler func(line string)
+type LineHandler func(line string) bool
type lineWriter struct {
buffer bytes.Buffer
@@ -42,6 +42,9 @@ func (lw *lineWriter) Write(p []byte) (n int, err error) {
func (lw *lineWriter) handleLine(line string) {
for _, h := range lw.handlers {
- h(line)
+ ok := h(line)
+ if !ok {
+ break
+ }
}
}
diff --git a/pkg/common/line_writer_test.go b/pkg/common/line_writer_test.go
index 462a20d..44e11ef 100644
--- a/pkg/common/line_writer_test.go
+++ b/pkg/common/line_writer_test.go
@@ -8,8 +8,9 @@ import (
func TestLineWriter(t *testing.T) {
lines := make([]string, 0)
- lineHandler := func(s string) {
+ lineHandler := func(s string) bool {
lines = append(lines, s)
+ return true
}
lineWriter := NewLineWriter(lineHandler)
diff --git a/pkg/runner/command.go b/pkg/runner/command.go
index 08c1ac9..9e27b74 100644
--- a/pkg/runner/command.go
+++ b/pkg/runner/command.go
@@ -8,50 +8,63 @@ import (
"github.com/nektos/act/pkg/common"
)
-var commandPattern *regexp.Regexp
+var commandPatternGA *regexp.Regexp
+var commandPatternADO *regexp.Regexp
func init() {
- commandPattern = regexp.MustCompile("^::([^ ]+)( (.+))?::([^\r\n]*)[\r\n]+$")
+ commandPatternGA = regexp.MustCompile("^::([^ ]+)( (.+))?::([^\r\n]*)[\r\n]+$")
+ commandPatternADO = regexp.MustCompile("^##\\[([^ ]+)( (.+))?\\]([^\r\n]*)[\r\n]+$")
}
func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
logger := common.Logger(ctx)
resumeCommand := ""
- return func(line string) {
- if m := commandPattern.FindStringSubmatch(line); m != nil {
- command := m[1]
- kvPairs := parseKeyValuePairs(m[3])
- arg := m[4]
+ return func(line string) bool {
+ var command string
+ var kvPairs map[string]string
+ var arg string
+ if m := commandPatternGA.FindStringSubmatch(line); m != nil {
+ command = m[1]
+ kvPairs = parseKeyValuePairs(m[3], ",")
+ arg = m[4]
+ } else if m := commandPatternADO.FindStringSubmatch(line); m != nil {
+ command = m[1]
+ kvPairs = parseKeyValuePairs(m[3], ";")
+ arg = m[4]
+ } else {
+ return true
+ }
- if resumeCommand != "" && command != resumeCommand {
- return
- }
+ if resumeCommand != "" && command != resumeCommand {
+ return false
+ }
- switch command {
- case "set-env":
- rc.setEnv(ctx, kvPairs, arg)
- case "set-output":
- rc.setOutput(ctx, kvPairs, arg)
- case "add-path":
- rc.addPath(ctx, arg)
- case "debug":
- logger.Infof(" \U0001F4AC %s", line)
- case "warning":
- logger.Infof(" \U0001F6A7 %s", line)
- case "error":
- logger.Infof(" \U00002757 %s", line)
- case "add-mask":
- logger.Infof(" \U00002699 %s", line)
- case "stop-commands":
- resumeCommand = arg
- logger.Infof(" \U00002699 %s", line)
- case resumeCommand:
- resumeCommand = ""
- logger.Infof(" \U00002699 %s", line)
- default:
- logger.Infof(" \U00002753 %s", line)
- }
+ switch command {
+ case "set-env":
+ rc.setEnv(ctx, kvPairs, arg)
+ case "set-output":
+ rc.setOutput(ctx, kvPairs, arg)
+ case "add-path":
+ rc.addPath(ctx, arg)
+ case "debug":
+ logger.Infof(" \U0001F4AC %s", line)
+ case "warning":
+ logger.Infof(" \U0001F6A7 %s", line)
+ case "error":
+ logger.Infof(" \U00002757 %s", line)
+ case "add-mask":
+ logger.Infof(" \U00002699 %s", line)
+ case "stop-commands":
+ resumeCommand = arg
+ logger.Infof(" \U00002699 %s", line)
+ case resumeCommand:
+ resumeCommand = ""
+ logger.Infof(" \U00002699 %s", line)
+ default:
+ logger.Infof(" \U00002753 %s", line)
}
+
+ return false
}
}
@@ -71,9 +84,9 @@ func (rc *RunContext) addPath(ctx context.Context, arg string) {
rc.ExtraPath = append(rc.ExtraPath, arg)
}
-func parseKeyValuePairs(kvPairs string) map[string]string {
+func parseKeyValuePairs(kvPairs string, separator string) map[string]string {
rtn := make(map[string]string)
- kvPairList := strings.Split(kvPairs, ",")
+ kvPairList := strings.Split(kvPairs, separator)
for _, kvPair := range kvPairList {
kv := strings.Split(kvPair, "=")
if len(kv) == 2 {
diff --git a/pkg/runner/command_test.go b/pkg/runner/command_test.go
index 4279bc0..6abe527 100644
--- a/pkg/runner/command_test.go
+++ b/pkg/runner/command_test.go
@@ -60,3 +60,16 @@ func TestStopCommands(t *testing.T) {
handler("::set-env name=x::abcd\n")
assert.Equal("abcd", rc.Env["x"])
}
+
+func TestAddpathADO(t *testing.T) {
+ assert := assert.New(t)
+ ctx := context.Background()
+ rc := new(RunContext)
+ handler := rc.commandHandler(ctx)
+
+ handler("##[add-path]/zoo\n")
+ assert.Equal("/zoo", rc.ExtraPath[0])
+
+ handler("##[add-path]/boo\n")
+ assert.Equal("/boo", rc.ExtraPath[1])
+}
diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go
index cd302cb..a86a009 100644
--- a/pkg/runner/run_context.go
+++ b/pkg/runner/run_context.go
@@ -62,12 +62,13 @@ func (rc *RunContext) startJobContainer() common.Executor {
return func(ctx context.Context) error {
rawLogger := common.Logger(ctx).WithField("raw_output", true)
- logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) {
+ logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) bool {
if rc.Config.LogOutput {
rawLogger.Infof(s)
} else {
rawLogger.Debugf(s)
}
+ return true
})
common.Logger(ctx).Infof("\U0001f680 Start image=%s", image)
@@ -79,17 +80,12 @@ func (rc *RunContext) startJobContainer() common.Executor {
bindModifiers = ":delegated"
}
- hostWorkdir := os.Getenv("ACT_HOST_WORKDIR")
- if hostWorkdir == "" {
- hostWorkdir = rc.Config.Workdir
- }
- envList = append(envList, fmt.Sprintf("%s=%s", "ACT_HOST_WORKDIR", hostWorkdir))
-
- hostActionCache := os.Getenv("ACT_HOST_ACTIONCACHE")
+ hostActionCache := os.Getenv("ACT_HOST_ACTION_CACHE")
if hostActionCache == "" {
hostActionCache = rc.ActionCacheDir()
}
- envList = append(envList, fmt.Sprintf("%s=%s", "ACT_HOST_ACTIONCACHE", hostActionCache))
+ envList = append(envList, fmt.Sprintf("%s=%s", "ACT_HOST_ACTION_CACHE", hostActionCache))
+ envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/toolcache"))
rc.JobContainer = container.NewContainer(&container.NewContainerInput{
Cmd: nil,
@@ -99,11 +95,12 @@ func (rc *RunContext) startJobContainer() common.Executor {
Name: name,
Env: envList,
Mounts: map[string]string{
- name: "/github",
+ name: "/github",
+ "act-toolcache": "/toolcache",
},
Binds: []string{
- fmt.Sprintf("%s:%s%s", hostWorkdir, "/github/workspace", bindModifiers),
+ fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers),
fmt.Sprintf("%s:%s%s", hostActionCache, "/github/home/.cache/act", bindModifiers),
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
},
diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go
index 479998f..a78211c 100644
--- a/pkg/runner/step_context.go
+++ b/pkg/runner/step_context.go
@@ -133,12 +133,13 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
rc := sc.RunContext
step := sc.Step
rawLogger := common.Logger(ctx).WithField("raw_output", true)
- logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) {
+ logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) bool {
if rc.Config.LogOutput {
rawLogger.Infof(s)
} else {
rawLogger.Debugf(s)
}
+ return true
})
envList := make([]string, 0)
for k, v := range sc.Env {
@@ -157,17 +158,7 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
bindModifiers = ":delegated"
}
- hostWorkdir := os.Getenv("ACT_HOST_WORKDIR")
- if hostWorkdir == "" {
- hostWorkdir = rc.Config.Workdir
- }
- envList = append(envList, fmt.Sprintf("%s=%s", "ACT_HOST_WORKDIR", hostWorkdir))
-
- hostActionCache := os.Getenv("ACT_HOST_ACTIONCACHE")
- if hostActionCache == "" {
- hostActionCache = rc.ActionCacheDir()
- }
- envList = append(envList, fmt.Sprintf("%s=%s", "ACT_HOST_ACTIONCACHE", hostActionCache))
+ envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/toolcache"))
stepContainer := container.NewContainer(&container.NewContainerInput{
Cmd: cmd,
@@ -178,9 +169,10 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
Env: envList,
Mounts: map[string]string{
rc.jobContainerName(): "/github",
+ "act-toolcache": "/toolcache",
},
Binds: []string{
- fmt.Sprintf("%s:%s%s", hostWorkdir, "/github/workspace", bindModifiers),
+ fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers),
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
},
Stdout: logWriter,