integration test
This commit is contained in:
@@ -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]
|
||||
|
||||
if resumeCommand != "" && command != resumeCommand {
|
||||
return
|
||||
}
|
||||
|
||||
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 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 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)
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@@ -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])
|
||||
}
|
||||
|
@@ -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"),
|
||||
},
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user