Skip to content

Commit

Permalink
fix nektos#89 - support .actrc file
Browse files Browse the repository at this point in the history
  • Loading branch information
cplee committed Feb 25, 2020
1 parent 5b90c8a commit 76a8bfc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-P ubuntu-latest=nektos/act-environments-ubuntu:18.04
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build:
go build -ldflags "-X main.version=$(VERSION)" -o dist/local/act main.go

test:
$(ACT) -P ubuntu-latest=nektos/act-environments-ubuntu:18.04
$(ACT)

install: build
@cp dist/local/act /usr/local/bin/act
Expand Down
34 changes: 34 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cmd

import (
"bufio"
"context"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/nektos/act/pkg/common"

Expand Down Expand Up @@ -41,12 +44,43 @@ func Execute(ctx context.Context, version string) {
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().BoolVarP(&input.noOutput, "quiet", "q", false, "disable logging of output from steps")
rootCmd.PersistentFlags().BoolVarP(&input.dryrun, "dryrun", "n", false, "dryrun mode")
rootCmd.SetArgs(args())
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}

}

func args() []string {
args := make([]string, 0)
for _, dir := range []string{
os.Getenv("HOME"),
".",
} {
args = append(args, readArgsFile(fmt.Sprintf("%s/.actrc", dir))...)
}
args = append(args, os.Args[1:]...)
return args
}

func readArgsFile(file string) []string {
args := make([]string, 0)
f, err := os.Open(file)
if err != nil {
return args
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
arg := scanner.Text()
if strings.HasPrefix(arg, "-") {
args = append(args, strings.Fields(arg)...)
}
}
return args

}

func setupLogging(cmd *cobra.Command, args []string) {
verbose, _ := cmd.Flags().GetBool("verbose")
if verbose {
Expand Down

0 comments on commit 76a8bfc

Please sign in to comment.