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

Commit

Permalink
use latest boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
honnix committed Jan 24, 2020
1 parent e9dc8d9 commit f11b511
Show file tree
Hide file tree
Showing 10 changed files with 667 additions and 23 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export REPOSITORY=flytestdlib
include boilerplate/lyft/golang_test_targets/Makefile

.PHONY: update_boilerplate
update_boilerplate:
@boilerplate/update.sh

# Generate golden files. Add test packages that generate golden files here.
golden:
go test ./cli/pflags/api -update
Expand All @@ -19,9 +23,7 @@ compile:
mkdir -p ./bin
go build -o pflags ./cli/pflags/main.go && mv ./pflags ./bin

gen-config:
# Note that installing it via download_tooling.sh doesn't work
which pflags || (go get github.com/lyft/flytestdlib/cli/pflags)
gen-config: download_tooling
@go generate ./...

.PHONY: test_unit_codecov
Expand Down
12 changes: 12 additions & 0 deletions boilerplate/lyft/golang_support_tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/lyft/boilerplate

go 1.13

require (
github.com/golangci/golangci-lint v1.22.2
github.com/lyft/flytestdlib v0.2.31
github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5
github.com/alvaroloes/enumer v1.1.2
)

replace github.com/vektra/mockery => github.com/enghabu/mockery v0.0.0-20191009061720-9d0c8670c2f0
553 changes: 553 additions & 0 deletions boilerplate/lyft/golang_support_tools/go.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions boilerplate/lyft/golang_support_tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build tools

package tools

import (
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/lyft/flytestdlib/cli/pflags"
_ "github.com/vektra/mockery/cmd/mockery"
_ "github.com/alvaroloes/enumer"
)
6 changes: 5 additions & 1 deletion boilerplate/lyft/golang_test_targets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ mod_download: #download dependencies (including test deps) for the package
.PHONY: install
install: download_tooling mod_download

.PHONY: show
show: go list -m all

.PHONY: test_unit
test_unit:
go test -cover ./... -race
Expand All @@ -39,4 +42,5 @@ test_unit_cover:

.PHONY: test_unit_visual
test_unit_visual:
go test ./... -coverprofile /tmp/cover.out -covermode=count; go tool cover -html=/tmp/cover.out
go test ./... -coverprofile /tmp/cover.out -covermode=count; go tool cover -html=/tmp/cover.out

4 changes: 2 additions & 2 deletions boilerplate/lyft/golang_test_targets/Readme.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Golang Test Targets
~~~~~~~~~~~~~~~~~~~

Provides an ``install`` make target that uses ``dep`` install golang dependencies.
Provides an ``install`` make target that uses ``go mod`` to install golang dependencies.

Provides a ``lint`` make target that uses golangci to lint your code.

Expand All @@ -17,7 +17,7 @@ Provides a ``test_benchmark`` target for benchmark tests.

Add ``lyft/golang_test_targets`` to your ``boilerplate/update.cfg`` file.

Make sure you're using ``dep`` for dependency management.
Make sure you're using ``go mod`` for dependency management.

Provide a ``.golangci`` configuration (the lint target requires it).

Expand Down
37 changes: 20 additions & 17 deletions boilerplate/lyft/golang_test_targets/download_tooling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@
# 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)
# We also want to version all the other tools. We also want to be able to run go mod tidy without removing the version
# pins. To facilitate this, we're maintaining two sets of go.mod/sum files - the second one only for tooling. This is
# the same approach that go 1.14 will take as well.
# See:
# https://github.com/lyft/flyte/issues/129
# https://github.com/golang/go/issues/30515 for some background context
# https://github.com/go-modules-by-example/index/blob/5ec250b4b78114a55001bd7c9cb88f6e07270ea5/010_tools/README.md

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"
"github.com/vektra/mockery/cmd/mockery"
"github.com/lyft/flytestdlib/cli/pflags"
"github.com/golangci/golangci-lint/cmd/golangci-lint"
"github.com/alvaroloes/enumer"
)

tmp_dir=$(mktemp -d -t gotooling-XXX)
echo "Using temp directory ${tmp_dir}"
cp -R boilerplate/lyft/golang_support_tools/* $tmp_dir
pushd "$tmp_dir"

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

popd
5 changes: 5 additions & 0 deletions boilerplate/lyft/golang_test_targets/goimports
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/usr/bin/env bash

# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

goimports -w $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/client/*")
1 change: 1 addition & 0 deletions boilerplate/update.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lyft/golang_test_targets
lyft/golangci_file
lyft/golang_support_tools
54 changes: 54 additions & 0 deletions boilerplate/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

OUT="$(mktemp -d)"
git clone [email protected]:lyft/boilerplate.git "${OUT}"

echo "Updating the update.sh script."
cp "${OUT}/boilerplate/update.sh" "${DIR}/update.sh"
echo ""


CONFIG_FILE="${DIR}/update.cfg"
README="https://github.com/lyft/boilerplate/blob/master/Readme.rst"

if [ ! -f "$CONFIG_FILE" ]; then
echo "$CONFIG_FILE not found."
echo "This file is required in order to select which features to include."
echo "See $README for more details."
exit 1
fi

if [ -z "$REPOSITORY" ]; then
echo '$REPOSITORY is required to run this script'
echo "See $README for more details."
exit 1
fi

while read directory; do
# TODO: Skip empty lines, whitespace only lines, and comment lines
echo "***********************************************************************************"
echo "$directory is configured in update.cfg."
echo "-----------------------------------------------------------------------------------"
echo "syncing files from source."
dir_path="${OUT}/boilerplate/${directory}"
rm -rf "${DIR}/${directory}"
mkdir -p $(dirname "${DIR}/${directory}")
cp -r "$dir_path" "${DIR}/${directory}"
if [ -f "${DIR}/${directory}/update.sh" ]; then
echo "executing ${DIR}/${directory}/update.sh"
"${DIR}/${directory}/update.sh"
fi
echo "***********************************************************************************"
echo ""
done < "$CONFIG_FILE"

rm -rf "${OUT}"

0 comments on commit f11b511

Please sign in to comment.