diff --git a/.goreleaser.yml b/.goreleaser.yml index d1ba517..7d011d7 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -5,7 +5,7 @@ builds: goos: - darwin - linux - - windows + #- windows goarch: - amd64 - 386 @@ -13,23 +13,23 @@ checksum: name_template: 'checksums.txt' snapshot: name_template: "{{ .Env.SNAPSHOT_VERSION }}" -archive: - name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}' - replacements: - darwin: Darwin - linux: Linux - windows: Windows - 386: i386 - amd64: x86_64 - format_overrides: - - goos: windows - format: zip -brew: - github: - owner: nektos - name: homebrew-tap - folder: Formula - homepage: https://github.com/nektos/act - description: Run GitHub Actions locally - test: | - system "#{bin}/act --version" +archives: + - name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}' + replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 + format_overrides: + - goos: windows + format: zip +brews: + - github: + owner: nektos + name: homebrew-tap + folder: Formula + homepage: https://github.com/nektos/act + description: Run GitHub Actions locally + test: | + system "#{bin}/act --version" diff --git a/cmd/input.go b/cmd/input.go index 22b9afa..cfb9134 100644 --- a/cmd/input.go +++ b/cmd/input.go @@ -12,6 +12,7 @@ type Input struct { eventPath string reuseContainers bool secrets []string + platforms []string dryrun bool forcePull bool logOutput bool diff --git a/cmd/platforms.go b/cmd/platforms.go new file mode 100644 index 0000000..46d45b1 --- /dev/null +++ b/cmd/platforms.go @@ -0,0 +1,25 @@ +package cmd + +import ( + "strings" +) + +func (i *Input) newPlatforms() map[string]string { + platforms := map[string]string{ + "ubuntu-latest": "ubuntu:18.04", + "ubuntu-18.04": "ubuntu:18.04", + "ubuntu-16.04": "ubuntu:16.04", + "windows-latest": "", + "windows-2019": "", + "macos-latest": "", + "macos-10.15": "", + } + + for _, p := range i.platforms { + pParts := strings.Split(p, "=") + if len(pParts) == 2 { + platforms[pParts[0]] = pParts[1] + } + } + return platforms +} diff --git a/cmd/root.go b/cmd/root.go index cf1d2f7..484cb39 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,6 +31,7 @@ func Execute(ctx context.Context, version string) { rootCmd.Flags().BoolP("list", "l", false, "list workflows") rootCmd.Flags().StringP("job", "j", "", "run job") rootCmd.Flags().StringArrayVarP(&input.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)") + rootCmd.Flags().StringArrayVarP(&input.platforms, "platform", "P", []string{}, "custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)") rootCmd.Flags().BoolVarP(&input.reuseContainers, "reuse", "r", false, "reuse action containers to maintain state") rootCmd.Flags().BoolVarP(&input.forcePull, "pull", "p", false, "pull docker image(s) if already present") rootCmd.Flags().StringVarP(&input.eventPath, "eventpath", "e", "", "path to event JSON file") @@ -98,6 +99,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str Workdir: input.Workdir(), LogOutput: input.logOutput, Secrets: newSecrets(input.secrets), + Platforms: input.newPlatforms(), } runner, err := runner.New(config) if err != nil { diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 7aea62a..2289847 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -102,7 +102,7 @@ func (rc *RunContext) Executor() common.Executor { } platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn) - if img := platformImage(platformName); img == "" { + if img, ok := rc.Config.Platforms[strings.ToLower(platformName)]; !ok || img == "" { log.Infof(" \U0001F6A7 Skipping unsupported platform '%s'", platformName) return nil } diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 2fc21ec..2c1888a 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -25,6 +25,7 @@ type Config struct { ForcePull bool // force pulling of the image, if already present LogOutput bool // log the output from docker run Secrets map[string]string // list of secrets + Platforms map[string]string // list of platforms } type runnerImpl struct { diff --git a/pkg/runner/step.go b/pkg/runner/step.go index 80258b8..408f033 100644 --- a/pkg/runner/step.go +++ b/pkg/runner/step.go @@ -51,7 +51,7 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor { containerSpec.Options = job.Container.Options } else { platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn) - containerSpec.Image = platformImage(platformName) + containerSpec.Image = rc.Config.Platforms[strings.ToLower(platformName)] } return common.NewPipelineExecutor( rc.setupEnv(containerSpec, step), @@ -162,24 +162,11 @@ func (rc *RunContext) setupShellCommand(containerSpec *model.ContainerSpec, shel return err } containerPath := fmt.Sprintf("/github/home/%s", filepath.Base(tempScript.Name())) - containerSpec.Args = strings.Replace(shellCommand, "{0}", containerPath, 1) + containerSpec.Entrypoint = strings.Replace(shellCommand, "{0}", containerPath, 1) return nil } } -func platformImage(platform string) string { - switch strings.ToLower(platform) { - case "ubuntu-latest", "ubuntu-18.04": - return "ubuntu:18.04" - case "ubuntu-16.04": - return "ubuntu:16.04" - case "windows-latest", "windows-2019", "macos-latest", "macos-10.15": - return "" - default: - return "" - } -} - func (rc *RunContext) setupAction(containerSpec *model.ContainerSpec, actionDir string) common.Executor { return func(ctx context.Context) error { f, err := os.Open(filepath.Join(actionDir, "action.yml")) diff --git a/pkg/runner/testdata/basic/push.yml b/pkg/runner/testdata/basic/push.yml index fce964a..720ca25 100644 --- a/pkg/runner/testdata/basic/push.yml +++ b/pkg/runner/testdata/basic/push.yml @@ -2,8 +2,14 @@ name: basic on: push jobs: + check: + runs-on: ubuntu-latest + steps: + - run: echo 'hello world' + build: runs-on: ubuntu-latest + needs: [check] steps: - uses: ./actions/action1 with: