unit tests pass
This commit is contained in:
parent
88041afb87
commit
6c632946be
4 changed files with 66 additions and 17 deletions
2
.github/workflows/push.yml
vendored
2
.github/workflows/push.yml
vendored
|
@ -7,4 +7,4 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: ./.github/workflows/check
|
- uses: ./.github/workflows/check
|
||||||
#- uses: ./.github/workflows/integration
|
- uses: ./.github/workflows/integration
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/nektos/act/pkg/container"
|
"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)
|
common.Logger(ctx).Infof("\U0001f680 Start image=%s", image)
|
||||||
name := rc.jobContainerName()
|
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{
|
rc.JobContainer = container.NewContainer(&container.NewContainerInput{
|
||||||
Cmd: nil,
|
Cmd: nil,
|
||||||
Entrypoint: []string{"/usr/bin/tail", "-f", "/dev/null"},
|
Entrypoint: []string{"/usr/bin/tail", "-f", "/dev/null"},
|
||||||
WorkingDir: "/github/workspace",
|
WorkingDir: "/github/workspace",
|
||||||
Image: image,
|
Image: image,
|
||||||
Name: name,
|
Name: name,
|
||||||
|
Env: envList,
|
||||||
Mounts: map[string]string{
|
Mounts: map[string]string{
|
||||||
name: "/github",
|
name: "/github",
|
||||||
},
|
},
|
||||||
|
|
||||||
Binds: []string{
|
Binds: []string{
|
||||||
fmt.Sprintf("%s:%s", rc.Config.Workdir, "/github/workspace"),
|
fmt.Sprintf("%s:%s%s", hostWorkdir, "/github/workspace", bindModifiers),
|
||||||
fmt.Sprintf("%s:%s", rc.ActionDir(), "/github/home/.act"),
|
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"),
|
||||||
},
|
},
|
||||||
Stdout: logWriter,
|
Stdout: logWriter,
|
||||||
|
@ -118,8 +139,8 @@ func (rc *RunContext) stopJobContainer() common.Executor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionDir is for rc
|
// ActionCacheDir is for rc
|
||||||
func (rc *RunContext) ActionDir() string {
|
func (rc *RunContext) ActionCacheDir() string {
|
||||||
var xdgCache string
|
var xdgCache string
|
||||||
var ok bool
|
var ok bool
|
||||||
if xdgCache, ok = os.LookupEnv("XDG_CACHE_HOME"); !ok {
|
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_ID"] = github.RunID
|
||||||
env["GITHUB_RUN_NUMBER"] = github.RunNumber
|
env["GITHUB_RUN_NUMBER"] = github.RunNumber
|
||||||
env["GITHUB_ACTION"] = github.Action
|
env["GITHUB_ACTION"] = github.Action
|
||||||
|
env["GITHUB_ACTIONS"] = "true"
|
||||||
env["GITHUB_ACTOR"] = github.Actor
|
env["GITHUB_ACTOR"] = github.Actor
|
||||||
env["GITHUB_REPOSITORY"] = github.Repository
|
env["GITHUB_REPOSITORY"] = github.Repository
|
||||||
env["GITHUB_EVENT_NAME"] = github.EventName
|
env["GITHUB_EVENT_NAME"] = github.EventName
|
||||||
|
|
|
@ -3,6 +3,7 @@ package runner
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nektos/act/pkg/model"
|
"github.com/nektos/act/pkg/model"
|
||||||
|
@ -59,8 +60,11 @@ func TestRunEvent(t *testing.T) {
|
||||||
platforms := map[string]string{
|
platforms := map[string]string{
|
||||||
"ubuntu-latest": "node:12.6-buster-slim",
|
"ubuntu-latest": "node:12.6-buster-slim",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workdir, err := filepath.Abs("testdata")
|
||||||
|
assert.NilError(t, err, table.workflowPath)
|
||||||
runnerConfig := &Config{
|
runnerConfig := &Config{
|
||||||
Workdir: "testdata",
|
Workdir: workdir,
|
||||||
EventName: table.eventName,
|
EventName: table.eventName,
|
||||||
Platforms: platforms,
|
Platforms: platforms,
|
||||||
ReuseContainers: false,
|
ReuseContainers: false,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/nektos/act/pkg/common"
|
"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(
|
return common.NewPipelineExecutor(
|
||||||
common.NewGitCloneExecutor(common.NewGitCloneExecutorInput{
|
common.NewGitCloneExecutor(common.NewGitCloneExecutorInput{
|
||||||
URL: remoteAction.CloneURL(),
|
URL: remoteAction.CloneURL(),
|
||||||
|
@ -150,6 +151,24 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
|
||||||
for i, v := range entrypoint {
|
for i, v := range entrypoint {
|
||||||
entrypoint[i] = stepEE.Interpolate(v)
|
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{
|
stepContainer := container.NewContainer(&container.NewContainerInput{
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
Entrypoint: entrypoint,
|
Entrypoint: entrypoint,
|
||||||
|
@ -161,7 +180,7 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
|
||||||
rc.jobContainerName(): "/github",
|
rc.jobContainerName(): "/github",
|
||||||
},
|
},
|
||||||
Binds: []string{
|
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"),
|
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
|
||||||
},
|
},
|
||||||
Stdout: logWriter,
|
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 {
|
switch action.Runs.Using {
|
||||||
case model.ActionRunsUsingNode12:
|
case model.ActionRunsUsingNode12:
|
||||||
basePath := "."
|
return rc.execJobContainer([]string{"node", fmt.Sprintf("%s/%s/%s", containerActionDir, actionName, action.Runs.Main)}, sc.Env)(ctx)
|
||||||
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)
|
|
||||||
case model.ActionRunsUsingDocker:
|
case model.ActionRunsUsingDocker:
|
||||||
var prepImage common.Executor
|
var prepImage common.Executor
|
||||||
var image string
|
var image string
|
||||||
if strings.HasPrefix(action.Runs.Image, "docker://") {
|
if strings.HasPrefix(action.Runs.Image, "docker://") {
|
||||||
image = strings.TrimPrefix(action.Runs.Image, "docker://")
|
image = strings.TrimPrefix(action.Runs.Image, "docker://")
|
||||||
} else {
|
} else {
|
||||||
image = fmt.Sprintf("%s:%s", regexp.MustCompile("[^a-zA-Z0-9]").ReplaceAllString(step.Uses, "-"), "latest")
|
image = fmt.Sprintf("%s:%s", regexp.MustCompile("[^a-zA-Z0-9]").ReplaceAllString(actionName, "-"), "latest")
|
||||||
image = strings.TrimLeft(image, "-")
|
image = fmt.Sprintf("act-%s", strings.TrimLeft(image, "-"))
|
||||||
contextDir := filepath.Join(actionDir, action.Runs.Main)
|
contextDir := filepath.Join(actionDir, action.Runs.Main)
|
||||||
prepImage = container.NewDockerBuildExecutor(container.NewDockerBuildExecutorInput{
|
prepImage = container.NewDockerBuildExecutor(container.NewDockerBuildExecutorInput{
|
||||||
ContextDir: contextDir,
|
ContextDir: contextDir,
|
||||||
|
|
Loading…
Reference in a new issue