From cd242a95485ace62dbdf959205d58796ae7f2aa1 Mon Sep 17 00:00:00 2001 From: James Ranson Date: Fri, 5 Mar 2021 15:25:32 -0700 Subject: [PATCH] add makefile, spell check artifacts and gitignore --- .gitignore | 18 ++++++++ Makefile | 91 +++++++++++++++++++++++++++++++++++++++ tricktool.go => main.go | 5 ++- testdata/ignore_words.txt | 0 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 Makefile rename tricktool.go => main.go (79%) create mode 100644 testdata/ignore_words.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d8ff46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ + +# IDE Files +.vscode/ +.idea/ + +# output path +OPATH + +# MacOS and other operating system artifacts +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..60d27e8 --- /dev/null +++ b/Makefile @@ -0,0 +1,91 @@ +# Copyright 2018 Comcast Cable Communications Management, LLC +# 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. + +DEFAULT: build + +PROJECT_DIR := $(shell pwd) +GO ?= go +GOFMT ?= $(GO)fmt +FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) +TRICKTOOL := $(FIRST_GOPATH)/bin/tricktool +PROGVER := $(shell grep 'applicationVersion = ' ./main.go | awk '{print $$4}' | sed -e 's/\"//g') +BUILD_TIME := $(shell date -u +%FT%T%z) +GIT_LATEST_COMMIT_ID := $(shell git rev-parse HEAD) +GO_VER := $(shell go version | awk '{print $$3}') +IMAGE_TAG ?= latest +IMAGE_ARCH ?= amd64 +GOARCH ?= amd64 +TAGVER ?= unspecified +LDFLAGS =-ldflags "-extldflags '-static' -w -s" +BUILD_SUBDIR := OPATH +PACKAGE_DIR := ./$(BUILD_SUBDIR)/tricktool-$(PROGVER) +BIN_DIR := $(PACKAGE_DIR)/bin +CGO_ENABLED ?= 0 + +.PHONY: spelling +spelling: + @codespell --skip="vendor,*.git,*.png,*.pdf,*.tiff,*.plist,*.pem,rangesim*.go,*.gz" --ignore-words="./testdata/ignore_words.txt" -q 3 + +.PHONY: validate-app-version +validate-app-version: + @if [ "$(PROGVER)" != $(TAGVER) ]; then\ + (echo "mismatch between TAGVER '$(TAGVER)' and applicationVersion '$(PROGVER)'"; exit 1);\ + fi + +.PHONY: go-mod-vendor +go-mod-vendor: + $(GO) mod vendor + +.PHONY: go-mod-tidy +go-mod-tidy: + $(GO) mod tidy + +.PHONY: test-go-mod +test-go-mod: + @git diff --quiet --exit-code go.mod go.sum || echo "There are changes to go.mod and go.sum which needs to be committed" + +.PHONY: build +build: go-mod-tidy go-mod-vendor + GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(LDFLAGS) -o ./$(BUILD_SUBDIR)/tricktool -a -v ./*.go + +.PHONY: release +release: validate-app-version clean go-mod-tidy go-mod-vendor release-artifacts + +.PHONY: release-artifacts +release-artifacts: clean + + mkdir -p $(PACKAGE_DIR) + mkdir -p $(BIN_DIR) + + cp ./README.md $(PACKAGE_DIR) + cp ./CONTRIBUTING.md $(PACKAGE_DIR) + cp ./LICENSE $(PACKAGE_DIR) + + GOOS=darwin GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(LDFLAGS) -o $(BIN_DIR)/tricktool-$(PROGVER).darwin-amd64 -a -v ./*.go + GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(LDFLAGS) -o $(BIN_DIR)/tricktool-$(PROGVER).linux-amd64 -a -v ./*.go + GOOS=linux GOARCH=arm64 CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(LDFLAGS) -o $(BIN_DIR)/tricktool-$(PROGVER).linux-arm64 -a -v ./*.go + GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(LDFLAGS) -o $(BIN_DIR)/tricktool-$(PROGVER).windows-amd64 -a -v ./*.go + + cd ./$(BUILD_SUBDIR) && tar cvfz ./tricktool-$(PROGVER).tar.gz ./tricktool-$(PROGVER)/* + +.PHONY: style +style: + ! gofmt -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' + +.PHONY: test +test: + @go test -v ./... + +.PHONY: clean +clean: + rm -rf ./tricktool ./$(BUILD_SUBDIR) diff --git a/tricktool.go b/main.go similarity index 79% rename from tricktool.go rename to main.go index 1b1a125..9880932 100644 --- a/tricktool.go +++ b/main.go @@ -4,6 +4,9 @@ import ( "github.com/spf13/cobra" ) +const applicationName = "tricktool" +const applicationVersion = "2.0.0" + func main() { var cmdUpgradeConfig = &cobra.Command{ @@ -15,7 +18,7 @@ func main() { Run: upgradeConfig, } - var rootCmd = &cobra.Command{Use: "app"} + var rootCmd = &cobra.Command{Use: "tricktool"} rootCmd.AddCommand(cmdUpgradeConfig) rootCmd.Execute() } diff --git a/testdata/ignore_words.txt b/testdata/ignore_words.txt new file mode 100644 index 0000000..e69de29