From 6cde8f64dcc0f54619168b4f3883afccc5539a9d Mon Sep 17 00:00:00 2001 From: rockandska Date: Mon, 29 Mar 2021 06:32:45 +0200 Subject: [PATCH] use project dir instead of /github/workspace (#567) --- pkg/runner/run_context.go | 19 +++++++++---------- pkg/runner/step_context.go | 12 ++++++------ pkg/runner/testdata/basic/push.yml | 4 ++-- pkg/runner/testdata/workdir/push.yml | 6 +++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 90dba18..5ba176d 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -86,7 +86,7 @@ func (rc *RunContext) startJobContainer() common.Executor { fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"), } if rc.Config.BindWorkdir { - binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers)) + binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, rc.Config.Workdir, bindModifiers)) } if rc.Config.ContainerArchitecture == "" { @@ -96,12 +96,12 @@ func (rc *RunContext) startJobContainer() common.Executor { rc.JobContainer = container.NewContainer(&container.NewContainerInput{ Cmd: nil, Entrypoint: []string{"/usr/bin/tail", "-f", "/dev/null"}, - WorkingDir: "/github/workspace", + WorkingDir: rc.Config.Workdir, Image: image, Name: name, Env: envList, Mounts: map[string]string{ - name: "/github", + name: filepath.Dir(rc.Config.Workdir), "act-toolcache": "/toolcache", "act-actions": "/actions", }, @@ -118,7 +118,7 @@ func (rc *RunContext) startJobContainer() common.Executor { var copyToPath string if !rc.Config.BindWorkdir { copyToPath, copyWorkspace = rc.localCheckoutPath() - copyToPath = filepath.Join("/github/workspace", copyToPath) + copyToPath = filepath.Join(rc.Config.Workdir, copyToPath) } return common.NewPipelineExecutor( @@ -127,7 +127,7 @@ func (rc *RunContext) startJobContainer() common.Executor { rc.JobContainer.Create(), rc.JobContainer.Start(false), rc.JobContainer.CopyDir(copyToPath, rc.Config.Workdir+string(filepath.Separator)+".").IfBool(copyWorkspace), - rc.JobContainer.Copy("/github/", &container.FileEntry{ + rc.JobContainer.Copy(filepath.Dir(rc.Config.Workdir), &container.FileEntry{ Name: "workflow/event.json", Mode: 0644, Body: rc.EventJSON, @@ -449,14 +449,14 @@ func (rc *RunContext) getGithubContext() *githubContext { } ghc := &githubContext{ Event: make(map[string]interface{}), - EventPath: "/github/workflow/event.json", + EventPath: fmt.Sprintf("%s/%s", filepath.Dir(rc.Config.Workdir), "workflow/event.json"), Workflow: rc.Run.Workflow.Name, RunID: runID, RunNumber: runNumber, Actor: rc.Config.Actor, EventName: rc.Config.EventName, Token: token, - Workspace: "/github/workspace", + Workspace: rc.Config.Workdir, Action: rc.CurrentStep, } @@ -580,9 +580,8 @@ func withDefaultBranch(b string, event map[string]interface{}) map[string]interf func (rc *RunContext) withGithubEnv(env map[string]string) map[string]string { github := rc.getGithubContext() env["CI"] = "true" - env["HOME"] = "/github/home" - - env["GITHUB_ENV"] = "/github/workflow/envs.txt" + env["HOME"] = fmt.Sprintf("%s/%s", filepath.Dir(rc.Config.Workdir), "home") + env["GITHUB_ENV"] = fmt.Sprintf("%s/%s", filepath.Dir(rc.Config.Workdir), "workflow/envs.txt") env["GITHUB_WORKFLOW"] = github.Workflow env["GITHUB_RUN_ID"] = github.RunID env["GITHUB_RUN_NUMBER"] = github.RunNumber diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 137d384..d161dc6 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -160,7 +160,7 @@ func (sc *StepContext) setupShellCommand() common.Executor { } scriptName := fmt.Sprintf("workflow/%s", step.ID) log.Debugf("Wrote command '%s' to '%s'", run, scriptName) - containerPath := fmt.Sprintf("/github/%s", scriptName) + containerPath := fmt.Sprintf("%s/%s", filepath.Dir(rc.Config.Workdir), scriptName) if step.Shell == "" { step.Shell = rc.Run.Job().Defaults.Run.Shell @@ -169,7 +169,7 @@ func (sc *StepContext) setupShellCommand() common.Executor { step.Shell = rc.Run.Workflow.Defaults.Run.Shell } sc.Cmd = strings.Fields(strings.Replace(step.ShellCommand(), "{0}", containerPath, 1)) - return rc.JobContainer.Copy("/github/", &container.FileEntry{ + return rc.JobContainer.Copy(fmt.Sprintf("%s/", filepath.Dir(rc.Config.Workdir)), &container.FileEntry{ Name: scriptName, Mode: 0755, Body: script.String(), @@ -214,7 +214,7 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [ fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"), } if rc.Config.BindWorkdir { - binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers)) + binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, rc.Config.Workdir, bindModifiers)) } if rc.Config.ContainerArchitecture == "" { @@ -224,12 +224,12 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [ stepContainer := container.NewContainer(&container.NewContainerInput{ Cmd: cmd, Entrypoint: entrypoint, - WorkingDir: "/github/workspace", + WorkingDir: rc.Config.Workdir, Image: image, Name: createContainerName(rc.jobContainerName(), step.ID), Env: envList, Mounts: map[string]string{ - rc.jobContainerName(): "/github", + rc.jobContainerName(): filepath.Dir(rc.Config.Workdir), "act-toolcache": "/toolcache", "act-actions": "/actions", }, @@ -299,7 +299,7 @@ func (sc *StepContext) getContainerActionPaths(step *model.Step, actionDir strin containerActionDir := "." if step.Type() == model.StepTypeUsesActionLocal { actionName = getOsSafeRelativePath(actionDir, rc.Config.Workdir) - containerActionDir = "/github/workspace" + containerActionDir = rc.Config.Workdir } else if step.Type() == model.StepTypeUsesActionRemote { actionName = getOsSafeRelativePath(actionDir, rc.ActionCacheDir()) containerActionDir = "/actions" diff --git a/pkg/runner/testdata/basic/push.yml b/pkg/runner/testdata/basic/push.yml index 898517f..5c3a355 100644 --- a/pkg/runner/testdata/basic/push.yml +++ b/pkg/runner/testdata/basic/push.yml @@ -16,8 +16,8 @@ jobs: args: echo ${INPUT_SOMEKEY} | grep somevalue - run: ls - run: echo 'hello world' - - run: echo ${GITHUB_SHA} >> /github/sha.txt - - run: cat /github/sha.txt | grep ${GITHUB_SHA} + - run: echo ${GITHUB_SHA} >> $(dirname "${GITHUB_WORKSPACE}")/sha.txt + - run: cat $(dirname "${GITHUB_WORKSPACE}")/sha.txt | grep ${GITHUB_SHA} build: runs-on: ubuntu-latest needs: [check] diff --git a/pkg/runner/testdata/workdir/push.yml b/pkg/runner/testdata/workdir/push.yml index 9e6eaad..42214b1 100644 --- a/pkg/runner/testdata/workdir/push.yml +++ b/pkg/runner/testdata/workdir/push.yml @@ -6,12 +6,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: ls -alFt /github/workspace/workdir - - run: '[[ "$(pwd)" == "/github/workspace/workdir" ]]' + - run: ls -alFt "${GITHUB_WORKSPACE}/workdir" + - run: '[[ "$(pwd)" == "${GITHUB_WORKSPACE}/workdir" ]]' working-directory: workdir noworkdir: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: '[[ "$(pwd)" == "/github/workspace" ]]' + - run: '[[ "$(pwd)" == "${GITHUB_WORKSPACE}" ]]'