Skip to content

Commit

Permalink
Merge pull request #24 from Clever/ux-nits
Browse files Browse the repository at this point in the history
UX Nits
  • Loading branch information
nathanleiby authored Feb 8, 2018
2 parents 3160af0 + 61c651f commit 47f21c3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.9
0.0.10
14 changes: 13 additions & 1 deletion cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"log"
"os"
"path/filepath"
"strings"

"github.com/Clever/microplane/clone"
"github.com/Clever/microplane/initialize"
"github.com/Clever/microplane/merge"
"github.com/Clever/microplane/plan"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -62,7 +64,7 @@ var planCmd = &cobra.Command{

err = parallelize(repos, planOneRepo)
if err != nil {
log.Fatal(err)
log.Fatal("# errors = ", strings.Count(err.Error(), " | ")+1)
}
},
}
Expand All @@ -77,6 +79,16 @@ func planOneRepo(r initialize.Repo, ctx context.Context) error {
return nil
}

// Exit early if already merged
var mergeOutput struct {
merge.Output
Error string
}
if loadJSON(outputPath(r.Name, "merge"), &mergeOutput) == nil && mergeOutput.Success {
log.Printf("%s/%s - already merged", r.Owner, r.Name)
return nil
}

// Prepare workdir for current step's output
planOutputPath := outputPath(r.Name, "plan")
planWorkDir := filepath.Dir(planOutputPath)
Expand Down
11 changes: 11 additions & 0 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"github.com/Clever/microplane/initialize"
"github.com/Clever/microplane/merge"
"github.com/Clever/microplane/plan"
"github.com/Clever/microplane/push"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -51,6 +52,16 @@ var pushCmd = &cobra.Command{
func pushOneRepo(r initialize.Repo, ctx context.Context) error {
log.Printf("pushing: %s/%s", r.Owner, r.Name)

// Exit early if already merged
var mergeOutput struct {
merge.Output
Error string
}
if loadJSON(outputPath(r.Name, "merge"), &mergeOutput) == nil && mergeOutput.Success {
log.Printf("%s/%s - already merged", r.Owner, r.Name)
return nil
}

// Get previous step's output
var planOutput plan.Output
if loadJSON(outputPath(r.Name, "plan"), &planOutput) != nil || !planOutput.Success {
Expand Down
4 changes: 4 additions & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var statusCmd = &cobra.Command{
if !valid {
log.Fatalf("%s not a targeted repo name (valid target repos are: %s)", singleRepo, strings.Join(validRepoNames, ", "))
}
isSingleRepo = true
}

repos := []string{}
Expand Down Expand Up @@ -120,6 +121,9 @@ func getRepoStatus(repo string) (status, details string) {
if err == nil {
details = fmt.Sprintf("%d file(s) modified", len(diff.Files))
}
if isSingleRepo {
fmt.Println(planOutput.GitDiff)
}

var pushOutput struct {
push.Output
Expand Down
26 changes: 23 additions & 3 deletions golang.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This is the default Clever Golang Makefile.
# It is stored in the dev-handbook repo, github.com/Clever/dev-handbook
# Please do not alter this file directly.
GOLANG_MK_VERSION := 0.2.0
GOLANG_MK_VERSION := 0.3.2

SHELL := /bin/bash
SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]')
Expand All @@ -18,7 +18,7 @@ define golang-version-check
_ := $(if \
$(shell \
expr >/dev/null \
`go version | cut -d" " -f3 | cut -c3- | cut -d. -f2` \
`go version | cut -d" " -f3 | cut -c3- | cut -d. -f2 | sed -E 's/beta[0-9]+//'` \
\>= `echo $(1) | cut -d. -f2` \
\& \
`go version | cut -d" " -f3 | cut -c3- | cut -d. -f1` \
Expand Down Expand Up @@ -52,9 +52,16 @@ golang-dep-vendor-deps: bin/dep
# golang-godep-vendor is a target for saving dependencies with the dep tool
# to the vendor/ directory. All nested vendor/ directories are deleted via
# the prune command.
# In CI, -vendor-only is used to avoid updating the lock file.
ifndef CI
define golang-dep-vendor
bin/dep ensure
bin/dep ensure -v
endef
else
define golang-dep-vendor
bin/dep ensure -v -vendor-only
endef
endif

# Golint is a tool for linting Golang code for common errors.
GOLINT := $(GOPATH)/bin/golint
Expand Down Expand Up @@ -147,6 +154,19 @@ $(call golang-vet,$(1))
$(call golang-test-strict,$(1))
endef

# golang-build: builds a golang binary. ensures CGO build is done during CI. This is needed to make a binary that works with a Docker alpine image.
# arg1: pkg path
# arg2: executable name
define golang-build
@echo "BUILDING..."
@if [ -z "$$CI" ]; then \
go build -o bin/$(2) $(1); \
else \
echo "-> Building CGO binary"; \
CGO_ENABLED=0 go build -installsuffix cgo -o bin/$(2) $(1); \
fi;
endef

# golang-update-makefile downloads latest version of golang.mk
golang-update-makefile:
@wget https://raw.githubusercontent.com/Clever/dev-handbook/master/make/golang.mk -O /tmp/golang.mk 2>/dev/null
Expand Down

0 comments on commit 47f21c3

Please sign in to comment.