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:
|
goos:
|
||||||
- darwin
|
- darwin
|
||||||
- linux
|
- linux
|
||||||
- windows
|
#- windows
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
- 386
|
- 386
|
||||||
@ -13,23 +13,23 @@ checksum:
|
|||||||
name_template: 'checksums.txt'
|
name_template: 'checksums.txt'
|
||||||
snapshot:
|
snapshot:
|
||||||
name_template: "{{ .Env.SNAPSHOT_VERSION }}"
|
name_template: "{{ .Env.SNAPSHOT_VERSION }}"
|
||||||
archive:
|
archives:
|
||||||
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
|
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
|
||||||
replacements:
|
replacements:
|
||||||
darwin: Darwin
|
darwin: Darwin
|
||||||
linux: Linux
|
linux: Linux
|
||||||
windows: Windows
|
windows: Windows
|
||||||
386: i386
|
386: i386
|
||||||
amd64: x86_64
|
amd64: x86_64
|
||||||
format_overrides:
|
format_overrides:
|
||||||
- goos: windows
|
- goos: windows
|
||||||
format: zip
|
format: zip
|
||||||
brew:
|
brews:
|
||||||
github:
|
- github:
|
||||||
owner: nektos
|
owner: nektos
|
||||||
name: homebrew-tap
|
name: homebrew-tap
|
||||||
folder: Formula
|
folder: Formula
|
||||||
homepage: https://github.com/nektos/act
|
homepage: https://github.com/nektos/act
|
||||||
description: Run GitHub Actions locally
|
description: Run GitHub Actions locally
|
||||||
test: |
|
test: |
|
||||||
system "#{bin}/act --version"
|
system "#{bin}/act --version"
|
||||||
|
@ -12,6 +12,7 @@ type Input struct {
|
|||||||
eventPath string
|
eventPath string
|
||||||
reuseContainers bool
|
reuseContainers bool
|
||||||
secrets []string
|
secrets []string
|
||||||
|
platforms []string
|
||||||
dryrun bool
|
dryrun bool
|
||||||
forcePull bool
|
forcePull bool
|
||||||
logOutput bool
|
logOutput bool
|
||||||
|
25
cmd/platforms.go
Normal file
25
cmd/platforms.go
Normal file
@ -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().BoolP("list", "l", false, "list workflows")
|
||||||
rootCmd.Flags().StringP("job", "j", "", "run job")
|
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.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.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().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")
|
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(),
|
Workdir: input.Workdir(),
|
||||||
LogOutput: input.logOutput,
|
LogOutput: input.logOutput,
|
||||||
Secrets: newSecrets(input.secrets),
|
Secrets: newSecrets(input.secrets),
|
||||||
|
Platforms: input.newPlatforms(),
|
||||||
}
|
}
|
||||||
runner, err := runner.New(config)
|
runner, err := runner.New(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -102,7 +102,7 @@ func (rc *RunContext) Executor() common.Executor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn)
|
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)
|
log.Infof(" \U0001F6A7 Skipping unsupported platform '%s'", platformName)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ type Config struct {
|
|||||||
ForcePull bool // force pulling of the image, if already present
|
ForcePull bool // force pulling of the image, if already present
|
||||||
LogOutput bool // log the output from docker run
|
LogOutput bool // log the output from docker run
|
||||||
Secrets map[string]string // list of secrets
|
Secrets map[string]string // list of secrets
|
||||||
|
Platforms map[string]string // list of platforms
|
||||||
}
|
}
|
||||||
|
|
||||||
type runnerImpl struct {
|
type runnerImpl struct {
|
||||||
|
@ -51,7 +51,7 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
|
|||||||
containerSpec.Options = job.Container.Options
|
containerSpec.Options = job.Container.Options
|
||||||
} else {
|
} else {
|
||||||
platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn)
|
platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn)
|
||||||
containerSpec.Image = platformImage(platformName)
|
containerSpec.Image = rc.Config.Platforms[strings.ToLower(platformName)]
|
||||||
}
|
}
|
||||||
return common.NewPipelineExecutor(
|
return common.NewPipelineExecutor(
|
||||||
rc.setupEnv(containerSpec, step),
|
rc.setupEnv(containerSpec, step),
|
||||||
@ -162,24 +162,11 @@ func (rc *RunContext) setupShellCommand(containerSpec *model.ContainerSpec, shel
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
containerPath := fmt.Sprintf("/github/home/%s", filepath.Base(tempScript.Name()))
|
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
|
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 {
|
func (rc *RunContext) setupAction(containerSpec *model.ContainerSpec, actionDir string) common.Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
f, err := os.Open(filepath.Join(actionDir, "action.yml"))
|
f, err := os.Open(filepath.Join(actionDir, "action.yml"))
|
||||||
|
6
pkg/runner/testdata/basic/push.yml
vendored
6
pkg/runner/testdata/basic/push.yml
vendored
@ -2,8 +2,14 @@ name: basic
|
|||||||
on: push
|
on: push
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo 'hello world'
|
||||||
|
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: [check]
|
||||||
steps:
|
steps:
|
||||||
- uses: ./actions/action1
|
- uses: ./actions/action1
|
||||||
with:
|
with:
|
||||||
|
Loading…
Reference in New Issue
Block a user