unit tests pass

This commit is contained in:
Casey Lee 2020-02-24 10:56:49 -08:00
parent 88041afb87
commit 6c632946be
No known key found for this signature in database
GPG key ID: 1899120ECD0A1784
4 changed files with 66 additions and 17 deletions

View file

@ -7,4 +7,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: ./.github/workflows/check
#- uses: ./.github/workflows/integration
- uses: ./.github/workflows/integration

View file

@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"github.com/nektos/act/pkg/container"
@ -72,18 +73,38 @@ func (rc *RunContext) startJobContainer() common.Executor {
common.Logger(ctx).Infof("\U0001f680 Start image=%s", image)
name := rc.jobContainerName()
envList := make([]string, 0)
bindModifiers := ""
if runtime.GOOS == "darwin" {
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))
rc.JobContainer = container.NewContainer(&container.NewContainerInput{
Cmd: nil,
Entrypoint: []string{"/usr/bin/tail", "-f", "/dev/null"},
WorkingDir: "/github/workspace",
Image: image,
Name: name,
Env: envList,
Mounts: map[string]string{
name: "/github",
},
Binds: []string{
fmt.Sprintf("%s:%s", rc.Config.Workdir, "/github/workspace"),
fmt.Sprintf("%s:%s", rc.ActionDir(), "/github/home/.act"),
fmt.Sprintf("%s:%s%s", hostWorkdir, "/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"),
},
Stdout: logWriter,
@ -118,8 +139,8 @@ func (rc *RunContext) stopJobContainer() common.Executor {
}
}
// ActionDir is for rc
func (rc *RunContext) ActionDir() string {
// ActionCacheDir is for rc
func (rc *RunContext) ActionCacheDir() string {
var xdgCache string
var ok bool
if xdgCache, ok = os.LookupEnv("XDG_CACHE_HOME"); !ok {
@ -336,6 +357,7 @@ func (rc *RunContext) withGithubEnv(env map[string]string) map[string]string {
env["GITHUB_RUN_ID"] = github.RunID
env["GITHUB_RUN_NUMBER"] = github.RunNumber
env["GITHUB_ACTION"] = github.Action
env["GITHUB_ACTIONS"] = "true"
env["GITHUB_ACTOR"] = github.Actor
env["GITHUB_REPOSITORY"] = github.Repository
env["GITHUB_EVENT_NAME"] = github.EventName

View file

@ -3,6 +3,7 @@ package runner
import (
"context"
"fmt"
"path/filepath"
"testing"
"github.com/nektos/act/pkg/model"
@ -59,8 +60,11 @@ func TestRunEvent(t *testing.T) {
platforms := map[string]string{
"ubuntu-latest": "node:12.6-buster-slim",
}
workdir, err := filepath.Abs("testdata")
assert.NilError(t, err, table.workflowPath)
runnerConfig := &Config{
Workdir: "testdata",
Workdir: workdir,
EventName: table.eventName,
Platforms: platforms,
ReuseContainers: false,

View file

@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"github.com/nektos/act/pkg/common"
@ -64,7 +65,7 @@ func (sc *StepContext) Executor() common.Executor {
}
}
actionDir := rc.ActionDir()
actionDir := fmt.Sprintf("%s/%s", rc.ActionCacheDir(), remoteAction.Repo)
return common.NewPipelineExecutor(
common.NewGitCloneExecutor(common.NewGitCloneExecutorInput{
URL: remoteAction.CloneURL(),
@ -150,6 +151,24 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
for i, v := range entrypoint {
entrypoint[i] = stepEE.Interpolate(v)
}
bindModifiers := ""
if runtime.GOOS == "darwin" {
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))
stepContainer := container.NewContainer(&container.NewContainerInput{
Cmd: cmd,
Entrypoint: entrypoint,
@ -161,7 +180,7 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
rc.jobContainerName(): "/github",
},
Binds: []string{
fmt.Sprintf("%s:%s", rc.Config.Workdir, "/github/workspace"),
fmt.Sprintf("%s:%s%s", hostWorkdir, "/github/workspace", bindModifiers),
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
},
Stdout: logWriter,
@ -221,23 +240,27 @@ func (sc *StepContext) runAction(actionDir string) common.Executor {
}
}
actionName := ""
containerActionDir := "."
if strings.HasPrefix(actionDir, rc.Config.Workdir) {
actionName = strings.TrimPrefix(actionDir, rc.Config.Workdir)
containerActionDir = "/github/workspace"
} else if strings.HasPrefix(actionDir, rc.ActionCacheDir()) {
actionName = strings.TrimPrefix(actionDir, rc.ActionCacheDir())
containerActionDir = "/github/home/.cache/act"
}
switch action.Runs.Using {
case model.ActionRunsUsingNode12:
basePath := "."
if strings.HasPrefix(actionDir, rc.Config.Workdir) {
basePath = fmt.Sprintf("/github/workspace/%s", strings.TrimPrefix(actionDir, rc.Config.Workdir))
} else if strings.HasPrefix(actionDir, rc.ActionDir()) {
basePath = fmt.Sprintf("/github/home/.act/%s", strings.TrimPrefix(actionDir, rc.ActionDir()))
}
return rc.execJobContainer([]string{"node", fmt.Sprintf("%s/%s", basePath, action.Runs.Main)}, sc.Env)(ctx)
return rc.execJobContainer([]string{"node", fmt.Sprintf("%s/%s/%s", containerActionDir, actionName, action.Runs.Main)}, sc.Env)(ctx)
case model.ActionRunsUsingDocker:
var prepImage common.Executor
var image string
if strings.HasPrefix(action.Runs.Image, "docker://") {
image = strings.TrimPrefix(action.Runs.Image, "docker://")
} else {
image = fmt.Sprintf("%s:%s", regexp.MustCompile("[^a-zA-Z0-9]").ReplaceAllString(step.Uses, "-"), "latest")
image = strings.TrimLeft(image, "-")
image = fmt.Sprintf("%s:%s", regexp.MustCompile("[^a-zA-Z0-9]").ReplaceAllString(actionName, "-"), "latest")
image = fmt.Sprintf("act-%s", strings.TrimLeft(image, "-"))
contextDir := filepath.Join(actionDir, action.Runs.Main)
prepImage = container.NewDockerBuildExecutor(container.NewDockerBuildExecutorInput{
ContextDir: contextDir,