Skip to content

Commit 4ec5b6a

Browse files
authored
Go 1.17 (#6)
1 parent 32f77ce commit 4ec5b6a

14 files changed

Lines changed: 1327 additions & 203 deletions

File tree

.circleci/config.yml

Lines changed: 109 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,130 @@
1-
version: 2.1
1+
# =================================================================
2+
#
3+
# Copyright (C) 2022 Spatial Current, Inc. - All Rights Reserved
4+
# Released as open source under the MIT License. See LICENSE file.
5+
#
6+
# =================================================================
7+
8+
version: "2.1"
9+
210
executors:
11+
# `main` uses the `cimg/go:1.17` docker image.
12+
main:
13+
docker:
14+
- image: cimg/go:1.17
15+
16+
# `base` uses the `cimg/base` docker image.
317
base:
418
docker:
5-
- image: circleci/golang:1.13
6-
working_directory: /go/src/github.com/spatialcurrent/gocat
19+
- image: cimg/base:2020.07
20+
21+
# `macos` uses the macOS machine image.
22+
macos:
23+
macos:
24+
xcode: 12.4.0
25+
resource_class: medium
26+
27+
# `windows` uses the Windows machine image.
28+
windows:
29+
machine:
30+
image: "windows-server-2019-vs2019:stable"
31+
resource_class: "windows.medium"
32+
shell: "powershell.exe -ExecutionPolicy Bypass"
33+
34+
735
jobs:
8-
pre_deps_golang:
9-
executor: base
10-
steps:
11-
- checkout
12-
- run: make deps_go
13-
- run: sudo chown -R circleci /go/src
14-
- save_cache:
15-
key: v1-go-src-{{ .Branch }}-{{ .Revision }}
16-
paths:
17-
- /go/src
36+
37+
# `test_go` tests the source code.
1838
test_go:
19-
executor: base
39+
executor: main
2040
steps:
21-
- run: sudo chown -R circleci /go/src
22-
- restore_cache:
23-
keys:
24-
- v1-go-src-{{ .Branch }}-{{ .Revision }}
25-
- run: make deps_go_test
26-
- run: make test_go
41+
- checkout
42+
- run: make fmt
2743
- run: make imports
44+
- run: make test_go
2845
- run: git diff --exit-code
46+
47+
# `test_cli` tests the executable.
2948
test_cli:
30-
executor: base
49+
executor: main
3150
steps:
32-
- run: sudo chown -R circleci /go/src
33-
- restore_cache:
34-
keys:
35-
- v1-go-src-{{ .Branch }}-{{ .Revision }}
36-
- run: make deps_go
37-
- run: make install
51+
- checkout
52+
- run: make tidy
53+
- run: make bin/gocat
3854
- run: make test_cli
39-
build_cli:
40-
executor: base
55+
56+
# `build` builds the executables
57+
build:
58+
executor: main
4159
steps:
42-
- run: sudo chown -R circleci /go/src
43-
- restore_cache:
44-
keys:
45-
- v1-go-src-{{ .Branch }}-{{ .Revision }}
46-
- run: go get github.com/inconshreveable/mousetrap # for windows CLI builds
47-
- run: make build_cli
60+
- checkout
61+
62+
# Update apt cache
63+
- run: sudo apt-get update
64+
65+
# Tidy dependencies
66+
- run: make tidy
67+
68+
# Build Executeables
69+
- run: make build_release
70+
71+
# Remove gox
72+
- run: rm -f bin/gox
73+
4874
- store_artifacts:
4975
path: bin
5076
destination: /
77+
- persist_to_workspace:
78+
root: bin
79+
paths:
80+
- gocat_darwin_amd64
81+
- gocat_darwin_arm64
82+
- gocat_linux_386
83+
- gocat_linux_amd64
84+
- gocat_linux_arm
85+
- gocat_linux_arm64
86+
- gocat_windows_386.exe
87+
- gocat_windows_amd64.exe
88+
89+
# `verify_linux` verifys the linux build
90+
verify_linux:
91+
executor: base
92+
steps:
93+
- attach_workspace:
94+
at: bin
95+
- run: bin/gocat_linux_386 --help
96+
- run: bin/gocat_linux_amd64 --help
97+
98+
# `verify_macos` verifys the macOS build
99+
verify_macos:
100+
executor: macos
101+
steps:
102+
- attach_workspace:
103+
at: bin
104+
- run: bin/gocat_darwin_amd64 --help
105+
106+
# `verify_windows` verifys the windows build
107+
verify_windows:
108+
executor: windows
109+
steps:
110+
- attach_workspace:
111+
at: bin
112+
- run: bin/gocat_windows_386.exe --help
113+
- run: bin/gocat_windows_amd64.exe --help
114+
51115
workflows:
116+
version: 2
52117
main:
53118
jobs:
54-
- pre_deps_golang
55-
- test_go:
119+
- test_go
120+
- test_cli
121+
- build
122+
- verify_linux:
56123
requires:
57-
- pre_deps_golang
58-
- build_cli:
124+
- build
125+
- verify_macos:
59126
requires:
60-
- pre_deps_golang
61-
- test_cli:
127+
- build
128+
- verify_windows:
62129
requires:
63-
- pre_deps_golang
130+
- build

.envrc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
##########################################
4+
# DO NOT MAKE LOCAL CHANGES TO THIS FILE #
5+
# #
6+
# Vars in this file can be overridden by #
7+
# exporting them in .envrc.local #
8+
##########################################
9+
10+
# Add local paths for binaries and scripts
11+
PATH_add ./bin
12+
PATH_add ./scripts
13+
14+
#####################
15+
# AWS Configuration #
16+
#####################
17+
18+
# Have aws-vault use the login keychain for better timeout behavior
19+
export AWS_VAULT_KEYCHAIN_NAME=login
20+
21+
# Read ~/.aws/config
22+
export AWS_SDK_LOAD_CONFIG=1
23+
24+
##############################################
25+
# Load Local Overrides and Check Environment #
26+
##############################################
27+
28+
# Load a local overrides file. Any changes you want to make for your local
29+
# environment should live in that file.
30+
31+
if [ -e .envrc.local ]
32+
then
33+
source_env .envrc.local
34+
fi

.gitignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# compiled binaries
2+
bin
3+
4+
# direnv
5+
.envrc.local
6+
7+
# secrets
18
secret/
2-
bin/
9+
10+
# miscellaneous
11+
.DS_Store
12+
temp
313
*.so
414
*.h

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Spatial Current, Inc.
3+
Copyright (c) 2022 Spatial Current, Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,13 @@
11
# =================================================================
22
#
3-
# Copyright (C) 2019 Spatial Current, Inc. - All Rights Reserved
3+
# Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
44
# Released as open source under the MIT License. See LICENSE file.
55
#
66
# =================================================================
77

8-
ifdef GOPATH
9-
GCFLAGS=-trimpath=$(shell printenv GOPATH)/src
10-
else
11-
GCFLAGS=-trimpath=$(shell go env GOPATH)/src
12-
endif
13-
14-
LDFLAGS=-X main.gitBranch=$(shell git branch | grep \* | cut -d ' ' -f2) -X main.gitCommit=$(shell git rev-list -1 HEAD)
15-
16-
ifndef DEST
17-
DEST=bin
18-
endif
19-
208
.PHONY: help
21-
229
help: ## Print the help documentation
23-
@grep -E '^[a-zA-Z0-9_-\]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
24-
25-
#
26-
# Dependencies
27-
#
28-
29-
deps_go: ## Install Go dependencies
30-
go get -d -t ./...
31-
32-
.PHONY: deps_go_test
33-
deps_go_test: ## Download Go dependencies for tests
34-
go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # download shadow
35-
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # install shadow
36-
go get -u github.com/kisielk/errcheck # download and install errcheck
37-
go get -u github.com/client9/misspell/cmd/misspell # download and install misspell
38-
go get -u github.com/gordonklaus/ineffassign # download and install ineffassign
39-
go get -u honnef.co/go/tools/cmd/staticcheck # download and instal staticcheck
40-
go get -u golang.org/x/tools/cmd/goimports # download and install goimports
41-
42-
deps_arm: ## Install dependencies to cross-compile to ARM
43-
# ARMv7
44-
apt-get install -y libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev gcc-arm-linux-gnueabi g++-arm-linux-gnueabi
45-
# ARMv8
46-
apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
10+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
4711

4812
#
4913
# Go building, formatting, testing, and installing
@@ -53,45 +17,61 @@ fmt: ## Format Go source code
5317
go fmt $$(go list ./... )
5418

5519
.PHONY: imports
56-
imports: ## Update imports in Go source code
57-
# If missing, install goimports with: go get golang.org/x/tools/cmd/goimports
58-
goimports -w -local github.com/spatialcurrent/gocat,github.com/spatialcurrent $$(find . -iname '*.go')
20+
imports: bin/goimports ## Update imports in Go source code
21+
bin/goimports -w -local github.com/spatialcurrent/gocat,github.com/spatialcurrent $$(find . -iname '*.go')
5922

6023
vet: ## Vet Go source code
61-
go vet $$(go list ./...)
24+
go vet github.com/spatialcurrent/gocat/pkg/... # vet packages
25+
go vet github.com/spatialcurrent/gocat/cmd/... # vet commands
26+
27+
tidy: ## Tidy Go source code
28+
go mod tidy
6229

6330
.PHONY: test_go
64-
test_go: ## Run Go tests
31+
test_go: bin/errcheck bin/misspell bin/staticcheck bin/shadow ## Run Go tests
6532
bash scripts/test.sh
6633

6734
.PHONY: test_cli
68-
test_cli: ## Run CLI tests
35+
test_cli: bin/gocat ## Run CLI tests
6936
bash scripts/test-cli.sh
7037

71-
.PHONY: build
72-
build: build_cli build_javascript build_so build_android ## Build CLI, Shared Objects (.so), JavaScript, and Android
73-
74-
install: ## Install gocat CLI on current platform
75-
go install -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gocat
38+
install: ## Install the CLI on current platform
39+
go install github.com/spatialcurrent/gocat/cmd/gocat
7640

7741
#
7842
# Command line Programs
7943
#
8044

81-
bin/gocat_darwin_amd64: ## Build gocat CLI for Darwin / amd64
82-
GOOS=darwin GOARCH=amd64 go build -o $(DEST)/gocat_darwin_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gocat
45+
bin/errcheck:
46+
go build -o bin/errcheck github.com/kisielk/errcheck
47+
48+
bin/goimports:
49+
go build -o bin/goimports golang.org/x/tools/cmd/goimports
50+
51+
bin/gox:
52+
go build -o bin/gox github.com/mitchellh/gox
8353

84-
bin/gocat_linux_amd64: ## Build gocat CLI for Linux / amd64
85-
GOOS=linux GOARCH=amd64 go build -o $(DEST)/gocat_linux_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gocat
54+
bin/misspell:
55+
go build -o bin/misspell github.com/client9/misspell/cmd/misspell
8656

87-
bin/gocat_windows_amd64.exe: ## Build gocat CLI for Windows / amd64
88-
GOOS=windows GOARCH=amd64 go build -o $(DEST)/gocat_windows_amd64.exe -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gocat
57+
bin/staticcheck:
58+
go build -o bin/staticcheck honnef.co/go/tools/cmd/staticcheck
8959

90-
bin/gocat_linux_arm64: ## Build gocat CLI for Linux / arm64
91-
GOOS=linux GOARCH=arm64 go build -o $(DEST)/gocat_linux_arm64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gocat
60+
bin/shadow:
61+
go build -o bin/shadow golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
62+
63+
bin/gocat: ## Build CLI for Darwin / amd64
64+
go build -o bin/gocat github.com/spatialcurrent/gocat/cmd/gocat
65+
66+
bin/gocat_linux_amd64: bin/gox ## Build CLI for Darwin / amd64
67+
scripts/build-release linux amd64
68+
69+
.PHONY: build
70+
build: bin/gocat
9271

93-
.PHONY: build_cli
94-
build_cli: bin/gocat_darwin_amd64 bin/gocat_linux_amd64 bin/gocat_windows_amd64.exe bin/gocat_linux_arm64 ## Build command line programs
72+
.PHONY: build_release
73+
build_release: bin/gox
74+
scripts/build-release
9575

9676
## Clean
9777

0 commit comments

Comments
 (0)