integration test

This commit is contained in:
Casey Lee 2020-02-24 12:48:12 -08:00
parent 6c632946be
commit 037e08a3a7
No known key found for this signature in database
GPG key ID: 1899120ECD0A1784
12 changed files with 94 additions and 73 deletions

View file

@ -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

View file

@ -1,4 +1,3 @@
#!/bin/sh
set -e
golangci-lint run
go test -cover -short ./...

View file

@ -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

View file

@ -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:

View file

@ -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
}

View file

@ -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
}
}
}

View file

@ -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)

View file

@ -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 {

View file

@ -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])
}

View file

@ -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"),
},

View file

@ -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,