Skip to content

Commit

Permalink
feat(*): add build command
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard committed Oct 4, 2018
1 parent aed2c22 commit 46a4ef5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ install:

script:
- conform enforce
- conform build

after_success:
- bash <(curl -s https://codecov.io/bash)
86 changes: 86 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
// 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")
}
7 changes: 0 additions & 7 deletions cmd/enforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (
"github.com/spf13/cobra"
)

var (
skipArray []string
varArray []string
)

// enforceCmd represents the enforce command
var enforceCmd = &cobra.Command{
Use: "enforce",
Expand Down Expand Up @@ -73,6 +68,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")
}
8 changes: 0 additions & 8 deletions pkg/enforcer/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 46a4ef5

Please sign in to comment.