Skip to content

Commit

Permalink
Add circleci for project and use goreleaser for managing releases
Browse files Browse the repository at this point in the history
  • Loading branch information
cplee committed Apr 11, 2018
1 parent 24fde43 commit 45971d9
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 35 deletions.
51 changes: 51 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,51 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/stelligent/config-lint
steps:
- checkout
- restore_cache:
keys:
- go-pkg-cache
- run:
name: Dependencies
command: make deps
- run:
name: Test
command: make test
- save_cache:
key: go-pkg-cache
paths:
- "/go/pkg"
- persist_to_workspace:
root: .
paths: .
release:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/stelligent/config-lint
steps:
- attach_workspace:
at: /go/src/github.com/stelligent/config-lint
- run:
name: Release
command: curl -sL https://git.io/goreleaser | bash

workflows:
version: 2
build-and-release:
jobs:
- build:
filters:
tags:
only: /.*/
- release:
requires:
- build
filters:
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
branches:
ignore: /.*/
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ coverage.out
web/assets.go
.release/
vendor/
dist/
46 changes: 46 additions & 0 deletions .goreleaser.yml
@@ -0,0 +1,46 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
- main: ./cli
env:
- CGO_ENABLED=0
- main: ./lambda
binary: lambda
goos:
- linux
goarch:
- amd64
- main: ./web
binary: webserver
goos:
- linux
goarch:
- amd64
archive:
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brew:
github:
owner: stelligent
name: homebrew-tap
commit_author:
name: goreleaserbot
email: goreleaser@stelligent.com
folder: Formula
59 changes: 28 additions & 31 deletions Makefile
@@ -1,15 +1,11 @@
ORG := stelligent
PACKAGE := config-lint
TARGET_OS := darwin
SRC_PACKAGES = assertion cli lambda linter web

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
IS_MASTER := $(filter master, $(BRANCH))
VERSION := $(shell cat VERSION)$(if $(IS_MASTER),,-$(BRANCH))
ARCH := $(shell go env GOARCH)
OS := $(shell go env GOOS)
VERSION = $(shell git tag -l --sort=creatordate | grep "^v[0-9]*.[0-9]*.[0-9]*$$" | tail -1)
MAJOR_VERSION := $(word 1, $(subst ., ,$(VERSION)))
MINOR_VERSION := $(word 2, $(subst ., ,$(VERSION)))
PATCH_VERSION := $(word 3, $(subst ., ,$(VERSION)))
NEXT_VERSION := $(MAJOR_VERSION).$(MINOR_VERSION).$(shell echo $(PATCH_VERSION)+1|bc)

BUILD_DIR = .release
GOLDFLAGS = "-X main.version=$(VERSION)"
GOLDFLAGS = "-X main.version=$(NEXT_VERSION)"

CLI_FILES = $(shell find cli linter assertion -name \*.go)
LAMBDA_FILES = $(shell find lambda assertion -name \*.go)
Expand All @@ -22,46 +18,47 @@ deps:
go get "github.com/jteeuwen/go-bindata/..."
go get "github.com/golang/lint/golint"
go get "github.com/fzipp/gocyclo"
go get "github.com/goreleaser/goreleaser"
dep ensure

gen:
@echo "=== generating ==="
@go generate ./...

lint: gen
@echo "=== linting ==="
@go vet ./...
@golint $(go list ./... | grep -v /vendor/)

test: lint
@echo "=== testing ==="
@go test ./...

bumpversion:
@echo "=== promoting $(NEXT_VERSION) ==="
@git tag -a -m "$(VERSION) -> $(NEXT_VERSION)" $(NEXT_VERSION)
@git push --follow-tags origin

$(BUILD_DIR)/config-lint: $(CLI_FILES)
@echo "=== building config-lint $(VERSION) - $@ ==="
@echo "=== building config-lint - $@ ==="
mkdir -p $(BUILD_DIR)
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags=$(GOLDFLAGS) -o $(BUILD_DIR)/config-lint cli/*.go

$(BUILD_DIR)/lambda: $(LAMBDA_FILES)
@echo "=== building lambda $(VERSION) - $@ ==="
@echo "=== building lambda - $@ ==="
mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 go build -ldflags=$(GOLDFLAGS) -o $(BUILD_DIR)/lambda lambda/*.go
cd $(BUILD_DIR) && zip lambda.zip lambda

lambda-deploy: $(BUILD_DIR)/lambda
aws lambda update-function-code --region us-east-1 --function-name config-go --zip-file fileb://$(BUILD_DIR)/lambda.zip

$(BUILD_DIR)/webserver: webserver-gen $(WEB_FILES)
$(BUILD_DIR)/webserver: gen $(WEB_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags=$(GOLDFLAGS) -o $(BUILD_DIR)/webserver web/*.go

webserver-gen: $(WEB_FILES)
cd web && go generate *.go

webserver-docker:
docker build -t lhitchon/config-lint-web -f Dockerfile-web .

test:
@echo "=== testing ==="
cd assertion && go test
cd linter && go test
cd lambda && go test

lint:
@echo "=== linting ==="
cd assertion && golint
cd linter && golint
cd cli && golint
cd lambda && golint
cd web && golint

build: $(BUILD_DIR)/config-lint $(BUILD_DIR)/lambda $(BUILD_DIR)/webserver

all: clean deps test build
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

7 changes: 4 additions & 3 deletions cli/app.go
Expand Up @@ -4,11 +4,12 @@ import (
"encoding/json"
"flag"
"fmt"
"os"
"strings"

"github.com/ghodss/yaml"
"github.com/stelligent/config-lint/assertion"
"github.com/stelligent/config-lint/linter"
"os"
"strings"
)

var version string
Expand Down Expand Up @@ -57,7 +58,7 @@ func main() {
}
ruleSets, err := loadRuleSets(rulesFilenames)
if err != nil {
fmt.Errorf("Failed to load rules: %v", err)
fmt.Printf("Failed to load rules: %v", err)
return
}
applyRules(ruleSets, flag.Args(), applyOptions)
Expand Down

0 comments on commit 45971d9

Please sign in to comment.