Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
incorporate latest boilerplate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
honnix committed Jan 21, 2020
1 parent 5da72d5 commit d447e1e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
18 changes: 11 additions & 7 deletions boilerplate/lyft/golang_test_targets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst


.PHONY: download_tooling
download_tooling: #download dependencies (including test deps) for the package
@boilerplate/lyft/golang_test_targets/download_tooling.sh

.PHONY: lint
lint: #lints the package for common code smells
which golangci-lint || go install github.com/golangci/golangci-lint/cmd/golangci-lint
# Calling lint twice here is a hack. The first call seem to fail when internally calling `go list...`
# However, that call seem to have some effects (e.g. https://github.com/golang/go/issues/29452) which, for some
# reason, allows the subsequent calls to succeed.
lint: download_tooling #lints the package for common code smells
GL_DEBUG=linters_output,env golangci-lint run --deadline=5m --exclude deprecated -v

# If code is failing goimports linter, this will fix.
Expand All @@ -17,10 +18,13 @@ lint: #lints the package for common code smells
goimports:
@boilerplate/lyft/golang_test_targets/goimports

.PHONY: install
install: #download dependencies (including test deps) for the package
.PHONY: mod_download
mod_download: #download dependencies (including test deps) for the package
go mod download

.PHONY: install
install: download_tooling mod_download

.PHONY: test_unit
test_unit:
go test -cover ./... -race
Expand Down
33 changes: 33 additions & 0 deletions boilerplate/lyft/golang_test_targets/download_tooling.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Everything in this file needs to be installed outside of current module
# The reason we cannot turn off module entirely and install is that we need the replace statement in go.mod
# because we are installing a mockery fork. Turning it off would result installing the original not the fork.
# However, because the installation of these tools themselves sometimes modifies the go.mod/go.sum files. We don't
# want this either. So instead, we're going to copy those files into a temporary directory, do the installation, and
# ignore any changes made to the go mod files.
# (See https://github.com/golang/go/issues/30515 for some background context)

set -e

go_install_tool () {
tmp_dir=$(mktemp -d -t gotooling-XXXXXXXXXX)
echo "Installing $1 inside $tmp_dir"
cp go.mod go.sum "$tmp_dir"
pushd "$tmp_dir"
go get "$1"
popd
}

# List of tools to go get
# In the format of "<cli>:<package>" or ":<package>" if no cli
tools=(
"golangci-lint:github.com/golangci/golangci-lint/cmd/golangci-lint"
)

for tool in "${tools[@]}"
do
cli=$(echo "$tool" | cut -d':' -f1)
package=$(echo "$tool" | cut -d':' -f2)
command -v "$cli" || go_install_tool "$package"
done

0 comments on commit d447e1e

Please sign in to comment.