Skip to content

Commit

Permalink
add versions
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <acidburn@google.com>
  • Loading branch information
jessfraz committed Jun 9, 2017
1 parent 345f781 commit aa37f2e
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 31 deletions.
48 changes: 46 additions & 2 deletions .travis.yml
Expand Up @@ -4,8 +4,9 @@
notifications:
email: true
go:
- 1.6
- 1.7
- 1.6.x
- 1.7.x
- 1.8.x
- tip
env:
global:
Expand All @@ -18,3 +19,46 @@
- test -z "$(golint ./... | grep -v vendor | tee /dev/stderr)"
- test -z "$(gofmt -s -l . | grep -v vendor | tee /dev/stderr)"
- go test $(go list ./... | grep -v vendor)
- make release
deploy:
provider: releases
api_key:
secure: "Yf3XI7nLyfbd/KLv3trryW+HaXpEsRHpD/5dCFDyBWbsOarGgvXVw8vB470vkxia6aywOUztRM/dV2W3VcpISgaCKQUuvYSA9zV1tUDiwlHCKvoRRhEo1cJe9fgUX4MZpuh/3gSSh3Ja5xg1U83pCQpufryGCJb2hN08rbkcftQKZh4LQy1fB4luzXuk1MgQ4RP0r7sM1pep2xcG9QlB8wKEVilWOBSjMhtV4ybX5s8WsqSGx5z/Cywg+pAS+VpfdPhVQ3mElDYkr3dbFqQk2Zeh/0nxfV+6VVg7mY75lq+uahBMJS1mMTFpdCx66vEWi6Tif1SAGjCWeJVi33/0/CL9Lv9AHivd/8ElWEnA3yQjnvYZwGktm2EKQw/9HA4lPZsKjOwb0DKeSz3aWUIsTt2/lmEoECAxWfyrIv0l3b7FhWCq+ILpN/Da6GoWm8zGZMFZ5urJRiLxnvf/GUo8PWIHIqHa8iUSEl6xcFswtz0C/PX1g8thuKbB/zAzw/v32bYd71MR23BZIxkODlG6sUgTqRWnOcheYGGpHOZZp6bXJ02GmGks07+1HZVojMo5P+CAKvANjHNdf/sSg/TCZcWjrjqH6HivYCJNz8YmC6yigeWqk4aO9Fww4Nk6wSdo+Jsc6Il/0BwBkNvi2vRiVZtWHKfvy4RQ26iaFR2/gV4="
go: 1.8.x
file:
- cross/apk-file-linux-amd64.md5
- cross/apk-file-windows-386.sha256
- cross/apk-file-linux-arm
- cross/apk-file-darwin-amd64.md5
- cross/apk-file-darwin-amd64
- cross/apk-file-solaris-amd64.md5
- cross/apk-file-linux-arm64.sha256
- cross/apk-file-linux-arm.sha256
- cross/apk-file-linux-386.sha256
- cross/apk-file-darwin-386.md5
- cross/apk-file-windows-386.md5
- cross/apk-file-freebsd-amd64.md5
- cross/apk-file-linux-arm64.md5
- cross/apk-file-linux-arm64
- cross/apk-file-freebsd-amd64.sha256
- cross/apk-file-freebsd-386.md5
- cross/apk-file-linux-amd64.sha256
- cross/apk-file-linux-386.md5
- cross/apk-file-freebsd-386
- cross/apk-file-solaris-amd64.sha256
- cross/apk-file-windows-amd64
- cross/apk-file-windows-amd64.md5
- cross/apk-file-windows-amd64.sha256
- cross/apk-file-linux-arm.md5
- cross/apk-file-darwin-386.sha256
- cross/apk-file-darwin-amd64.sha256
- cross/apk-file-windows-386
- cross/apk-file-solaris-amd64
- cross/apk-file-darwin-386
- cross/apk-file-linux-386
- cross/apk-file-freebsd-amd64
- cross/apk-file-freebsd-386.sha256
- cross/apk-file-linux-amd64
skip_cleanup: true
on:
tags: true
123 changes: 104 additions & 19 deletions Makefile
@@ -1,40 +1,125 @@
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)
BUILDTAGS=

.PHONY: clean all fmt vet lint build test install static
.DEFAULT: default
# Setup name variables for the package/tool
NAME := apk-file
PKG := github.com/jessfraz/$(NAME)

all: clean build fmt lint test vet install
# Set any default go build tags
BUILDTAGS :=

build:
# 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)
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 = darwin/amd64 darwin/386 freebsd/amd64 freebsd/386 linux/arm linux/arm64 linux/amd64 linux/386 solaris/amd64 windows/amd64 windows/386

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
@echo "+ $@"
@go build -tags "$(BUILDTAGS) cgo" .
go build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(NAME) .

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

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

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

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

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

clean:
.PHONY: install
install: ## Installs the executable or package
@echo "+ $@"
@rm -rf apk-file
@go install .

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 ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary)
@echo "+ $@"
@go install .
$(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 ## 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: bump-version
BUMP := patch
bump-version: ## Bump the version in the version file. Set KIND to [ patch | major | minor ]
@go get -u github.com/jessfraz/junk/sembump # update sembump tool
$(eval NEW_VERSION = $(shell sembump --kind $(BUMP) $(VERSION)))
@echo "Bumping VERSION from $(VERSION) to $(NEW_VERSION)"
echo $(NEW_VERSION) > VERSION
@echo "Updating links to download binaries in README.md"
sed -i s/$(VERSION)/$(NEW_VERSION)/g README.md
git add VERSION README.md
git commit -vsam "Bump version to $(NEW_VERSION)"
@echo "Run make tag to create and push the tag for new version $(NEW_VERSION)"

.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: 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}'
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -6,6 +6,16 @@ Search apk packages via the command line.

> Basically `apt-file` but for alpine.
## Installation

#### Binaries

- **darwin** [386](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-darwin-386) / [amd64](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-darwin-amd64)
- **freebsd** [386](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-freebsd-386) / [amd64](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-freebsd-amd64)
- **linux** [386](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-linux-386) / [amd64](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-linux-amd64) / [arm](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-linux-arm) / [arm64](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-linux-arm64)
- **solaris** [amd64](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-solaris-amd64)
- **windows** [386](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-windows-386) / [amd64](https://github.com/jessfraz/apk-file/releases/download/v0.1.0/apk-file-windows-amd64)

**Usage**

```console
Expand Down
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
v0.1.0
18 changes: 8 additions & 10 deletions main.go
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/PuerkitoBio/goquery"
"github.com/Sirupsen/logrus"
"github.com/jessfraz/apk-file/version"
)

const (
Expand All @@ -27,9 +28,6 @@ const (
Version: %s
`
// VERSION is the binary version.
VERSION = "v0.1.0"

alpineContentsSearchURI = "https://pkgs.alpinelinux.org/contents"
)

Expand All @@ -41,8 +39,8 @@ var (
arch string
repo string

debug bool
version bool
debug bool
vrsn bool

validArches = []string{"x86", "x86_64", "armhf"}
validRepos = []string{"main", "community", "testing"}
Expand All @@ -53,19 +51,19 @@ func init() {
flag.StringVar(&arch, "arch", "", "arch to search for ("+strings.Join(validArches, ", ")+")")
flag.StringVar(&repo, "repo", "", "repository to search in ("+strings.Join(validRepos, ", ")+")")

flag.BoolVar(&version, "version", false, "print version and exit")
flag.BoolVar(&version, "v", false, "print version and exit (shorthand)")
flag.BoolVar(&vrsn, "version", false, "print version and exit")
flag.BoolVar(&vrsn, "v", false, "print version and exit (shorthand)")
flag.BoolVar(&debug, "d", false, "run in debug mode")

flag.Usage = func() {
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, VERSION))
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, version.VERSION))
flag.PrintDefaults()
}

flag.Parse()

if version {
fmt.Printf("%s", VERSION)
if vrsn {
fmt.Printf("apk-file version %s, build %s", version.VERSION, version.GITCOMMIT)
os.Exit(0)
}

Expand Down
7 changes: 7 additions & 0 deletions version/version.go
@@ -0,0 +1,7 @@
package version

// VERSION indicates which version of the binary is running.
var VERSION string

// GITCOMMIT indicates which git hash the binary was built off of
var GITCOMMIT string

0 comments on commit aa37f2e

Please sign in to comment.