Skip to content

Commit

Permalink
Merge pull request #357 from CircleCI-Public/dnephin/use-tests-cmd-fr…
Browse files Browse the repository at this point in the history
…om-agent

Delegate the entire 'tests' subcommand to circleci-agent
  • Loading branch information
dnephin authored Jan 15, 2020
2 parents 716811d + 8fe9d3c commit cc17c54
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 251 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ orbs:
executors:
go:
docker:
- image: circleci/golang:1.11
- image: circleci/golang:1.12.15
environment:
CGO_ENABLED: 0

Expand Down Expand Up @@ -51,6 +51,7 @@ commands:
name: Install GoReleaser
command: |
[ -f ~/goreleaser_amd64.deb ] || curl --silent --location --fail --retry 3 << parameters.GORELEASER_URL >> > ~/goreleaser_amd64.deb
sudo apt-get update -y
sudo apt install ~/goreleaser_amd64.deb
gomod:
steps:
Expand Down
2 changes: 1 addition & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Second, it's written in Go. If you are new to Go, we recommend the following res

## Requirements

* Go 1.11+
* Go 1.12+
* Make
* ...

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func MakeCommands() *cobra.Command {
rootCmd.SetUsageTemplate(usageTemplate)
rootCmd.DisableAutoGenTag = true

rootCmd.AddCommand(newTestsCommand(rootOptions))
rootCmd.AddCommand(newTestsCommand())
rootCmd.AddCommand(newQueryCommand(rootOptions))
rootCmd.AddCommand(newConfigCommand(rootOptions))
rootCmd.AddCommand(newOrbCommand(rootOptions))
Expand Down
90 changes: 7 additions & 83 deletions cmd/tests.go
Original file line number Diff line number Diff line change
@@ -1,95 +1,19 @@
package cmd

import (
"fmt"

"github.com/CircleCI-Public/circleci-cli/proxy"
"github.com/CircleCI-Public/circleci-cli/settings"
"github.com/bmatcuk/doublestar"
"github.com/spf13/cobra"
)

type testsOptions struct {
cfg *settings.Config
args []string
}

func newTestsCommand(config *settings.Config) *cobra.Command {
opts := testsOptions{
cfg: config,
}

func newTestsCommand() *cobra.Command {
testsCmd := &cobra.Command{
Use: "tests",
Short: "Collect and split files with tests",
Hidden: true,
}

globCmd := &cobra.Command{
Use: "glob",
Short: "Glob files using pattern",
PreRun: func(cmd *cobra.Command, args []string) {
opts.args = args
},
RunE: func(_ *cobra.Command, _ []string) error {
return globRun(opts)
Use: "tests",
Short: "Collect and split tests so they may be run in parallel.",
DisableFlagParsing: true,
Hidden: true,
RunE: func(_ *cobra.Command, args []string) error {
return proxy.Exec([]string{"tests"}, args)
},
}

splitCmd := &cobra.Command{
Use: "split",
Short: "Return a split batch of provided files (must be inside a build).",
Long: "This command wraps `circleci-agent` which must be run inside of a build.",
PreRun: func(cmd *cobra.Command, args []string) {
opts.args = args

},
RunE: func(_ *cobra.Command, _ []string) error {
return splitRunE(opts)
},
}
splitCmd.Flags().Uint("index", 0, "index of node.")
splitCmd.Flags().Uint("total", 1, "number of nodes.")
splitCmd.Flags().String("split-by", "name", `how to weight the split, allowed values are "name", "filesize", and "timings".`)
splitCmd.Flags().String("timings-type", "filename", `lookup historical timing data by: "classname", "filename", or "testname".`)
splitCmd.Flags().Bool("show-counts", false, `print test file or test class counts to stderr (default false).`)
splitCmd.Flags().String("timings-file", "", "JSON file containing historical timing data.")

testsCmd.AddCommand(globCmd)
testsCmd.AddCommand(splitCmd)

return testsCmd
}

func expandGlobs(opts testsOptions) ([]string, error) {
result := []string{}

for _, arg := range opts.args {
matches, err := doublestar.Glob(arg)
if err != nil {
return nil, err
}

result = append(result, matches...)
}

return result, nil
}

func globRun(opts testsOptions) error {
allfiles, err := expandGlobs(opts)

if err != nil {
return err
}

for _, filename := range allfiles {
fmt.Println(filename)
}

return nil
}

func splitRunE(opts testsOptions) error {
return proxy.Exec([]string{"tests", "split"}, opts.args)
}
42 changes: 16 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,37 @@ module github.com/CircleCI-Public/circleci-cli
require (
github.com/Masterminds/semver v1.4.2
github.com/blang/semver v3.5.1+incompatible
github.com/bmatcuk/doublestar v1.0.10
github.com/briandowns/spinner v0.0.0-20181018151057-dd69c579ff20
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/fatih/color v1.7.0
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/gobuffalo/buffalo-plugins v1.9.3 // indirect
github.com/gobuffalo/flect v0.0.0-20181210151238-24a2b68e0316 // indirect
github.com/gobuffalo/packr/v2 v2.0.0-rc.13
github.com/golang/protobuf v1.2.0
github.com/google/go-cmp v0.2.0
github.com/google/go-github v15.0.0+incompatible
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135
github.com/google/pprof v0.0.0-20190309163659-77426154d546 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6 // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/inconshreveable/mousetrap v1.0.0
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a
github.com/lunixbochs/vtclean v0.0.0-20170504063817-d14193dfc626
github.com/google/go-cmp v0.2.0 // indirect
github.com/google/go-github v15.0.0+incompatible // indirect
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
github.com/lunixbochs/vtclean v0.0.0-20170504063817-d14193dfc626 // indirect
github.com/manifoldco/promptui v0.3.0
github.com/mattn/go-colorable v0.0.9
github.com/mattn/go-isatty v0.0.4
github.com/microcosm-cc/bluemonday v1.0.2 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/onsi/ginkgo v1.7.0
github.com/onsi/gomega v1.4.3
github.com/pkg/errors v0.8.0
github.com/rhysd/go-github-selfupdate v0.0.0-20180520142321-41c1bbb0804a
github.com/spf13/afero v1.2.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3
github.com/tcnksm/go-gitconfig v0.1.2
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 // indirect
github.com/ulikunitz/xz v0.5.4
golang.org/x/arch v0.0.0-20190226203302-36aee92af9e8 // indirect
golang.org/x/net v0.0.0-20181220203305-927f97764cc3
golang.org/x/oauth2 v0.0.0-20180724155351-3d292e4d0cdc
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
github.com/ulikunitz/xz v0.5.4 // indirect
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 // indirect
golang.org/x/oauth2 v0.0.0-20180724155351-3d292e4d0cdc // indirect
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb
golang.org/x/text v0.3.0
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb // indirect
golang.org/x/tools v0.0.0-20181221235234-d00ac6d27372 // indirect
google.golang.org/appengine v1.2.0
gopkg.in/yaml.v2 v2.2.2
gotest.tools v2.1.0+incompatible
)

go 1.12
Loading

0 comments on commit cc17c54

Please sign in to comment.