diff --git a/.travis.yml b/.travis.yml index 5ef7668a..cf70db5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ install: script: - conform enforce + - conform build after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/cmd/build.go b/cmd/build.go new file mode 100644 index 00000000..235c5146 --- /dev/null +++ b/cmd/build.go @@ -0,0 +1,86 @@ +// Copyright © 2017 NAME HERE +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "fmt" + "os" + "strings" + + "github.com/autonomy/conform/pkg/enforcer" + "github.com/autonomy/conform/pkg/utilities" + "github.com/spf13/cobra" +) + +var ( + skipArray []string + varArray []string +) + +// buildCmd represents the build command +var buildCmd = &cobra.Command{ + Use: "build", + Short: "", + Long: ``, + Run: func(cmd *cobra.Command, args []string) { + if len(args) != 0 { + err := fmt.Errorf("The build command does not take arguments") + + fmt.Println(err) + os.Exit(1) + } + if err := utilities.CheckDockerVersion(); err != nil { + fmt.Println(err) + os.Exit(1) + } + e, err := enforcer.New() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + for _, variable := range varArray { + s := strings.Split(variable, "=") + if len(s) != 2 { + fmt.Printf("Variable key and value must be delimited by a '=': [%s]", variable) + os.Exit(1) + } + e.Metadata.Variables[s[0]] = s[1] + } + for _, skip := range skipArray { + for i, stage := range e.Pipeline.Stages { + if stage == skip { + e.Pipeline.Stages = append(e.Pipeline.Stages[:i], e.Pipeline.Stages[i+1:]...) + } + } + } + if err := e.Pipeline.Build(e.Metadata, e.Stages, e.Tasks); err != nil { + fmt.Println(err) + os.Exit(1) + } + + if e.Script == nil { + return + } + if err := e.Script.Execute(e.Metadata); err != nil { + fmt.Println(err) + os.Exit(1) + } + }, +} + +func init() { + RootCmd.AddCommand(buildCmd) + buildCmd.Flags().StringArrayVar(&skipArray, "skip", []string{}, "skip a stage in the pipeline") + buildCmd.Flags().StringArrayVar(&varArray, "var", []string{}, "set a variable") +} diff --git a/cmd/enforce.go b/cmd/enforce.go index 0459ebf7..e966c7c9 100644 --- a/cmd/enforce.go +++ b/cmd/enforce.go @@ -16,18 +16,11 @@ package cmd import ( "fmt" "os" - "strings" "github.com/autonomy/conform/pkg/enforcer" - "github.com/autonomy/conform/pkg/utilities" "github.com/spf13/cobra" ) -var ( - skipArray []string - varArray []string -) - // enforceCmd represents the enforce command var enforceCmd = &cobra.Command{ Use: "enforce", @@ -40,30 +33,11 @@ var enforceCmd = &cobra.Command{ fmt.Println(err) os.Exit(1) } - if err := utilities.CheckDockerVersion(); err != nil { - fmt.Println(err) - os.Exit(1) - } e, err := enforcer.New() if err != nil { fmt.Println(err) os.Exit(1) } - for _, variable := range varArray { - s := strings.Split(variable, "=") - if len(s) != 2 { - fmt.Printf("Variable key and value must be delimited by a '=': [%s]", variable) - os.Exit(1) - } - e.Metadata.Variables[s[0]] = s[1] - } - for _, skip := range skipArray { - for i, stage := range e.Pipeline.Stages { - if stage == skip { - e.Pipeline.Stages = append(e.Pipeline.Stages[:i], e.Pipeline.Stages[i+1:]...) - } - } - } if err = e.Enforce(); err != nil { fmt.Println(err) os.Exit(1) @@ -73,6 +47,4 @@ var enforceCmd = &cobra.Command{ func init() { RootCmd.AddCommand(enforceCmd) - enforceCmd.Flags().StringArrayVar(&skipArray, "skip", []string{}, "skip a stage in the pipeline") - enforceCmd.Flags().StringArrayVar(&varArray, "var", []string{}, "set a variable") } diff --git a/pkg/enforcer/enforcer.go b/pkg/enforcer/enforcer.go index 918dee20..72723bd7 100644 --- a/pkg/enforcer/enforcer.go +++ b/pkg/enforcer/enforcer.go @@ -66,14 +66,6 @@ func (c *Conform) Enforce() error { } fmt.Printf("passed\n") } - err := c.Pipeline.Build(c.Metadata, c.Stages, c.Tasks) - if err != nil { - return err - } - - if c.Script != nil { - return c.Script.Execute(c.Metadata) - } return nil }