add support to override platform
Signed-off-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
parent
e4ee2ddab7
commit
543501a36a
|
@ -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"
|
||||
|
|
|
@ -12,6 +12,7 @@ type Input struct {
|
|||
eventPath string
|
||||
reuseContainers bool
|
||||
secrets []string
|
||||
platforms []string
|
||||
dryrun bool
|
||||
forcePull bool
|
||||
logOutput bool
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue