From ccda0eae939e3b7934048951b0f41bba31a84c88 Mon Sep 17 00:00:00 2001 From: y_uuki Date: Mon, 17 Jun 2019 12:58:45 +0900 Subject: [PATCH 1/3] Modernize release scripts --- .travis.yml | 2 +- Dockerfile | 13 ++++++----- Makefile | 43 +++++++++++++++++++++++++----------- _tools/credits | 39 ++++++++++++++++++++++++++++++++ _tools/release | 21 ++++++++++++++++++ _tools/upload_artifacts | 6 +++++ script/build_in_container.sh | 20 ----------------- script/build_release.sh | 15 ------------- script/release.sh | 27 ---------------------- 9 files changed, 104 insertions(+), 82 deletions(-) create mode 100755 _tools/credits create mode 100755 _tools/release create mode 100755 _tools/upload_artifacts delete mode 100755 script/build_in_container.sh delete mode 100755 script/build_release.sh delete mode 100755 script/release.sh diff --git a/.travis.yml b/.travis.yml index d4d2784..88fd843 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: false language: go go: - - 1.10.x + - 1.12 script: - make test diff --git a/Dockerfile b/Dockerfile index 345e2c2..934f5e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ -FROM golang:1.10 +FROM golang:1.12 -RUN go get github.com/laher/goxc +RUN mkdir -p /src +WORKDIR /src +COPY go.mod . +COPY go.sum . -ENV USER root -WORKDIR /go/src/github.com/yuuki/gokc - -ADD . /go/src/github.com/yuuki/gokc +RUN go mod download +COPY . . diff --git a/Makefile b/Makefile index bd4bc63..11ac0d9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,10 @@ -BIN := gokc +export GO111MODULE=on + +PKG = github.com/yuuki/gokc +COMMIT = $$(git describe --tags --always) +DATE = $$(date --utc '+%Y-%m-%d_%H:%M:%S') +BUILD_LDFLAGS = -X $(PKG).commit=$(COMMIT) -X $(PKG).date=$(DATE) +RELEASE_BUILD_LDFLAGS = -s -w $(BUILD_LDFLAGS) all: build @@ -6,10 +12,8 @@ yacc: deps goyacc -o parser/parser.go -v parser/parser.output parser/parser.go.y build: yacc - go build -o $(BIN) ./cmd/... - -buildlinux: yacc - GOOS=linux GOARCH=amd64 make build + go build -o $(BIN) + go build -ldflags="$(BUILD_LDFLAGS)" $(PKG)/cmd/... test: yacc go test -v $$(go list ./... | grep -v vendor) @@ -18,19 +22,32 @@ testfiles: build find ./testdata -type f | xargs -I{} ./$(BIN) -f {} find ./keepalived/doc/samples/keepalived.conf.* -type f | xargs -I{} ./$(BIN) -f {} -patch: gobump - ./script/release.sh patch - -minor: gobump - ./script/release.sh minor - -gobump: - go get github.com/motemen/gobump/cmd/gobump +.PHONY: devel-deps +devel-deps: + GO111MODULE=off go get -v \ + golang.org/x/tools/cmd/cover \ + github.com/mattn/goveralls \ + github.com/motemen/gobump/cmd/gobump \ + github.com/Songmu/ghch/cmd/ghch \ + github.com/Songmu/goxz/cmd/goxz \ + github.com/tcnksm/ghr \ + github.com/Songmu/gocredits/cmd/gocredits deps: go get golang.org/x/tools/cmd/goyacc go get -d -v ./... +.PHONY: crossbuild +crossbuild: devel-deps + $(eval ver = $(shell gobump show -r)) + goxz -pv=v$(ver) -os=linux,darwin -arch=386,amd64 -build-ldflags="$(RELEASE_BUILD_LDFLAGS)" \ + -d=./dist/v$(ver) + +.PHONY: release +release: devel-deps + _tools/release + _tools/upload_artifacts + clean: go clean diff --git a/_tools/credits b/_tools/credits new file mode 100755 index 0000000..a37d15b --- /dev/null +++ b/_tools/credits @@ -0,0 +1,39 @@ +#!/bin/bash +set -e -o pipefail + +ROOT=$(dirname "${BASH_SOURCE}")/.. +cd "${ROOT}" + +echo '==========================================================================================' +echo "= lstf licensed under: =" +echo "https://github.com/yuuki/lstf/" +echo +cat "${ROOT}"/LICENSE +echo +echo "= LICENSE $(cat ${ROOT}/LICENSE | md5sum | awk '{print $1}')" +echo '==========================================================================================' +echo + +echo "= Go (the standard library) licensed under: =" +echo "https://golang.org/" +echo +curl -sS https://raw.githubusercontent.com/golang/go/release-branch.go1.9/LICENSE 2>/dev/null +echo +echo '==========================================================================================' +echo + +find_names=(-iname 'licen[sc]e*') +for repo in $(dep status -json | jq -rM '.[].ProjectRoot'); do + echo + echo '==========================================================================================' + echo "= vendor/${repo} licensed under: =" + echo "https://${repo}/" + for lic in $(find vendor/${repo} -xdev -follow -maxdepth 1 -type f "${find_names[@]}"); do + echo + cat "${lic}" + echo + echo "= ${lic} $(cat ${lic} | md5sum | awk '{print $1}')" + done + echo '==========================================================================================' + echo +done diff --git a/_tools/release b/_tools/release new file mode 100755 index 0000000..22fb78f --- /dev/null +++ b/_tools/release @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +if [[ $(git status -s) != "" ]]; then + echo 2>&1 "git is currently in a dirty state" + exit 1 +fi + +current_version=$(gobump show -r) + +echo "current version: $current_version" +read -p "input next version: " next_version + +echo "--> Bumping version $next_version" +gobump set "$next_version" -w +echo "--> Generating CHANGELOG" +ghch -w -N "v$next_version" + +git commit -am "Bump version $next_version" +git tag "v$next_version" +git push && git push --tags \ No newline at end of file diff --git a/_tools/upload_artifacts b/_tools/upload_artifacts new file mode 100755 index 0000000..f2db036 --- /dev/null +++ b/_tools/upload_artifacts @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +ver=v$(gobump show -r) +make crossbuild +ghr -username yuuki -replace ${ver} dist/${ver} \ No newline at end of file diff --git a/script/build_in_container.sh b/script/build_in_container.sh deleted file mode 100755 index a2aebd9..0000000 --- a/script/build_in_container.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -set -e - -DOCKER_IMAGE_NAME="gokc-build" -DOCKER_CONTAINER_NAME="gokc-build-container" - -if [[ $(docker ps -a | grep $DOCKER_CONTAINER_NAME) != "" ]]; then - docker rm -f $DOCKER_CONTAINER_NAME 2>/dev/null -fi - -docker build -t $DOCKER_IMAGE_NAME . - -docker run --volume "$GOPATH"/src/:/go/src/ -e GOOS=$GOOS -e GOARCH=$GOARCH --name $DOCKER_CONTAINER_NAME $DOCKER_IMAGE_NAME "$@" - -if [[ "$@" == *"clean"* ]] && [[ -d bin ]]; then - rm -Rf bin -fi - -docker cp $DOCKER_CONTAINER_NAME:/go/src/github.com/yuuki/gokc/gokc . diff --git a/script/build_release.sh b/script/build_release.sh deleted file mode 100755 index 8b0b8a3..0000000 --- a/script/build_release.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -e - -NAME="gokc" - -ROOT=$(dirname $0)/.. - -goxc -tasks='xc archive' -bc 'linux,!arm windows darwin' -d . -cp -p "$ROOT"/snapshot/linux_amd64/"$NAME" "$ROOT"/snapshot/"$NAME"_linux_amd64 -cp -p "$ROOT"/snapshot/linux_386/"$NAME" "$ROOT"/snapshot/"$NAME"_linux_386 -cp -p "$ROOT"/snapshot/darwin_amd64/"$NAME" "$ROOT"/snapshot/"$NAME"_darwin_amd64 -cp -p "$ROOT"/snapshot/darwin_386/"$NAME" "$ROOT"/snapshot/"$NAME"_darwin_386 -cp -p "$ROOT"/snapshot/windows_amd64/"$NAME".exe "$ROOT"/snapshot/"$NAME"_windows_amd64.exe -cp -p "$ROOT"/snapshot/windows_386/"$NAME".exe "$ROOT"/snapshot/"$NAME"_windows_386.exe diff --git a/script/release.sh b/script/release.sh deleted file mode 100755 index 0c3a4ba..0000000 --- a/script/release.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -set -e - -if [ -z "$1" ]; then - echo "required patch/minor/major" 1>&2 - exit 1 -fi - -ROOT=$(dirname $0)/.. - -# gofmt -gofmt -s -w . -git add ./*.go -git commit -m "gofmt" || true # ignore no changes error - -# gobump -new_version=$(gobump "$1" -w -v cmd/gokc | jq -r '.[]') -git add ./*.go -git commit -m "Bump version $new_version" -git push origin master - -# build release files -"$ROOT"/script/build_in_container.sh "$ROOT"/script/build_release.sh - -# make github release draft -ghr --username yuuki --replace --draft "v$new_version" snapshot/ From e9692eaf85d0414d76ce696507bbf784b6ad7ce6 Mon Sep 17 00:00:00 2001 From: y_uuki Date: Mon, 17 Jun 2019 13:02:12 +0900 Subject: [PATCH 2/3] go mod --- go.mod | 8 ++++++++ go.sum | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c92f94b --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/yuuki/gokc + +go 1.12 + +require ( + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db + golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d968aa6 --- /dev/null +++ b/go.sum @@ -0,0 +1,9 @@ +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59 h1:QjA/9ArTfVTLfEhClDCG7SGrZkZixxWpwNCDiwJfh88= +golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= From 421460f30fa6761134cb5ef525bf83b69b5e0509 Mon Sep 17 00:00:00 2001 From: y_uuki Date: Mon, 17 Jun 2019 13:03:02 +0900 Subject: [PATCH 3/3] Add version.go --- Makefile | 1 - cmd/gokc/gokc.go | 2 +- cmd/gokc/version.go | 12 +++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 11ac0d9..983eb1f 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,6 @@ yacc: deps goyacc -o parser/parser.go -v parser/parser.output parser/parser.go.y build: yacc - go build -o $(BIN) go build -ldflags="$(BUILD_LDFLAGS)" $(PKG)/cmd/... test: yacc diff --git a/cmd/gokc/gokc.go b/cmd/gokc/gokc.go index 5dcede1..3f6133a 100644 --- a/cmd/gokc/gokc.go +++ b/cmd/gokc/gokc.go @@ -43,7 +43,7 @@ func main() { flag.Parse() if isVersion { - log.Infof("gokc version %s", Version) + log.Infof("gokc version %s", version) os.Exit(0) } diff --git a/cmd/gokc/version.go b/cmd/gokc/version.go index 7b43d89..92a1c7c 100644 --- a/cmd/gokc/version.go +++ b/cmd/gokc/version.go @@ -1,3 +1,13 @@ package main -var Version string = "0.4.2" +// name is application name. +const name = "gokc" + +// version is application version. +const version = "0.4.2" + +// commit describes latest git commit hash. +// This is automatically extracted by git describe --always. +var commit string + +var date string