-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Makefile and version command.
- Loading branch information
Showing
9 changed files
with
314 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
SHELL=/bin/sh -e | ||
NAME=kev | ||
AUTHOR=appvia | ||
AUTHOR_EMAIL[email protected] | ||
BUILD_TIME=$(shell date '+%s') | ||
CURRENT_TAG=$(shell git tag --points-at HEAD) | ||
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) | ||
GIT_SHA=$(shell git --no-pager describe --always --dirty) | ||
GIT_LAST_TAG_SHA=$(shell git rev-list --tags='v[0.9]*.[0-9]*.[0-9]*' --max-count=1) | ||
GIT_LAST_TAG=$(shell git describe --tags $(GIT_LAST_TAG_SHA)) | ||
HARDWARE=$(shell uname -m) | ||
PACKAGES=$(shell go list ./...) | ||
VETARGS ?= -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -unsafeptr | ||
ifeq ($(USE_GIT_VERSION),true) | ||
ifeq ($(CURRENT_TAG),) | ||
VERSION ?= $(GIT_LAST_TAG)-$(GIT_SHA) | ||
else | ||
VERSION ?= $(CURRENT_TAG) | ||
endif | ||
else | ||
VERSION ?= $(GIT_LAST_TAG) | ||
endif | ||
LFLAGS ?= -X github.com/appvia/kube-devx/pkg/version.Tag=${GIT_LAST_TAG} -X github.com/appvia/kube-devx/pkg/version.GitSHA=${GIT_SHA} -X github.com/appvia/kube-devx/pkg/version.Compiled=${BUILD_TIME} -X github.com/appvia/kube-devx/pkg/version.Release=${VERSION} -X github.com/appvia/kube-devx/pkg/version.GitBranch=${GIT_BRANCH} | ||
CLI_PLATFORMS=darwin linux windows | ||
CLI_ARCHITECTURES=386 amd64 | ||
export GOFLAGS = -mod=vendor | ||
|
||
.PHONY: test authors changelog build release check vet golangci-lint | ||
|
||
default: build | ||
|
||
golang: | ||
@echo "--> Go Version" | ||
@go version | ||
@echo "GOFLAGS: $$GOFLAGS" | ||
|
||
build: golang | ||
@echo "--> Compiling the project ($(VERSION))" | ||
@mkdir -p bin | ||
go build -ldflags "${LFLAGS}" -tags=jsoniter -o bin/${NAME} cmd/${NAME}/*.go || exit 1; | ||
|
||
package: | ||
@rm -rf ./release | ||
@mkdir ./release | ||
@$(MAKE) package-cli | ||
cd ./release && sha256sum * > kev.sha256sums | ||
|
||
package-cli: | ||
@echo "--> Compiling CLI static binaries" | ||
CGO_ENABLED=0 go run github.com/mitchellh/gox -parallel=4 -arch="${CLI_ARCHITECTURES}" -os="${CLI_PLATFORMS}" -ldflags "-w ${LFLAGS}" -output=./release/{{.Dir}}-cli-{{.OS}}-{{.Arch}} ./cmd/${NAME}/ | ||
|
||
push-release-packages: | ||
@echo "--> Pushing compiled CLI binaries to draft release (requires github token set in .gitconfig or GITHUB_TOKEN env variable)" | ||
go run github.com/tcnksm/ghr -replace -draft -n "Release ${VERSION}" "${VERSION}" ./release | ||
|
||
release: build | ||
mkdir -p release | ||
gzip -c bin/${NAME} > release/${NAME}_${VERSION}_linux_${HARDWARE}.gz | ||
rm -f release/${NAME} | ||
|
||
clean: | ||
@echo "--> Cleaning up the environment" | ||
rm -rf ./bin 2>/dev/null | ||
rm -rf ./release 2>/dev/null | ||
|
||
authors: | ||
@echo "--> Updating the AUTHORS" | ||
git log --format='%aN <%aE>' | sort -u > AUTHORS | ||
|
||
vet: | ||
@echo "--> Running go vet $(VETARGS) $(PACKAGES)" | ||
@go vet $(VETARGS) $(PACKAGES) | ||
|
||
gofmt: | ||
@echo "--> Running gofmt check" | ||
@if gofmt -s -l $$(go list -f '{{.Dir}}' ./...) | grep -q \.go ; then \ | ||
echo "You need to run the make format, we have file unformatted"; \ | ||
gofmt -s -l $$(go list -f '{{.Dir}}' ./...); \ | ||
exit 1; \ | ||
fi | ||
|
||
format: | ||
@echo "--> Running go fmt" | ||
@gofmt -s -w $$(go list -f '{{.Dir}}' ./...) | ||
|
||
bench: | ||
@echo "--> Running go bench" | ||
@go test -bench=. -benchmem | ||
|
||
verify-licence: | ||
@echo "--> Verifying the licence headers" | ||
@hack/verify-licence.sh | ||
|
||
coverage: | ||
@echo "--> Running go coverage" | ||
@go test -coverprofile cover.out | ||
@go tool cover -html=cover.out -o cover.html | ||
|
||
spelling: | ||
@echo "--> Checking the spelling" | ||
@find . -name "*.go" -type f -not -path "./vendor/*" -not -path "./ui/node_modules/*" | xargs go run github.com/client9/misspell/cmd/misspell -error -source=go *.go | ||
@find . -name "*.md" -type f -not -path "./vendor/*" -not -path "./ui/node_modules/*" | xargs go run github.com/client9/misspell/cmd/misspell -error -source=text *.md | ||
|
||
golangci-lint: | ||
@echo "--> Checking against the golangci-lint" | ||
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout 5m -j 2 ./... | ||
|
||
check: | ||
@echo "--> Running code checkers" | ||
@$(MAKE) golang | ||
@$(MAKE) gofmt | ||
@$(MAKE) golangci-lint | ||
@$(MAKE) spelling | ||
@$(MAKE) vet | ||
@$(MAKE) verify-licences | ||
@$(MAKE) check-generate-assets | ||
|
||
test: | ||
@echo "--> Running the tests" | ||
@go test --cover -v $(PACKAGES) | ||
|
||
all: test | ||
@echo "--> Performing all tests" | ||
@$(MAKE) bench | ||
@$(MAKE) coverage | ||
|
||
changelog: release | ||
git log $(shell git tag | tail -n1)..HEAD --no-merges --format=%B >> changelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright 2020 Appvia Ltd <[email protected]> | ||
* | ||
* 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. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/appvia/kube-devx/pkg/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print Kev version", | ||
Long: `All software has versions. This is Kev's`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(version.Version()) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.