diff options
author | Catâ„¢ <me@hackerc.at> | 2021-01-19 15:30:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-19 15:30:17 +0100 |
commit | 6130460c401f5266aaa73f7b38c9b53a5934e246 (patch) | |
tree | b4399a3b1ae5c2d5d948ca600ab3f0bba0e7a824 /cmd | |
parent | Report error when `if` expression is invalid (#485) (diff) | |
download | forgejo-act-6130460c401f5266aaa73f7b38c9b53a5934e246.tar.xz forgejo-act-6130460c401f5266aaa73f7b38c9b53a5934e246.zip |
Add survey during first run for a default image (#483)
* Add survey during first run for a default image
* few minor formatting updates
* Use image from DockerHub
Co-authored-by: Casey Lee <cplee@nektos.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/root.go | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/cmd/root.go b/cmd/root.go index afd3fbb..70f30b6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,7 +3,6 @@ package cmd import ( "bufio" "context" - "fmt" "os" "path/filepath" "regexp" @@ -11,13 +10,15 @@ import ( "github.com/nektos/act/pkg/common" + "github.com/AlecAivazis/survey/v2" "github.com/andreaskoch/go-fswatch" "github.com/joho/godotenv" - "github.com/nektos/act/pkg/model" - "github.com/nektos/act/pkg/runner" gitignore "github.com/sabhiram/go-gitignore" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" + + "github.com/nektos/act/pkg/model" + "github.com/nektos/act/pkg/runner" ) // Execute is the entry point to running the CLI @@ -65,13 +66,65 @@ func Execute(ctx context.Context, version string) { func args() []string { args := make([]string, 0) - for _, dir := range []string{ - os.Getenv("HOME"), - ".", - } { - args = append(args, readArgsFile(fmt.Sprintf("%s/.actrc", dir))...) + actrc := []string{ + filepath.Join(os.Getenv("HOME"), ".actrc"), + filepath.Join(".", ".actrc"), + } + for _, f := range actrc { + args = append(args, readArgsFile(f)...) + } + + if len(args) == 0 { + var answer string + confirmation := &survey.Select{ + Message: "Please choose the default image you want to use with act:\n\n - Large size image: +20GB Docker image, includes almost all tools used on GitHub Actions\n - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with all actions\n - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions\n\nDefault image and other options can be changed manually in ~/.actrc", + Help: "If you want to know why act asks you that, please go to https://github.com/nektos/act/issues/107", + Default: "Medium", + Options: []string{"Large", "Medium", "Micro"}, + } + + err := survey.AskOne(confirmation, &answer) + if err != nil { + log.Error(err) + os.Exit(1) + } + + _, err = os.Stat(actrc[0]) + if os.IsNotExist(err) { + var option string + switch answer { + case "Large": + option = "-P ubuntu-latest=nektos/act-environments-ubuntu:18.04\n-P ubuntu-18.04=nektos/act-environments-ubuntu:18.04" + case "Medium": + option = "-P ubuntu-latest=catthehacker/ubuntu:act-latest\n-P ubuntu-20.04=catthehacker/ubuntu:act-20.04\n-P ubuntu-18.04=catthehacker/ubuntu:act-18.04\nubuntu-16.04=catthehacker/ubuntu:act-16.04" + case "Micro": + option = "-P ubuntu-latest=node:12.6-buster-slim\n-P ubuntu-12.04=node:12.6-buster-slim\n-P ubuntu-18.04=node:12.6-buster-slim\n-P ubuntu-16.04=node:12.6-stretch-slim" + } + + f, err := os.Create(actrc[0]) + if err != nil { + log.Fatal(err) + } + + _, err = f.WriteString(option) + if err != nil { + log.Fatal(err) + _ = f.Close() + } + + err = f.Close() + if err != nil { + log.Fatal(err) + } + + args = append(args, readArgsFile(actrc[0])...) + } else { + log.Error("File ~/.actrc already exists") + } } + args = append(args, os.Args[1:]...) + return args } @@ -95,7 +148,6 @@ func readArgsFile(file string) []string { } } return args - } func setupLogging(cmd *cobra.Command, _ []string) { |