Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Copy the excellent Makefile from goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed May 10, 2017
1 parent 339e4dc commit 57452bc
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 16 deletions.
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
SOURCE_FILES?=$$(go list ./... | grep -v /vendor/)
TEST_PATTERN?=.
TEST_OPTIONS?=

setup: ## Install all the build and lint dependencies
go get -u github.com/alecthomas/gometalinter
go get -u github.com/golang/dep/...
go get -u github.com/pierrre/gotestcover
go get -u golang.org/x/tools/cmd/cover
dep ensure
gometalinter --install

test: ## Run all the tests
gotestcover $(TEST_OPTIONS) -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s

cover: test ## Run all the tests and opens the coverage report
go tool cover -html=coverage.txt

fmt: ## gofmt and goimports all go files
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done

lint: ## Run all the linters
gometalinter --vendor --disable-all \
--enable=deadcode \
--enable=ineffassign \
--enable=gosimple \
--enable=staticcheck \
--enable=gofmt \
--enable=goimports \
--enable=dupl \
--enable=misspell \
--enable=errcheck \
--enable=vet \
--enable=vetshadow \
--deadline=10m \
./...

ci: lint test ## Run all the tests and code checks

build: ## Build a beta version of goreleaser
go build

# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := build


samples:
Expand Down
42 changes: 26 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,11 @@ func Load(repo string, file string) (*config.Project, error) {
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
} else {
body, err = ioutil.ReadFile(file)
if err != nil {
return nil, err
}
}
if err != nil {
return nil, err
}
project := &config.Project{}
err = yaml.Unmarshal(body, project)
Expand All @@ -163,7 +160,21 @@ func Load(repo string, file string) (*config.Project, error) {
project.Release.GitHub.Owner = path.Dir(repo)
project.Release.GitHub.Name = path.Base(repo)
}
var uname = map[string]string{

// set default archive format
if project.Archive.Format == "" {
project.Archive.Format = "tar.gz"
}

// set default binary name
if project.Build.Binary == "" {
project.Build.Binary = path.Base(repo)
}

// Convert replacements from GOOS/GOARCH to uname.

// map of golang OS/ARCH identifier to what uname uses
uname := map[string]string{
"darwin": "Darwin",
"linux": "Linux",
"freebsd": "FreeBSD",
Expand All @@ -173,26 +184,25 @@ func Load(repo string, file string) (*config.Project, error) {
"386": "i386",
"amd64": "x86_64",
}

rmap := make(map[string]string)
for k, v := range project.Archive.Replacements {
newk := uname[k]

// if unknown, keep
if newk == "" {
rmap[k] = v
continue
}
if newk != v {
rmap[newk] = v

// if mapping is an idenity, then ignore
if newk == v {
continue
}

rmap[newk] = v
}
project.Archive.Replacements = rmap

if project.Archive.Format == "" {
project.Archive.Format = "tar.gz"
}
if project.Build.Binary == "" {
project.Build.Binary = path.Base(repo)
}
return project, nil
}

Expand Down

0 comments on commit 57452bc

Please sign in to comment.