Skip to content

Commit

Permalink
add makefile, spell check artifacts and gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
James Ranson committed Mar 5, 2021
1 parent 36b780b commit cd242a9
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
91 changes: 91 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 4 additions & 1 deletion tricktool.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"github.com/spf13/cobra"
)

const applicationName = "tricktool"
const applicationVersion = "2.0.0"

func main() {

var cmdUpgradeConfig = &cobra.Command{
Expand All @@ -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()
}
Empty file added testdata/ignore_words.txt
Empty file.

0 comments on commit cd242a9

Please sign in to comment.