Skip to content

Commit

Permalink
Merge pull request #12 from shogo82148/release-script
Browse files Browse the repository at this point in the history
add build scripts
  • Loading branch information
shogo82148 authored Oct 20, 2019
2 parents 24dbd59 + 04641d1 commit 4de22cc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.mod/
/artifacts/
/release/
80 changes: 78 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,80 @@
.PHONY: test
GOVERSION=$(shell go version)
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
VERSION=$(patsubst "%",%,$(lastword $(shell grep 'const Version' internal/config/version.go)))
ARTIFACTS_DIR=$(CURDIR)/artifacts/$(VERSION)
RELEASE_DIR=$(CURDIR)/release/$(VERSION)
SRC_FILES=$(shell find . -type f -name '*.go')
GITHUB_USERNAME=shogo82148

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

all: build-windows-amd64 build-linux-amd64 build-darwin-amd64 ## Build binaries.

.PHONY: all test clean help

test: ## Run test.
go test -v -race ./...
go vet ./...

clean: ## Remove built files.


##### build settings

.PHONY: build build-windows-amd64 build-linux-amd64 build-darwin-amd64

$(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH):
@mkdir -p $@

$(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH)/rdsmysql$(SUFFIX): $(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH) $(SRC_FILES)
@echo " * Building binary for $(GOOS)/$(GOARCH)..."
@CGO_ENABLED=0 go build -o $@ cmd/rdsmysql/*.go

$(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH)/rdsmysqldump$(SUFFIX): $(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH) $(SRC_FILES)
@echo " * Building binary for $(GOOS)/$(GOARCH)..."
@CGO_ENABLED=0 go build -o $@ cmd/rdsmysqldump/*.go

build: $(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH)/rdsmysql$(SUFFIX) $(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH)/rdsmysqldump$(SUFFIX)

build-windows-amd64:
@$(MAKE) build GOOS=windows GOARCH=amd64 SUFFIX=.exe

build-linux-amd64:
@$(MAKE) build GOOS=linux GOARCH=amd64

build-darwin-amd64:
@$(MAKE) build GOOS=darwin GOARCH=amd64


##### release settings

.PHONY: release-windows-amd64 release-linux-amd64 release-darwin-amd64
.PHONY: release-targz release-zip release-files release-upload

$(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH):
@mkdir -p $@

release-windows-amd64:
@$(MAKE) release-zip GOOS=windows GOARCH=amd64 SUFFIX=.exe

release-linux-amd64:
@$(MAKE) release-targz GOOS=linux GOARCH=amd64

release-darwin-amd64:
@$(MAKE) release-targz GOOS=darwin GOARCH=amd64

release-targz: build $(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH)
@echo " * Creating tar.gz for $(GOOS)/$(GOARCH)"
tar -czf $(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH).tar.gz -C $(ARTIFACTS_DIR) rdsmysql_$(GOOS)_$(GOARCH)

release-zip: build $(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH)
@echo " * Creating zip for $(GOOS)/$(GOARCH)"
cd $(ARTIFACTS_DIR) && zip -9 $(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH).zip rdsmysql_$(GOOS)_$(GOARCH)/*

release-files: release-windows-amd64 release-linux-amd64 release-darwin-amd64

release-upload: release-files
ghr -u $(GITHUB_USERNAME) --draft --replace v$(VERSION) $(RELEASE_DIR)
4 changes: 4 additions & 0 deletions internal/config/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package config

// Version is the version of rdsmysql command.
const Version = "1.0.0"
9 changes: 9 additions & 0 deletions run-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

CURRENT=$(cd "$(dirname "$0")" && pwd)
docker run --rm -it \
-e GO111MODULE=on \
-e "GOOS=${GOOS:-linux}" -e "GOARCH=${GOARCH:-amd64}" -e "CGO_ENABLED=${CGO_ENABLED:-0}" \
-v "$CURRENT":/go/src/github.com/shogo82148/rdsmysql \
-v "$CURRENT/.mod":/go/pkg/mod \
-w /go/src/github.com/shogo82148/rdsmysql golang:1.13.2 "$@"

0 comments on commit 4de22cc

Please sign in to comment.