Fix environment variables and move `envs.txt`/`event.json` to fixed location (#667)
* fix: environment variables sourcing from `/etc/environment` * fix: move `envs.txt` & `event.json` to `/tmp/` Since #635 `envs.txt` is not copying properly when running `act` in WSL2 Moving it to fixed location resolves that.
This commit is contained in:
parent
aba4fec0ee
commit
8153dc92e5
|
@ -69,7 +69,7 @@ type Container interface {
|
|||
Pull(forcePull bool) common.Executor
|
||||
Start(attach bool) common.Executor
|
||||
Exec(command []string, env map[string]string) common.Executor
|
||||
UpdateFromGithubEnv(env *map[string]string) common.Executor
|
||||
UpdateFromEnv(srcPath string, env *map[string]string) common.Executor
|
||||
Remove() common.Executor
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,7 @@ func (cr *containerReference) Pull(forcePull bool) common.Executor {
|
|||
Password: cr.input.Password,
|
||||
})
|
||||
}
|
||||
|
||||
func (cr *containerReference) Copy(destPath string, files ...*FileEntry) common.Executor {
|
||||
return common.NewPipelineExecutor(
|
||||
cr.connect(),
|
||||
|
@ -150,8 +151,8 @@ func (cr *containerReference) CopyDir(destPath string, srcPath string, useGitIgn
|
|||
).IfNot(common.Dryrun)
|
||||
}
|
||||
|
||||
func (cr *containerReference) UpdateFromGithubEnv(env *map[string]string) common.Executor {
|
||||
return cr.extractGithubEnv(env).IfNot(common.Dryrun)
|
||||
func (cr *containerReference) UpdateFromEnv(srcPath string, env *map[string]string) common.Executor {
|
||||
return cr.extractEnv(srcPath, env).IfNot(common.Dryrun)
|
||||
}
|
||||
|
||||
func (cr *containerReference) Exec(command []string, env map[string]string) common.Executor {
|
||||
|
@ -161,6 +162,7 @@ func (cr *containerReference) Exec(command []string, env map[string]string) comm
|
|||
cr.exec(command, env),
|
||||
).IfNot(common.Dryrun)
|
||||
}
|
||||
|
||||
func (cr *containerReference) Remove() common.Executor {
|
||||
return common.NewPipelineExecutor(
|
||||
cr.connect(),
|
||||
|
@ -328,7 +330,7 @@ func (cr *containerReference) create() common.Executor {
|
|||
|
||||
var singleLineEnvPattern, mulitiLineEnvPattern *regexp.Regexp
|
||||
|
||||
func (cr *containerReference) extractGithubEnv(env *map[string]string) common.Executor {
|
||||
func (cr *containerReference) extractEnv(srcPath string, env *map[string]string) common.Executor {
|
||||
if singleLineEnvPattern == nil {
|
||||
singleLineEnvPattern = regexp.MustCompile("^([^=]+)=([^=]+)$")
|
||||
mulitiLineEnvPattern = regexp.MustCompile(`^([^<]+)<<(\w+)$`)
|
||||
|
@ -336,11 +338,11 @@ func (cr *containerReference) extractGithubEnv(env *map[string]string) common.Ex
|
|||
|
||||
localEnv := *env
|
||||
return func(ctx context.Context) error {
|
||||
githubEnvTar, _, err := cr.cli.CopyFromContainer(ctx, cr.id, localEnv["GITHUB_ENV"])
|
||||
envTar, _, err := cr.cli.CopyFromContainer(ctx, cr.id, srcPath)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
reader := tar.NewReader(githubEnvTar)
|
||||
reader := tar.NewReader(envTar)
|
||||
_, err = reader.Next()
|
||||
if err != nil && err != io.EOF {
|
||||
return errors.WithStack(err)
|
||||
|
|
|
@ -256,13 +256,13 @@ func (s *Step) ShellCommand() string {
|
|||
//Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17
|
||||
switch s.Shell {
|
||||
case "", "bash":
|
||||
shellCommand = "bash --login --noprofile --norc -e -o pipefail {0}"
|
||||
shellCommand = "bash --noprofile --norc -e -o pipefail {0}"
|
||||
case "pwsh":
|
||||
shellCommand = "pwsh -command . '{0}'"
|
||||
case "python":
|
||||
shellCommand = "python {0}"
|
||||
case "sh":
|
||||
shellCommand = "sh -l -e -c {0}"
|
||||
shellCommand = "sh -e -c {0}"
|
||||
case "cmd":
|
||||
shellCommand = "%ComSpec% /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
|
||||
case "powershell":
|
||||
|
|
|
@ -144,8 +144,9 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||
rc.stopJobContainer(),
|
||||
rc.JobContainer.Create(),
|
||||
rc.JobContainer.Start(false),
|
||||
rc.JobContainer.UpdateFromEnv("/etc/environment", &rc.Env),
|
||||
rc.JobContainer.CopyDir(copyToPath, rc.Config.Workdir+string(filepath.Separator)+".", rc.Config.UseGitIgnore).IfBool(copyWorkspace),
|
||||
rc.JobContainer.Copy(rc.Config.ContainerWorkdir(), &container.FileEntry{
|
||||
rc.JobContainer.Copy("/tmp/", &container.FileEntry{
|
||||
Name: "workflow/event.json",
|
||||
Mode: 0644,
|
||||
Body: rc.EventJSON,
|
||||
|
@ -153,10 +154,6 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||
Name: "workflow/envs.txt",
|
||||
Mode: 0644,
|
||||
Body: "",
|
||||
}, &container.FileEntry{
|
||||
Name: "home/.act",
|
||||
Mode: 0644,
|
||||
Body: "",
|
||||
}),
|
||||
)(ctx)
|
||||
}
|
||||
|
@ -475,17 +472,20 @@ func (rc *RunContext) getGithubContext() *githubContext {
|
|||
if !ok {
|
||||
token = os.Getenv("GITHUB_TOKEN")
|
||||
}
|
||||
|
||||
runID := rc.Config.Env["GITHUB_RUN_ID"]
|
||||
if runID == "" {
|
||||
runID = "1"
|
||||
}
|
||||
|
||||
runNumber := rc.Config.Env["GITHUB_RUN_NUMBER"]
|
||||
if runNumber == "" {
|
||||
runNumber = "1"
|
||||
}
|
||||
|
||||
ghc := &githubContext{
|
||||
Event: make(map[string]interface{}),
|
||||
EventPath: fmt.Sprintf("%s/%s", rc.Config.ContainerWorkdir(), "workflow/event.json"),
|
||||
EventPath: "/tmp/workflow/event.json",
|
||||
Workflow: rc.Run.Workflow.Name,
|
||||
RunID: runID,
|
||||
RunNumber: runNumber,
|
||||
|
@ -627,7 +627,7 @@ 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["GITHUB_ENV"] = fmt.Sprintf("%s/%s", rc.Config.ContainerWorkdir(), "workflow/envs.txt")
|
||||
env["GITHUB_ENV"] = "/tmp/workflow/envs.txt"
|
||||
env["GITHUB_WORKFLOW"] = github.Workflow
|
||||
env["GITHUB_RUN_ID"] = github.RunID
|
||||
env["GITHUB_RUN_NUMBER"] = github.RunNumber
|
||||
|
|
|
@ -113,8 +113,7 @@ func (sc *StepContext) mergeEnv() map[string]string {
|
|||
}
|
||||
|
||||
if (rc.ExtraPath != nil) && (len(rc.ExtraPath) > 0) {
|
||||
s := append(rc.ExtraPath, `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`)
|
||||
env["PATH"] = strings.Join(s, `:`)
|
||||
env["PATH"] = strings.Join(rc.ExtraPath, `:`)
|
||||
}
|
||||
|
||||
sc.Env = rc.withGithubEnv(env)
|
||||
|
@ -131,7 +130,7 @@ func (sc *StepContext) setupEnv(ctx context.Context) (ExpressionEvaluator, error
|
|||
rc := sc.RunContext
|
||||
sc.Env = sc.mergeEnv()
|
||||
if sc.Env != nil {
|
||||
err := rc.JobContainer.UpdateFromGithubEnv(&sc.Env)(ctx)
|
||||
err := rc.JobContainer.UpdateFromEnv(sc.Env["GITHUB_ENV"], &sc.Env)(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue