integration test
This commit is contained in:
parent
6c632946be
commit
037e08a3a7
12 changed files with 94 additions and 73 deletions
|
@ -1,5 +1,5 @@
|
||||||
name: Check
|
name: Lint
|
||||||
description: Run static analysis and unit tests
|
description: Run static analysis
|
||||||
branding:
|
branding:
|
||||||
icon: check-circle
|
icon: check-circle
|
||||||
color: green
|
color: green
|
|
@ -1,4 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
golangci-lint run
|
golangci-lint run
|
||||||
go test -cover -short ./...
|
|
9
.github/workflows/push.yml
vendored
9
.github/workflows/push.yml
vendored
|
@ -6,5 +6,10 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: ./.github/workflows/check
|
- uses: ./.github/workflows/lint
|
||||||
- uses: ./.github/workflows/integration
|
- uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.13
|
||||||
|
- run: go test -cover ./...
|
||||||
|
env:
|
||||||
|
CGO_ENABLED: 0
|
||||||
|
|
2
.github/workflows/tag.yml
vendored
2
.github/workflows/tag.yml
vendored
|
@ -9,8 +9,6 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: ./.github/workflows/check
|
|
||||||
#- uses: ./.github/workflows/integration
|
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v1
|
uses: goreleaser/goreleaser-action@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -254,7 +254,7 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor {
|
||||||
Force: true,
|
Force: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Unable to checkout %s: %v", refName, err)
|
logger.Errorf("Unable to checkout %s: %v", *hash, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// LineHandler is a callback function for handling a line
|
// LineHandler is a callback function for handling a line
|
||||||
type LineHandler func(line string)
|
type LineHandler func(line string) bool
|
||||||
|
|
||||||
type lineWriter struct {
|
type lineWriter struct {
|
||||||
buffer bytes.Buffer
|
buffer bytes.Buffer
|
||||||
|
@ -42,6 +42,9 @@ func (lw *lineWriter) Write(p []byte) (n int, err error) {
|
||||||
|
|
||||||
func (lw *lineWriter) handleLine(line string) {
|
func (lw *lineWriter) handleLine(line string) {
|
||||||
for _, h := range lw.handlers {
|
for _, h := range lw.handlers {
|
||||||
h(line)
|
ok := h(line)
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,9 @@ import (
|
||||||
|
|
||||||
func TestLineWriter(t *testing.T) {
|
func TestLineWriter(t *testing.T) {
|
||||||
lines := make([]string, 0)
|
lines := make([]string, 0)
|
||||||
lineHandler := func(s string) {
|
lineHandler := func(s string) bool {
|
||||||
lines = append(lines, s)
|
lines = append(lines, s)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
lineWriter := NewLineWriter(lineHandler)
|
lineWriter := NewLineWriter(lineHandler)
|
||||||
|
|
|
@ -8,50 +8,63 @@ import (
|
||||||
"github.com/nektos/act/pkg/common"
|
"github.com/nektos/act/pkg/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var commandPattern *regexp.Regexp
|
var commandPatternGA *regexp.Regexp
|
||||||
|
var commandPatternADO *regexp.Regexp
|
||||||
|
|
||||||
func init() {
|
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 {
|
func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
|
||||||
logger := common.Logger(ctx)
|
logger := common.Logger(ctx)
|
||||||
resumeCommand := ""
|
resumeCommand := ""
|
||||||
return func(line string) {
|
return func(line string) bool {
|
||||||
if m := commandPattern.FindStringSubmatch(line); m != nil {
|
var command string
|
||||||
command := m[1]
|
var kvPairs map[string]string
|
||||||
kvPairs := parseKeyValuePairs(m[3])
|
var arg string
|
||||||
arg := m[4]
|
if m := commandPatternGA.FindStringSubmatch(line); m != nil {
|
||||||
|
command = m[1]
|
||||||
if resumeCommand != "" && command != resumeCommand {
|
kvPairs = parseKeyValuePairs(m[3], ",")
|
||||||
return
|
arg = m[4]
|
||||||
}
|
} else if m := commandPatternADO.FindStringSubmatch(line); m != nil {
|
||||||
|
command = m[1]
|
||||||
switch command {
|
kvPairs = parseKeyValuePairs(m[3], ";")
|
||||||
case "set-env":
|
arg = m[4]
|
||||||
rc.setEnv(ctx, kvPairs, arg)
|
} else {
|
||||||
case "set-output":
|
return true
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
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)
|
rtn := make(map[string]string)
|
||||||
kvPairList := strings.Split(kvPairs, ",")
|
kvPairList := strings.Split(kvPairs, separator)
|
||||||
for _, kvPair := range kvPairList {
|
for _, kvPair := range kvPairList {
|
||||||
kv := strings.Split(kvPair, "=")
|
kv := strings.Split(kvPair, "=")
|
||||||
if len(kv) == 2 {
|
if len(kv) == 2 {
|
||||||
|
|
|
@ -60,3 +60,16 @@ func TestStopCommands(t *testing.T) {
|
||||||
handler("::set-env name=x::abcd\n")
|
handler("::set-env name=x::abcd\n")
|
||||||
assert.Equal("abcd", rc.Env["x"])
|
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 {
|
return func(ctx context.Context) error {
|
||||||
rawLogger := common.Logger(ctx).WithField("raw_output", true)
|
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 {
|
if rc.Config.LogOutput {
|
||||||
rawLogger.Infof(s)
|
rawLogger.Infof(s)
|
||||||
} else {
|
} else {
|
||||||
rawLogger.Debugf(s)
|
rawLogger.Debugf(s)
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
common.Logger(ctx).Infof("\U0001f680 Start image=%s", image)
|
common.Logger(ctx).Infof("\U0001f680 Start image=%s", image)
|
||||||
|
@ -79,17 +80,12 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
||||||
bindModifiers = ":delegated"
|
bindModifiers = ":delegated"
|
||||||
}
|
}
|
||||||
|
|
||||||
hostWorkdir := os.Getenv("ACT_HOST_WORKDIR")
|
hostActionCache := os.Getenv("ACT_HOST_ACTION_CACHE")
|
||||||
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 == "" {
|
if hostActionCache == "" {
|
||||||
hostActionCache = rc.ActionCacheDir()
|
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{
|
rc.JobContainer = container.NewContainer(&container.NewContainerInput{
|
||||||
Cmd: nil,
|
Cmd: nil,
|
||||||
|
@ -99,11 +95,12 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
||||||
Name: name,
|
Name: name,
|
||||||
Env: envList,
|
Env: envList,
|
||||||
Mounts: map[string]string{
|
Mounts: map[string]string{
|
||||||
name: "/github",
|
name: "/github",
|
||||||
|
"act-toolcache": "/toolcache",
|
||||||
},
|
},
|
||||||
|
|
||||||
Binds: []string{
|
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%s", hostActionCache, "/github/home/.cache/act", bindModifiers),
|
||||||
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
|
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
|
rc := sc.RunContext
|
||||||
step := sc.Step
|
step := sc.Step
|
||||||
rawLogger := common.Logger(ctx).WithField("raw_output", true)
|
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 {
|
if rc.Config.LogOutput {
|
||||||
rawLogger.Infof(s)
|
rawLogger.Infof(s)
|
||||||
} else {
|
} else {
|
||||||
rawLogger.Debugf(s)
|
rawLogger.Debugf(s)
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
envList := make([]string, 0)
|
envList := make([]string, 0)
|
||||||
for k, v := range sc.Env {
|
for k, v := range sc.Env {
|
||||||
|
@ -157,17 +158,7 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
|
||||||
bindModifiers = ":delegated"
|
bindModifiers = ":delegated"
|
||||||
}
|
}
|
||||||
|
|
||||||
hostWorkdir := os.Getenv("ACT_HOST_WORKDIR")
|
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/toolcache"))
|
||||||
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))
|
|
||||||
|
|
||||||
stepContainer := container.NewContainer(&container.NewContainerInput{
|
stepContainer := container.NewContainer(&container.NewContainerInput{
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
|
@ -178,9 +169,10 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
|
||||||
Env: envList,
|
Env: envList,
|
||||||
Mounts: map[string]string{
|
Mounts: map[string]string{
|
||||||
rc.jobContainerName(): "/github",
|
rc.jobContainerName(): "/github",
|
||||||
|
"act-toolcache": "/toolcache",
|
||||||
},
|
},
|
||||||
Binds: []string{
|
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"),
|
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
|
||||||
},
|
},
|
||||||
Stdout: logWriter,
|
Stdout: logWriter,
|
||||||
|
|
Loading…
Reference in a new issue