Skip to content

Commit

Permalink
Use a Makefile to build the project
Browse files Browse the repository at this point in the history
Shameless copy of the amazing one found in https://github.com/jessfraz/amicontained
Remove goxc (which is not maintained anymore).

Binaries are uploaded by Travis CI when building tag.
  • Loading branch information
jcgay committed Aug 17, 2017
1 parent b226cb9 commit e357a32
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ _testmain.go
*.test
*.prof

# goxc
.goxc.local.json
# Cross Platform builds
cross/
14 changes: 0 additions & 14 deletions .goxc.json

This file was deleted.

25 changes: 24 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
language: go
sudo: false
go:
- tip
- 1.8.x
before_install:
- go get github.com/mattn/goveralls
script:
- $HOME/gopath/bin/goveralls -service=travis-ci
- make all release
before_deploy:
- make prepare-bintray
deploy:
- provider: releases
api_key:
secure: Oom3MCaI+y3UWCe44rewz3mtqJ19CDapW4txDmcmijedrrmY8X8q4QefgUONIlXj40uyhOmsLFUHcxCOPzQ/cxpEHh5rpr1hQZodAIM7bdhh6PxfjF9b2P5ZtFJjI5EkRqxTxmNX1lNYMHI4OAN+TE0ui7A0EPGFVHuJtGZUV5dZc7EBhLxNkBppNYIq2ZYoKitCETDC3+EPZi3+QRSKNHbmIeJtDT3dTHzMdJA18ExbxHc37wjuZhUJlZAWR6HnbDWykl5fUVHA8rPEYSwl8C34ANxfXjSOP+woO4jJOhllHdHW/XpbN4xC2OBGOK6zn/LR8nmCZ/lRit9o8G9ZQ7rJALOL+IDDyblt2STB9vzFosIObYSQPPflzDeT1zeDPeZbHkzZNPF89MS3cJRVW9BXWoHEQdS6AWYHzXLE+VdnFLyzhKtlC0HKoA+/20pbFkIsn4SGJMXULlr7jSmBVgmHuVO/6q5fBp/70EjZShO/gzhvdl2oMzhi42RNMLUJzsPJuzDODVTR+QEwqxsk5SWdBWj4pBphbl3A+7Yygzwub++mdrxe0oVHtvSpj8xYAPSPU7V7AGWHPCKxyXK84Lyil0x3fpzGMe7SLd1MNWaGp5iTtkOD6K7H/RPSfugy0CgjoxGxj3SNkllr/n4imc6spNKXOB5Rh7PAj9D+hXw=
go: 1.8.x
file: cross/*
skip_cleanup: true
on:
repo: jcgay/parallel-git-repo
tags: true
- provider: bintray
user: jcgay
key:
secure: obUD+i5GcosTbTld+EDF/2dzOnNV1uYDOC8UTnsyZsAmFRJCUfzCK3A4AiUYXlhf7InA/YlnCcIYrPceY74O6GSPoYldV/m77wOmFO91e4LdwnOzSK/GjXIQpY58/uIe1nmqX5A8AbRNI0CPsRXKiwL3huSLOZbKSb6ls8W4Vi9N/MeqZAKPQtIvAxzjhh8Tt729cddEVk0Ym9BomDaSLRxNRAEBCjuRWyiqz2rA2DdKWSCswBCGa3FPC6L8yffY6ylJS0O6IQBsYrTOzuAJNM6byP7HE8b98v28ZMCBrQ8g39IYtF497A59KjVwCmAcUep4CNPkNsx0i+4YZx3WjGjsvbAArgHymdln3+ENDiAaBnOiQz2F3iSm/JVhtUxb2C0hDzNEoUhbOCLr0cdWOXLFjFyGE444CZgd6vOvh/nX8yYqhOeIyycv5ovOb+gd2QqmA85ZwBUzPx9FHgJWOvEueU/NZQN9zFpvYMLtAy/cLiijZR1DXH3Y56q/BrX5rUrbR/NxjUelyO71zRRGU5j7p4KWY8Rvk4eX653AZqFNXIC+JIK2CbN3K6l8I5AS3zG0scwkuP1+pZo0RSY83OliquyDZnkJB1BmqbYGkNCZs95/GrMh2E6ZkwPw8x/8gIyS+es+WebN7JI36r5/eOCKZWJZBCYiUclUmYfSkpw=
go: 1.8.x
file: bintray/descriptor.json
skip_cleanup: true
on:
repo: jcgay/parallel-git-repo
tags: true
122 changes: 122 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Prepare a GNU sed for macOS users (brew install gnu-sed)
sed = $(shell { command -v gsed || command -v sed; } 2>/dev/null)

# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)

# Setup name variables for the package/tool
NAME := parallel-git-repo
PKG := github.com/jcgay/$(NAME)

# Set any default go build tags
BUILDTAGS :=

# Set the build dir, where built cross-compiled binaries will be output
BUILDDIR := ${PREFIX}/cross

# Populate version variables
# Add to compile time flags
VERSION := $(shell cat version/VERSION)
GITCOMMIT := $(shell git rev-parse --short HEAD)
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif
CTIMEVAR=-X $(PKG)/version.GITCOMMIT=$(GITCOMMIT) -X $(PKG)/version.VERSION=$(VERSION)
GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)"
GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static"

# List the GOOS and GOARCH to build
GOOSARCHES = linux/amd64 linux/386 darwin/amd64 windows/amd64

TODAY = $(shell date +"%Y-%d-%m")

all: clean build fmt lint test vet install ## Runs a clean, build, fmt, lint, test, vet and install

.PHONY: build
build: $(NAME) ## Builds a dynamic executable or package

$(NAME): *.go version/VERSION
@echo "+ $@"
go build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(NAME) .

.PHONY: static
static: ## Builds a static executable
@echo "+ $@"
CGO_ENABLED=0 go build \
-tags "$(BUILDTAGS) static_build" \
${GO_LDFLAGS_STATIC} -o $(NAME) .

.PHONY: fmt
fmt: ## Verifies all files have men `gofmt`ed
@echo "+ $@"
@gofmt -s -l . | grep -v vendor | tee /dev/stderr

.PHONY: lint
lint: ## Verifies `golint` passes
@echo "+ $@"
@golint ./... | grep -v vendor | tee /dev/stderr

.PHONY: test
test: ## Runs the go tests
@echo "+ $@"
@go test -v -tags "$(BUILDTAGS)" $(shell go list ./... | grep -v vendor)

.PHONY: vet
vet: ## Verifies `go vet` passes
@echo "+ $@"
@go vet $(shell go list ./... | grep -v vendor) | tee /dev/stderr

.PHONY: install
install: ## Installs the executable or package
@echo "+ $@"
@go install .

define buildpretty
mkdir -p $(BUILDDIR)/$(1)/$(2);
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build \
-o $(BUILDDIR)/$(1)/$(2)/$(NAME) \
-a -tags "$(BUILDTAGS) static_build netgo" \
-installsuffix netgo ${GO_LDFLAGS_STATIC} .;
md5sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).md5;
sha256sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).sha256;
endef

.PHONY: cross
cross: *.go version/VERSION ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary)
@echo "+ $@"
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildpretty,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))

define buildrelease
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build \
-o $(BUILDDIR)/$(NAME)-$(1)-$(2) \
-a -tags "$(BUILDTAGS) static_build netgo" \
-installsuffix netgo ${GO_LDFLAGS_STATIC} .;
md5sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).md5;
sha256sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).sha256;
endef

.PHONY: release
release: *.go version/VERSION ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH)
@echo "+ $@"
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))

.PHONY: tag
tag: ## Create a new git tag to prepare to build a release
git tag -sa $(VERSION) -m "$(VERSION)"
@echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a travis build."

.PHONY: prepare-bintray
prepare-bintray: ## Update bintray/descriptor.json with current version
$(sed) -i s/%VERSION%/$(VERSION)/g bintray/descriptor.json
$(sed) -i s/%DATE%/$(TODAY)/g bintray/descriptor.json

.PHONY: clean
clean: ## Cleanup any build binaries or packages
@echo "+ $@"
$(RM) $(NAME)
$(RM) -r $(BUILDDIR)

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,8 @@ maven-notifier: ✔

### Release

- Configure Bintray deployment in `.goxc.local.json`:

```json
{
"ConfigVersion": "0.9",
"TaskSettings": {
"bintray": {
"apikey": "12d312314235afe56090932ea13234"
}
}
}
```

- run `goxc default bintray`
make release

### List available tasks

goxc -h tasks
make help
31 changes: 31 additions & 0 deletions bintray/descriptor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"package": {
"name": "parallel-git-repo",
"repo": "tools",
"subject": "jcgay",
"desc": "Run command on git repositories in parallel",
"website_url": "https://github.com/jcgay/parallel-git-repo",
"issue_tracker_url": "https://github.com/jcgay/parallel-git-repo/issues",
"vcs_url": "https://github.com/jcgay/parallel-git-repo.git",
"github_use_tag_release_notes": true,
"github_release_notes_file": "CHANGELOG.md",
"licenses": ["MIT"],
"labels": ["git", "parallel", "go"],
"public_download_numbers": false,
"public_stats": false
},

"version": {
"name": "%VERSION%",
"desc": "%VERSION%",
"released": "%DATE%",
"vcs_tag": "%VERSION%",
"gpgSign": false
},

"files":
[
{"includePattern": "cross/.*"}
],
"publish": true
}
9 changes: 4 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"github.com/fatih/color"
"github.com/jcgay/parallel-git-repo/version"
"github.com/mitchellh/go-homedir"
"github.com/pelletier/go-toml"
"io"
Expand All @@ -18,8 +19,6 @@ import (
"sync"
)

// VERSION injected at compile time by goxc (see https://github.com/laher/goxc/wiki/versioning#version-number-interpolation)
var VERSION = "unknown-snapshot"
var home string

var (
Expand All @@ -34,7 +33,7 @@ USAGE:
./parallel-git-repo [global options] command [arguments...]
VERSION:
%s
%s (%s)
COMMANDS:
%s
Expand Down Expand Up @@ -63,14 +62,14 @@ func main() {
flag.StringVar(&group, "g", "default", "execute command for a specific repositories group")

flag.Usage = func() {
fmt.Fprint(os.Stderr, fmt.Sprintf(help, VERSION, listCommands(configuration)))
fmt.Fprint(os.Stderr, fmt.Sprintf(help, version.VERSION, version.GITCOMMIT, listCommands(configuration)))
flag.PrintDefaults()
}

flag.Parse()

if printVersion {
fmt.Printf("version: %s", VERSION)
fmt.Printf("version: %s (%s)", version.VERSION, version.GITCOMMIT)
} else if os.Args[1] == "list" {
repos := configuration.ListRepositories()
for key, repos := range repos {
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Example() {
main()

// Output:
// version: unknown-snapshot
// version: unknown-snapshot (unknown-commit)
}

type SingleTempRepository struct {
Expand Down
1 change: 1 addition & 0 deletions version/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.0.0
7 changes: 7 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package version

// VERSION indicates which version of the binary is running.
var VERSION = "unknown-snapshot"

// GITCOMMIT indicates which git hash the binary was built off of
var GITCOMMIT = "unknown-commit"

0 comments on commit e357a32

Please sign in to comment.