Skip to content

Commit

Permalink
feat(*): services, skip flag, and UX improvements (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard authored Jan 10, 2018
1 parent c53f523 commit 0373fea
Show file tree
Hide file tree
Showing 7,226 changed files with 14,765 additions and 2,525,813 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .codebeatignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docs/**
vendor/**
website/**
11 changes: 6 additions & 5 deletions .conform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ policies:
- "policy"
- "readme"
- "renderer"
- "service"
- "*"

script:
Expand All @@ -45,13 +46,13 @@ stages:
tasks:
binary:
template: |
FROM autonomy/golang:1.8.3 as binary
FROM autonomy/golang:1.9 as {{ .Docker.CurrentStage }}
WORKDIR $GOPATH/src/github.com/{{ .Repository }}
COPY ./ ./
{{ if and .Git.IsClean .Git.IsTag }}
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /conform -ldflags "-X \"github.com/{{ .Repository }}/pkg/version.Tag={{ trimAll "v" .Git.Tag }}\" -X \"github.com/{{ .Repository }}/pkg/version.SHA={{ .Git.SHA }}\" -X \"github.com/{{ .Repository }}/pkg/version.Built={{ .Built }}\""
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /conform -ldflags "-X \"github.com/{{ .Repository }}/cmd.Tag={{ trimAll "v" .Git.Tag }}\" -X \"github.com/{{ .Repository }}/cmd.SHA={{ .Git.SHA }}\" -X \"github.com/{{ .Repository }}/cmd.Built={{ .Built }}\""
{{ else if .Git.IsClean }}
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /conform -ldflags "-X \"github.com/{{ .Repository }}/pkg/version.SHA={{ .Git.SHA }}\" -X \"github.com/{{ .Repository }}/pkg/version.Built={{ .Built }}\""
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /conform -ldflags "-X \"github.com/{{ .Repository }}/cmd.SHA={{ .Git.SHA }}\" -X \"github.com/{{ .Repository }}/cmd.Built={{ .Built }}\""
{{ else }}
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /conform
{{ end }}
Expand All @@ -60,8 +61,8 @@ tasks:
{{ fromURL "https://raw.githubusercontent.com/autonomy/conform-templates/master/golang/Dockerfile.test" }}
image:
template: |
FROM alpine:3.6 as image
MAINTAINER Andrew Rynhard <[email protected]>
FROM alpine:3.6 as {{ .Docker.CurrentStage }}
LABEL maintainer="Andrew Rynhard <[email protected]>"
RUN apk --update add bash \
&& rm -rf /var/cache/apk/*
COPY --from=binary /conform /bin
Expand Down
27 changes: 20 additions & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@
[[constraint]]
branch = "v2"
name = "gopkg.in/yaml.v2"

[[constraint]]
name = "gopkg.in/src-d/go-git.v4"
source = "github.com/src-d/go-git"
version = "v4.0.0"
29 changes: 22 additions & 7 deletions cmd/enforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,53 @@ package cmd

import (
"fmt"
"os"

"github.com/autonomy/conform/pkg/enforcer"
"github.com/autonomy/conform/pkg/utilities"
"github.com/spf13/cobra"
)

var (
skipArray []string
)

// enforceCmd represents the enforce command
var enforceCmd = &cobra.Command{
Use: "enforce",
Short: "",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
err := fmt.Errorf("The enforce command does not take arguments")

return err
fmt.Println(err)
os.Exit(1)
}
if err := utilities.CheckDockerVersion(); err != nil {
return err
fmt.Println(err)
os.Exit(1)
}
e, err := enforcer.New()
if err != nil {
return err
fmt.Println(err)
os.Exit(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 {
return err
fmt.Println(err)
os.Exit(1)
}

return nil
},
}

func init() {
RootCmd.AddCommand(enforceCmd)
enforceCmd.Flags().StringArrayVarP(&skipArray, "skip", "s", []string{}, "skip a stage in the pipeline")
}
6 changes: 5 additions & 1 deletion pkg/enforcer/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func (c *Conform) Enforce() error {
return err
}

return c.Script.Execute(c.Metadata)
if c.Script != nil {
return c.Script.Execute(c.Metadata)
}

return nil
}

func (c *Conform) enforce(p *PolicyDeclaration) error {
Expand Down
20 changes: 11 additions & 9 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package git
import (
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
)

// Git is a helper for git.
Expand All @@ -18,7 +19,7 @@ func NewGit() (g *Git, err error) {
}
g = &Git{repo: repo}

return
return g, err
}

// Branch returns the current git branch name.
Expand All @@ -27,12 +28,12 @@ func (g *Git) Branch() (branch string, isBranch bool, err error) {
if err != nil {
return
}
if ref.IsBranch() {
if ref.Name().IsBranch() {
isBranch = true
branch = ref.Name().Short()
}

return
return branch, isBranch, err
}

// SHA returns the sha of the current commit.
Expand All @@ -43,7 +44,7 @@ func (g *Git) SHA() (sha string, err error) {
}
sha = ref.Hash().String()[0:7]

return
return sha, err
}

// Tag returns the tag name if HEAD is a tag.
Expand All @@ -68,7 +69,7 @@ func (g *Git) Tag() (tag string, isTag bool, err error) {
return
}

return
return tag, isTag, err
}

// Status returns the status of the working tree.
Expand All @@ -88,7 +89,7 @@ func (g *Git) Status() (status string, isClean bool, err error) {
status = worktreeStatus.String()
}

return
return status, isClean, err
}

// Message returns the commit message. In the case that a commit has multiple
Expand All @@ -105,9 +106,10 @@ func (g *Git) Message() (message string, err error) {
if commit.NumParents() > 1 {
parents := commit.Parents()
for i := 1; i <= commit.NumParents(); i++ {
next, err := parents.Next()
var next *object.Commit
next, err = parents.Next()
if err != nil {
return "", err
return
}
if i == commit.NumParents() {
message = next.Message
Expand All @@ -117,5 +119,5 @@ func (g *Git) Message() (message string, err error) {
message = commit.Message
}

return
return message, err
}
5 changes: 4 additions & 1 deletion pkg/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type Metadata struct {

// Docker contains docker specific metadata.
type Docker struct {
Image string
Image string
PreviousStage string
CurrentStage string
NextStage string
}

// Git contains git specific metadata.
Expand Down
Loading

0 comments on commit 0373fea

Please sign in to comment.