Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit 9058723

Browse files
author
Bryan Johnson
committed
Update service template with go tool support
1 parent 325fdf0 commit 9058723

File tree

9 files changed

+1215
-1322
lines changed

9 files changed

+1215
-1322
lines changed

.circleci/config.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ version: 2.1
22

33
orbs:
44
slack: circleci/slack@5.1.1
5+
go: circleci/go@2.2.4
56

67
workflows:
78
main-workflow:
@@ -77,6 +78,9 @@ jobs:
7778
- run:
7879
name: go tidy
7980
command: go mod tidy -v
81+
- run:
82+
name: run goimports
83+
command: ./do run-goimports
8084
- run:
8185
name: verify no changes
8286
command: git diff --ignore-matching-lines='Generated on ' --exit-code
@@ -270,8 +274,9 @@ commands:
270274
setup:
271275
steps:
272276
- checkout
273-
- run: go mod download
274-
- run: ./do install-devtools
277+
- go/with-cache:
278+
steps:
279+
- run: go mod download
275280

276281
store_results:
277282
steps:

.golangci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ run:
44

55
# Do not treat these as gospel, adjust as appropriate
66
linters-settings:
7-
govet:
8-
check-shadowing: false
7+
shadow: false
98
golint:
109
min-confidence: 0
1110
gocyclo:

cmd/api/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/circleci/ex/system"
1414
"github.com/circleci/ex/termination"
1515

16-
/* todo rename 'ex-service-template' to 'your-service' */
1716
"github.com/circleci/ex-service-template/api/api"
1817
"github.com/circleci/ex-service-template/books"
1918
"github.com/circleci/ex-service-template/cmd"

do

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ set -eu -o pipefail
33

44
_version=1.0.${CIRCLE_BUILD_NUM-0}-$(git rev-parse --short HEAD 2>/dev/null || echo latest)
55
reportDir="test-reports"
6-
serviceName="ex-service-template"
6+
serviceName="ex-service-template" #FIXME: update with the new service name
7+
package="github.com/circleci/${serviceName}"
78

89
make-target() {
910
mkdir -p "target"
@@ -35,7 +36,7 @@ help_build="Build the binaries for production"
3536
build() {
3637
local date ldflags
3738
date=$(date "+%FT%T%z")
38-
ldflags="-s -w -X github.com/circleci/${serviceName}/cmd.Version=$_version -X github.com/circleci/${serviceName}/cmd.Date=$date"
39+
ldflags="-s -w -X ${package}/cmd.Version=$_version -X ${package}/cmd.Date=$date"
3940

4041
GOOS=linux GOARCH=amd64 binary "$ldflags" &
4142

@@ -59,7 +60,7 @@ build() {
5960
# shellcheck disable=SC2034
6061
help_lint="Run golanci-lint to lint go files."
6162
lint() {
62-
exec ./bin/golangci-lint run "${@:-./...}"
63+
exec go tool golangci-lint run "${@:-./...}"
6364
}
6465

6566
# This variable is used, but shellcheck can't tell.
@@ -79,26 +80,25 @@ help_test="Run normal unit tests"
7980
test() {
8081
mkdir -p "${reportDir}"
8182
# -count=1 is used to forcibly disable test result caching
82-
./bin/gotestsum --junitfile="${reportDir}/junit.xml" -- -race -count=1 "${@:-./...}"
83+
go tool gotestsum --junitfile="${reportDir}/junit.xml" -- -race -count=1 "${@:-./...}"
8384
}
8485

8586
# This variable is used, but shellcheck can't tell.
8687
# shellcheck disable=SC2034
8788
help_run_goimports="Run goimports for package"
8889
run-goimports () {
89-
./bin/gosimports -local "github.com/circleci/ex-service-template" -w
90+
go tool gosimports -local "${package}" -w .
9091
}
9192

9293
# This variable is used, but shellcheck can't tell.
9394
# shellcheck disable=SC2034
9495
help_godoc="Run godoc to read documentation."
9596
godoc() {
96-
install-go-bin "golang.org/x/tools/cmd/godoc@v0.1.3"
9797
local url
98-
url="http://localhost:6060/pkg/github.com/circleci/${serviceName}/"
98+
url="http://localhost:6060/pkg/${package}/"
9999
command -v xdg-open && xdg-open $url &
100100
command -v open && open $url &
101-
./bin/godoc -http=127.0.0.1:6060
101+
go tool godoc -http=127.0.0.1:6060
102102
}
103103

104104
# This variable is used, but shellcheck can't tell.
@@ -108,29 +108,6 @@ go-mod-tidy() {
108108
go mod tidy -v
109109
}
110110

111-
install-go-bin() {
112-
local binDir="$PWD/bin"
113-
for pkg in "${@}"; do
114-
echo "${pkg}"
115-
(
116-
cd tools
117-
GOBIN="${binDir}" go install "${pkg}"
118-
)
119-
done
120-
}
121-
122-
# This variable is used, but shellcheck can't tell.
123-
# shellcheck disable=SC2034
124-
help_install_devtools="Install tools that other tasks expect into ./bin"
125-
install-devtools() {
126-
local tools=()
127-
while IFS='' read -r value; do
128-
tools+=("$value")
129-
done < <(grep _ tools/tools.go | awk -F'"' '{print $2}')
130-
131-
install-go-bin "${tools[@]}"
132-
}
133-
134111
# This variable is used, but shellcheck can't tell.
135112
# shellcheck disable=SC2034
136113
help_create_stub_test_files="Create an empty pkg_test in all directories with no tests.
@@ -145,14 +122,6 @@ create-stub-test-files() {
145122
xargs -r --max-args=2 bash -c 'echo "package $0" > "$1/pkg_test.go"'
146123
}
147124

148-
# This variable is used, but shellcheck can't tell.
149-
# shellcheck disable=SC2034
150-
help_run_goimports="Run goimports for package"
151-
run-goimports () {
152-
command -v ./bin/goimports || install-go-bin "golang.org/x/tools/cmd/goimports@v0.0.0-20201208183658-cc330816fc52"
153-
./bin/goimports -local "github.com/circleci/${serviceName}" -w "${@:-.}"
154-
}
155-
156125
# This variable is used, but shellcheck can't tell.
157126
# shellcheck disable=SC2034
158127
help_version="Print version"

0 commit comments

Comments
 (0)