support custom shell
Signed-off-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
parent
532af98aef
commit
4e046e1ec0
3 changed files with 54 additions and 12 deletions
5
.github/workflows/basic.yml
vendored
5
.github/workflows/basic.yml
vendored
|
@ -2,6 +2,10 @@ name: basic
|
||||||
on: push
|
on: push
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
action:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
|
@ -12,6 +16,7 @@ jobs:
|
||||||
- run: env
|
- run: env
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build]
|
||||||
steps:
|
steps:
|
||||||
- run: cp $GITHUB_EVENT_PATH $HOME/foo.json
|
- run: cp $GITHUB_EVENT_PATH $HOME/foo.json
|
||||||
- run: ls $HOME
|
- run: ls $HOME
|
||||||
|
|
|
@ -10,6 +10,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"
|
||||||
|
@ -105,8 +106,7 @@ func (rc *RunContext) Executor() common.Executor {
|
||||||
// read action.yaml
|
// read action.yaml
|
||||||
// if runs.using == node12, start node12 container and run `main`
|
// if runs.using == node12, start node12 container and run `main`
|
||||||
// if runs.using == docker, pull `image` and run
|
// if runs.using == docker, pull `image` and run
|
||||||
// set inputs as env
|
// caputre output/commands
|
||||||
// caputre output
|
|
||||||
} else {
|
} else {
|
||||||
stepExecutor = common.NewErrorExecutor(fmt.Errorf("Unable to determine how to run job:%s step:%+v", rc.Run, step))
|
stepExecutor = common.NewErrorExecutor(fmt.Errorf("Unable to determine how to run job:%s step:%+v", rc.Run, step))
|
||||||
}
|
}
|
||||||
|
@ -125,13 +125,13 @@ func (rc *RunContext) setupContainerSpec(step *model.Step, containerSpec *model.
|
||||||
containerSpec.Image = step.Uses
|
containerSpec.Image = step.Uses
|
||||||
} else if job.Container != nil {
|
} else if job.Container != nil {
|
||||||
containerSpec.Image = job.Container.Image
|
containerSpec.Image = job.Container.Image
|
||||||
containerSpec.Args = step.Run
|
containerSpec.Args = rc.shellCommand(step.Shell, step.Run)
|
||||||
containerSpec.Ports = job.Container.Ports
|
containerSpec.Ports = job.Container.Ports
|
||||||
containerSpec.Volumes = job.Container.Volumes
|
containerSpec.Volumes = job.Container.Volumes
|
||||||
containerSpec.Options = job.Container.Options
|
containerSpec.Options = job.Container.Options
|
||||||
} else if step.Run != "" {
|
} else if step.Run != "" {
|
||||||
containerSpec.Image = platformImage(job.RunsOn)
|
containerSpec.Image = platformImage(job.RunsOn)
|
||||||
containerSpec.Args = step.Run
|
containerSpec.Args = rc.shellCommand(step.Shell, step.Run)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("Unable to setup container for %s", step)
|
return fmt.Errorf("Unable to setup container for %s", step)
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,44 @@ func (rc *RunContext) setupContainerSpec(step *model.Step, containerSpec *model.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *RunContext) shellCommand(shell string, run string) string {
|
||||||
|
shellCommand := ""
|
||||||
|
|
||||||
|
switch shell {
|
||||||
|
case "", "bash":
|
||||||
|
shellCommand = "bash --noprofile --norc -eo pipefail {0}"
|
||||||
|
case "pwsh":
|
||||||
|
shellCommand = "pwsh -command \"& '{0}'\""
|
||||||
|
case "python":
|
||||||
|
shellCommand = "python {0}"
|
||||||
|
case "sh":
|
||||||
|
shellCommand = "sh -e -c {0}"
|
||||||
|
case "cmd":
|
||||||
|
shellCommand = "%ComSpec% /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
|
||||||
|
case "powershell":
|
||||||
|
shellCommand = "powershell -command \"& '{0}'\""
|
||||||
|
default:
|
||||||
|
shellCommand = shell
|
||||||
|
}
|
||||||
|
|
||||||
|
tempScript, err := ioutil.TempFile(rc.Tempdir, ".temp-script-")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Unable to create temp script %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := tempScript.Write([]byte(run)); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Debugf("Wrote command '%s' to '%s'", run, tempScript.Name())
|
||||||
|
if err := tempScript.Close(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
containerPath := fmt.Sprintf("/github/home/%s", filepath.Base(tempScript.Name()))
|
||||||
|
cmd := strings.Replace(shellCommand, "{0}", containerPath, 1)
|
||||||
|
log.Debugf("about to run %s", cmd)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
func platformImage(platform string) string {
|
func platformImage(platform string) string {
|
||||||
switch platform {
|
switch platform {
|
||||||
case "ubuntu-latest", "ubuntu-18.04":
|
case "ubuntu-latest", "ubuntu-18.04":
|
||||||
|
@ -165,7 +203,11 @@ func mergeMaps(maps ...map[string]string) map[string]string {
|
||||||
func (rc *RunContext) setupTempDir() common.Executor {
|
func (rc *RunContext) setupTempDir() common.Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
var err error
|
var err error
|
||||||
rc.Tempdir, err = ioutil.TempDir("", "act-")
|
tempBase := ""
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
tempBase = "/tmp"
|
||||||
|
}
|
||||||
|
rc.Tempdir, err = ioutil.TempDir(tempBase, "act-")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,11 +234,7 @@ func (rc *RunContext) runContainer(containerSpec *model.ContainerSpec) common.Ex
|
||||||
}
|
}
|
||||||
var cmd, entrypoint []string
|
var cmd, entrypoint []string
|
||||||
if containerSpec.Args != "" {
|
if containerSpec.Args != "" {
|
||||||
cmd = []string{
|
cmd = strings.Fields(containerSpec.Args)
|
||||||
"/bin/sh",
|
|
||||||
"-c",
|
|
||||||
containerSpec.Args,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if containerSpec.Entrypoint != "" {
|
if containerSpec.Entrypoint != "" {
|
||||||
entrypoint = strings.Fields(containerSpec.Entrypoint)
|
entrypoint = strings.Fields(containerSpec.Entrypoint)
|
||||||
|
|
|
@ -9,8 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGraphEvent(t *testing.T) {
|
func TestGraphEvent(t *testing.T) {
|
||||||
runnerConfig := &RunnerConfig{
|
runnerConfig := &Config{
|
||||||
Ctx: context.Background(),
|
|
||||||
WorkflowPath: "multi.workflow",
|
WorkflowPath: "multi.workflow",
|
||||||
WorkingDir: "testdata",
|
WorkingDir: "testdata",
|
||||||
EventName: "push",
|
EventName: "push",
|
||||||
|
|
Loading…
Reference in a new issue