use project dir instead of /github/workspace (#567)

This commit is contained in:
rockandska 2021-03-29 06:32:45 +02:00 committed by GitHub
parent 6c258cf40d
commit 6cde8f64dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 21 deletions

View file

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

View file

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

View file

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

View file

@ -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}" ]]'