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
4 changed files with 19 additions and 18 deletions
pkg
|
@ -69,7 +69,7 @@ type Container interface {
|
||||||
Pull(forcePull bool) common.Executor
|
Pull(forcePull bool) common.Executor
|
||||||
Start(attach bool) common.Executor
|
Start(attach bool) common.Executor
|
||||||
Exec(command []string, env map[string]string) 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
|
Remove() common.Executor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +132,7 @@ func (cr *containerReference) Pull(forcePull bool) common.Executor {
|
||||||
Password: cr.input.Password,
|
Password: cr.input.Password,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *containerReference) Copy(destPath string, files ...*FileEntry) common.Executor {
|
func (cr *containerReference) Copy(destPath string, files ...*FileEntry) common.Executor {
|
||||||
return common.NewPipelineExecutor(
|
return common.NewPipelineExecutor(
|
||||||
cr.connect(),
|
cr.connect(),
|
||||||
|
@ -150,8 +151,8 @@ func (cr *containerReference) CopyDir(destPath string, srcPath string, useGitIgn
|
||||||
).IfNot(common.Dryrun)
|
).IfNot(common.Dryrun)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *containerReference) UpdateFromGithubEnv(env *map[string]string) common.Executor {
|
func (cr *containerReference) UpdateFromEnv(srcPath string, env *map[string]string) common.Executor {
|
||||||
return cr.extractGithubEnv(env).IfNot(common.Dryrun)
|
return cr.extractEnv(srcPath, env).IfNot(common.Dryrun)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *containerReference) Exec(command []string, env map[string]string) common.Executor {
|
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),
|
cr.exec(command, env),
|
||||||
).IfNot(common.Dryrun)
|
).IfNot(common.Dryrun)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *containerReference) Remove() common.Executor {
|
func (cr *containerReference) Remove() common.Executor {
|
||||||
return common.NewPipelineExecutor(
|
return common.NewPipelineExecutor(
|
||||||
cr.connect(),
|
cr.connect(),
|
||||||
|
@ -328,7 +330,7 @@ func (cr *containerReference) create() common.Executor {
|
||||||
|
|
||||||
var singleLineEnvPattern, mulitiLineEnvPattern *regexp.Regexp
|
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 {
|
if singleLineEnvPattern == nil {
|
||||||
singleLineEnvPattern = regexp.MustCompile("^([^=]+)=([^=]+)$")
|
singleLineEnvPattern = regexp.MustCompile("^([^=]+)=([^=]+)$")
|
||||||
mulitiLineEnvPattern = regexp.MustCompile(`^([^<]+)<<(\w+)$`)
|
mulitiLineEnvPattern = regexp.MustCompile(`^([^<]+)<<(\w+)$`)
|
||||||
|
@ -336,11 +338,11 @@ func (cr *containerReference) extractGithubEnv(env *map[string]string) common.Ex
|
||||||
|
|
||||||
localEnv := *env
|
localEnv := *env
|
||||||
return func(ctx context.Context) error {
|
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 {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
reader := tar.NewReader(githubEnvTar)
|
reader := tar.NewReader(envTar)
|
||||||
_, err = reader.Next()
|
_, err = reader.Next()
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return errors.WithStack(err)
|
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
|
//Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17
|
||||||
switch s.Shell {
|
switch s.Shell {
|
||||||
case "", "bash":
|
case "", "bash":
|
||||||
shellCommand = "bash --login --noprofile --norc -e -o pipefail {0}"
|
shellCommand = "bash --noprofile --norc -e -o pipefail {0}"
|
||||||
case "pwsh":
|
case "pwsh":
|
||||||
shellCommand = "pwsh -command . '{0}'"
|
shellCommand = "pwsh -command . '{0}'"
|
||||||
case "python":
|
case "python":
|
||||||
shellCommand = "python {0}"
|
shellCommand = "python {0}"
|
||||||
case "sh":
|
case "sh":
|
||||||
shellCommand = "sh -l -e -c {0}"
|
shellCommand = "sh -e -c {0}"
|
||||||
case "cmd":
|
case "cmd":
|
||||||
shellCommand = "%ComSpec% /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
|
shellCommand = "%ComSpec% /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
|
||||||
case "powershell":
|
case "powershell":
|
||||||
|
|
|
@ -144,8 +144,9 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
||||||
rc.stopJobContainer(),
|
rc.stopJobContainer(),
|
||||||
rc.JobContainer.Create(),
|
rc.JobContainer.Create(),
|
||||||
rc.JobContainer.Start(false),
|
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.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",
|
Name: "workflow/event.json",
|
||||||
Mode: 0644,
|
Mode: 0644,
|
||||||
Body: rc.EventJSON,
|
Body: rc.EventJSON,
|
||||||
|
@ -153,10 +154,6 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
||||||
Name: "workflow/envs.txt",
|
Name: "workflow/envs.txt",
|
||||||
Mode: 0644,
|
Mode: 0644,
|
||||||
Body: "",
|
Body: "",
|
||||||
}, &container.FileEntry{
|
|
||||||
Name: "home/.act",
|
|
||||||
Mode: 0644,
|
|
||||||
Body: "",
|
|
||||||
}),
|
}),
|
||||||
)(ctx)
|
)(ctx)
|
||||||
}
|
}
|
||||||
|
@ -475,17 +472,20 @@ func (rc *RunContext) getGithubContext() *githubContext {
|
||||||
if !ok {
|
if !ok {
|
||||||
token = os.Getenv("GITHUB_TOKEN")
|
token = os.Getenv("GITHUB_TOKEN")
|
||||||
}
|
}
|
||||||
|
|
||||||
runID := rc.Config.Env["GITHUB_RUN_ID"]
|
runID := rc.Config.Env["GITHUB_RUN_ID"]
|
||||||
if runID == "" {
|
if runID == "" {
|
||||||
runID = "1"
|
runID = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
runNumber := rc.Config.Env["GITHUB_RUN_NUMBER"]
|
runNumber := rc.Config.Env["GITHUB_RUN_NUMBER"]
|
||||||
if runNumber == "" {
|
if runNumber == "" {
|
||||||
runNumber = "1"
|
runNumber = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
ghc := &githubContext{
|
ghc := &githubContext{
|
||||||
Event: make(map[string]interface{}),
|
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,
|
Workflow: rc.Run.Workflow.Name,
|
||||||
RunID: runID,
|
RunID: runID,
|
||||||
RunNumber: runNumber,
|
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 {
|
func (rc *RunContext) withGithubEnv(env map[string]string) map[string]string {
|
||||||
github := rc.getGithubContext()
|
github := rc.getGithubContext()
|
||||||
env["CI"] = "true"
|
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_WORKFLOW"] = github.Workflow
|
||||||
env["GITHUB_RUN_ID"] = github.RunID
|
env["GITHUB_RUN_ID"] = github.RunID
|
||||||
env["GITHUB_RUN_NUMBER"] = github.RunNumber
|
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) {
|
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(rc.ExtraPath, `:`)
|
||||||
env["PATH"] = strings.Join(s, `:`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.Env = rc.withGithubEnv(env)
|
sc.Env = rc.withGithubEnv(env)
|
||||||
|
@ -131,7 +130,7 @@ func (sc *StepContext) setupEnv(ctx context.Context) (ExpressionEvaluator, error
|
||||||
rc := sc.RunContext
|
rc := sc.RunContext
|
||||||
sc.Env = sc.mergeEnv()
|
sc.Env = sc.mergeEnv()
|
||||||
if sc.Env != nil {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue