diff --git a/Makefile b/Makefile index b8c6600..9f6c1a3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,17 @@ +# Copyright © 2019 cloud.ca Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # Project variables ORG := cloud-ca NAME := cca @@ -33,8 +47,8 @@ GOBUILD ?= GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 $(GOCMD) build $(MODV GORUN ?= GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOCMD) run $(MODVENDOR) # Binary versions -GOLANGCI_VERSION := v1.17.1 GITCHGLOG_VERSION := 0.8.0 +GOLANGCI_VERSION := v1.17.1 .PHONY: default default: help @@ -66,19 +80,20 @@ verify: ## Verify 'vendor' dependencies $(GOCMD) mod verify .PHONY: lint +lint: SHELL := /usr/bin/env bash lint: ## Run linter @ $(MAKE) --no-print-directory log-$@ GO111MODULE=on golangci-lint run ./... .PHONY: fmt -fmt: ## Format all go files +fmt: ## Format go files @ $(MAKE) --no-print-directory log-$@ goimports -w $(GOFILES) .PHONY: checkfmt checkfmt: RESULT = $(shell goimports -l $(GOFILES) | tee >(if [ "$$(wc -l)" = 0 ]; then echo "OK"; fi)) -checkfmt: SHELL := /bin/bash -checkfmt: ## Check formatting of all go files +checkfmt: SHELL := /usr/bin/env bash +checkfmt: ## Check formatting of go files @ $(MAKE) --no-print-directory log-$@ @ echo "$(RESULT)" @ if [ "$(RESULT)" != "OK" ]; then exit 1; fi @@ -98,7 +113,7 @@ build: clean ## Build binary for current OS/ARCH @ $(MAKE) --no-print-directory log-$@ $(GOBUILD) -o ./$(BUILD_DIR)/$(GOOS)-$(GOARCH)/$(NAME) @ if [ $(compress) = "true" ]; then \ - ./hack/build/compress.sh "$(NAME)" "$(VERSION)" ; \ + ./scripts/build/compress.sh "$(NAME)" "$(VERSION)" ; \ fi .PHONY: build-all @@ -116,7 +131,7 @@ build-all: clean ## Build binary for all OS/ARCH -output="$(BUILD_DIR)/{{.OS}}-{{.Arch}}/{{.Dir}}" . @ if [ $(compress) = "true" ]; then \ - ./hack/build/compress.sh "$(NAME)" "$(VERSION)" ; \ + ./scripts/build/compress.sh "$(NAME)" "$(VERSION)" ; \ fi ##################### @@ -127,29 +142,18 @@ PATTERN = release: version ?= $(shell echo $(VERSION) | sed 's/^v//' | awk -F'[ .]' '{print $(PATTERN)}') release: push ?= false -release: ## Prepare Module release +release: ## Prepare release @ $(MAKE) --no-print-directory log-$@ - @ if [ -z "$(version)" ]; then \ - echo "Error: missing value for 'version'. e.g. 'make release version=x.y.z'" ; \ - elif [ "v$(version)" = "$(VERSION)" ] ; then \ - echo "Error: provided version (v$(version)) exists." ; \ - else \ - git tag --annotate --message "v$(version) Release" v$(version) ; \ - echo "Tag v$(version) Release" ; \ - if [ $(push) = "true" ]; then \ - git push origin v$(version) ; \ - echo "Push v$(version) Release" ; \ - fi \ - fi + @ ./scripts/release/release.sh "$(version)" "$(push)" "$(VERSION)" "1" patch: PATTERN = '\$$1\".\"\$$2\".\"\$$3+1' -patch: release ## Prepare Module Patch release +patch: release ## Prepare Patch release minor: PATTERN = '\$$1\".\"\$$2+1\".0\"' -minor: release ## Prepare Module Minor release +minor: release ## Prepare Minor release major: PATTERN = '\$$1+1\".0.0\"' -major: release ## Prepare Module Major release +major: release ## Prepare Major release #################### ## Helper targets ## @@ -159,21 +163,32 @@ authors: ## Generate Authors git log --all --format='%aN <%aE>' | sort -u | egrep -v noreply > AUTHORS .PHONY: changelog +changelog: push ?= false changelog: ## Generate Changelog - git-chglog --config hack/chglog --output CHANGELOG.md - -.PHONY: goimports -goimports: ## Install goimports @ $(MAKE) --no-print-directory log-$@ + git-chglog --config ./scripts/chglog/config-full-history.yml --output CHANGELOG.md + @ git add CHANGELOG.md + @ git commit -m "Update Changelog" + @ if $(push) = "true"; then git push origin master; fi + +.PHONY: tools git-chglog goimports golangci gox + +git-chglog: + curl -sfL https://github.com/git-chglog/git-chglog/releases/download/$(GITCHGLOG_VERSION)/git-chglog_$(shell go env GOOS)_$(shell go env GOARCH) -o $(shell go env GOPATH)/bin/git-chglog && chmod +x $(shell go env GOPATH)/bin/git-chglog + +goimports: GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports -.PHONY: tools -tools: ## Install required tools - @ $(MAKE) --no-print-directory log-$@ +golangci: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION) - curl -sfL https://github.com/git-chglog/git-chglog/releases/download/$(GITCHGLOG_VERSION)/git-chglog_$(shell go env GOOS)_$(shell go env GOARCH) -o $(shell go env GOPATH)/bin/git-chglog && chmod +x $(shell go env GOPATH)/bin/git-chglog + +gox: GO111MODULE=off go get -u github.com/mitchellh/gox +tools: ## Install required tools + @ $(MAKE) --no-print-directory log-$@ + @ $(MAKE) --no-print-directory git-chglog goimports golangci gox + #################################### ## Self-Documenting Makefile Help ## #################################### diff --git a/hack/chglog/config.yml b/hack/chglog/config.yml deleted file mode 100755 index 212a250..0000000 --- a/hack/chglog/config.yml +++ /dev/null @@ -1,13 +0,0 @@ -style: github -template: CHANGELOG.tpl.md -info: - title: CHANGELOG - repository_url: https://github.com/cloud-ca/cca -options: - header: - pattern: "^(.*)$" - pattern_maps: - - Subject - notes: - keywords: - - BREAKING CHANGE diff --git a/hack/build/compress.sh b/scripts/build/compress.sh similarity index 72% rename from hack/build/compress.sh rename to scripts/build/compress.sh index f44d4af..bad03a1 100755 --- a/hack/build/compress.sh +++ b/scripts/build/compress.sh @@ -1,6 +1,22 @@ #!/usr/bin/env bash - -set -e +# +# Copyright © 2019 cloud.ca Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail NAME=$1 VERSION=$2 diff --git a/hack/chglog/CHANGELOG.tpl.md b/scripts/chglog/CHANGELOG-full-history.tpl.md similarity index 69% rename from hack/chglog/CHANGELOG.tpl.md rename to scripts/chglog/CHANGELOG-full-history.tpl.md index 3d1b032..8040408 100755 --- a/hack/chglog/CHANGELOG.tpl.md +++ b/scripts/chglog/CHANGELOG-full-history.tpl.md @@ -1,4 +1,4 @@ -# CHANGELOG +# Changelog {{ if .Versions -}} @@ -7,12 +7,12 @@ {{ range .Unreleased.CommitGroups -}} ### {{ .Title }} {{ range .Commits -}} -- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }} {{ end }} {{ end -}} {{ else }} {{ range .Unreleased.Commits -}} -- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }} {{ end }} {{ end -}} {{ end -}} @@ -24,12 +24,12 @@ {{ range .CommitGroups -}} ### {{ .Title }} {{ range .Commits -}} -- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }} {{ end }} {{ end -}} {{ else }} {{ range .Commits -}} -- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }} {{ end }} {{ end -}} @@ -50,4 +50,4 @@ [{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }} {{ end -}} {{ end -}} -{{ end -}} \ No newline at end of file +{{ end -}} diff --git a/scripts/chglog/CHANGELOG-release-note.tpl.md b/scripts/chglog/CHANGELOG-release-note.tpl.md new file mode 100755 index 0000000..14e506a --- /dev/null +++ b/scripts/chglog/CHANGELOG-release-note.tpl.md @@ -0,0 +1,16 @@ +## Changelog + +{{ if .Versions -}} +{{ if .Unreleased.CommitGroups -}} +{{ range .Unreleased.CommitGroups -}} +### {{ .Title }} +{{ range .Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }} +{{ end }} +{{ end -}} +{{ else }} +{{ range .Unreleased.Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ if .Subject }}{{ .Subject }}{{ else }}{{ .Header }}{{ end }} +{{ end }} +{{ end -}} +{{ end -}} diff --git a/scripts/chglog/config-full-history.yml b/scripts/chglog/config-full-history.yml new file mode 100755 index 0000000..0ab3040 --- /dev/null +++ b/scripts/chglog/config-full-history.yml @@ -0,0 +1,31 @@ +style: github +template: CHANGELOG-full-history.tpl.md +info: + title: CHANGELOG + repository_url: https://github.com/cloud-ca/cca +options: + commits: + filters: + Type: + - doc + - enhance + - feat + - fix + - perf + - refactor + commit_groups: + title_maps: + doc: Documentation + enhance: Enhancements + feat: Features + fix: Bug Fixes + perf: Performance Improvements + refactor: Code Refactoring + header: + pattern: "^(\\w*)\\:\\s(.*)$" + pattern_maps: + - Type + - Subject + notes: + keywords: + - BREAKING CHANGE diff --git a/scripts/chglog/config-release-note.yml b/scripts/chglog/config-release-note.yml new file mode 100755 index 0000000..eb57dea --- /dev/null +++ b/scripts/chglog/config-release-note.yml @@ -0,0 +1,31 @@ +style: github +template: CHANGELOG-release-note.tpl.md +info: + title: CHANGELOG + repository_url: https://github.com/cloud-ca/cca +options: + commits: + filters: + Type: + - doc + - enhance + - feat + - fix + - perf + - refactor + commit_groups: + title_maps: + doc: Documentation + enhance: Enhancements + feat: Features + fix: Bug Fixes + perf: Performance Improvements + refactor: Code Refactoring + header: + pattern: "^(\\w*)?\\:\\s(.*)$" + pattern_maps: + - Type + - Subject + notes: + keywords: + - BREAKING CHANGE diff --git a/scripts/release/release-note.sh b/scripts/release/release-note.sh new file mode 100755 index 0000000..b2c8047 --- /dev/null +++ b/scripts/release/release-note.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Copyright © 2019 cloud.ca Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +PWD=$(cd $(dirname "$0") && pwd -P) + +# Find closest tag +CLOSEST_VERSION=$(git describe --tags --abbrev=0) + +# Install git-chglog binary +if ! command -v git-chglog >/dev/null ; then + make git-chglog +fi + +# Generate Changelog +git-chglog --config ${PWD}/../../scripts/chglog/config-release-note.yml --output ${PWD}/../../CURRENT-RELEASE-CHANGELOG.md ${CLOSEST_VERSION} + +cat ${PWD}/../../CURRENT-RELEASE-CHANGELOG.md diff --git a/scripts/release/release.sh b/scripts/release/release.sh new file mode 100755 index 0000000..daedd93 --- /dev/null +++ b/scripts/release/release.sh @@ -0,0 +1,94 @@ +#!/usr/bin/env bash +# +# Copyright © 2019 cloud.ca Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o pipefail + +NEW_VERSION=$1 +PUSH=$2 +CURRENT_VERSION=$3 +MAKEFILE=$4 + +if [ -z "${NEW_VERSION}" ]; then + if [ -z "${MAKEFILE}" ]; then + echo "Error: VERSION is missing. e.g. ./release.sh " + else + echo "Error: missing value for 'version'. e.g. 'make release version=x.y.z'" + fi + exit 1 +fi + +if [ -z "${PUSH}" ]; then + echo "Error: PUSH is missing. e.g. ./release.sh " + exit 1 +fi + +if [ -z "${CURRENT_VERSION}" ]; then + CURRENT_VERSION=$(git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.1-$(COMMIT_HASH)") +fi + +if [ "v${NEW_VERSION}" = "${CURRENT_VERSION}" ]; then + echo "Error: provided version (v${version}) exists." + exit 1 +fi + +PWD=$(cd $(dirname "$0") && pwd -P) +CLOSEST_VERSION=$(git describe --tags --abbrev=0) + +# Bump the released version in README and version.go +sed -i -E 's|'${CLOSEST_VERSION}'|v'${NEW_VERSION}'|g' README.md +sed -i -E 's|'${CLOSEST_VERSION}'-alpha|v'${NEW_VERSION}'|g' cmd/cca/version/version.go + +# Commit changes +printf "\033[36m==> %s\033[0m\n" "Commit changes for release version v${NEW_VERSION}" +git add README.md cmd/cca/version/version.go +git commit -m "Release version v${NEW_VERSION}" + +if [ "${PUSH}" == "true" ]; then + printf "\033[36m==> %s\033[0m\n" "Push commits for v${NEW_VERSION}" + git push origin master +fi + +# Tag the release +git tag --annotate --message "v${NEW_VERSION} Release" "v${NEW_VERSION}" + +# Generate Changelog +make --no-print-directory -f ${PWD}/../../Makefile changelog push="${PUSH}" + +git tag -d "v${NEW_VERSION}" + +# Tag the release +printf "\033[36m==> %s\033[0m\n" "Tag release v${NEW_VERSION}" +git tag --annotate --message "v${NEW_VERSION} Release" "v${NEW_VERSION}" + +if [ "${PUSH}" == "true" ]; then + printf "\033[36m==> %s\033[0m\n" "Push tag release v${NEW_VERSION}" + git push origin v${NEW_VERSION} +fi + +# Bump the next version in version.go +NEXT_VERSION=$(echo "${NEW_VERSION}" | sed 's/^v//' | awk -F'[ .]' '{print $1"."$2+1".0"}') +sed -i -E 's|'${NEW_VERSION}'|'${NEXT_VERSION}'-alpha|g' cmd/cca/version/version.go + +# Commit changes +printf "\033[36m==> %s\033[0m\n" "Bump version to ${NEXT_VERSION}-alpha" +git add cmd/cca/version/version.go +git commit -m "Bump version to ${NEXT_VERSION}-alpha" + +if [ "${PUSH}" == "true" ]; then + printf "\033[36m==> %s\033[0m\n" "Push commits for ${NEXT_VERSION}-alpha" + git push origin master +fi