Skip to content

Commit

Permalink
Harmonize CI scripts with bosh-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ctlong committed May 17, 2022
1 parent 446e2a7 commit 3c5a45a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
30 changes: 26 additions & 4 deletions bin/format
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,31 @@ set -eu -o pipefail

ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"

(
cd "${ROOT_DIR}"
go install -v golang.org/x/tools/cmd/goimports
)
go_bin_path="$(go env GOPATH)/bin" # TODO this should be handled in the docker container
export PATH=${go_bin_path}:${PATH}

case ${1:-} in
'-l' | '-w')
goimports_flag="${1}"
;;
'')
goimports_flag='-l'
;;
*)
echo "Error: invalid arg '${1}'"
echo "$(basename "$0") [flags]"
echo " -l list files whose formatting differs from goimport's"
echo " -w write result to (source) file instead of stdout"
exit
;;
esac

pushd "${ROOT_DIR}" > /dev/null 2>&1
# shellcheck disable=SC2038
# shellcheck disable=SC2035
find * -name '*.go' -and \( -not -path 'vendor/*' \) \
| xargs go run golang.org/x/tools/cmd/goimports -w
# shellcheck disable=SC2046
goimports "${goimports_flag}" \
$(find "${ROOT_DIR}" -name '*.go' -and \( -not -path "${ROOT_DIR}/vendor/*" \))
popd > /dev/null 2>&1
9 changes: 8 additions & 1 deletion bin/ginkgo
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"

SLOW_SPEC_THRESHOLD="${SLOW_SPEC_THRESHOLD:-20}"

(
cd "${ROOT_DIR}"
go install -v github.com/onsi/ginkgo/ginkgo
)
go_bin_path="$(go env GOPATH)/bin" # TODO this should be handled in the docker container
export PATH=${go_bin_path}:${PATH}

# shellcheck disable=SC2068
go run github.com/onsi/ginkgo/ginkgo \
ginkgo \
-keepGoing \
-skipPackage=vendor \
-slowSpecThreshold="${SLOW_SPEC_THRESHOLD}" \
Expand Down
10 changes: 7 additions & 3 deletions bin/lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ set -eu -o pipefail
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"

(
cd "$ROOT_DIR" && \
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint
cd "$ROOT_DIR"
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint
)
go_bin_path="$(go env GOPATH)/bin" # TODO this should be handled in the docker container
export PATH=${go_bin_path}:${PATH}

golangci-lint version

for os in windows linux; do
linted_os_list=(windows linux)

for os in ${linted_os_list[*]}; do
echo -e "\n lint-ing with GOOS=${os}..."
GOOS="${os}" golangci-lint run "${ROOT_DIR}"/...
done
16 changes: 13 additions & 3 deletions bin/test-unit
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
echo 'Note: if you want to quickly run tests for just one package, do it like this:'
echo ' % bin/ginkgo path/to/package'

"${ROOT_DIR}/bin/format" # TODO: this should be called in parallel via Concourse
echo -e "\n Checking formatting..." # TODO: should CI do this in parallel?
files_needing_reformat="$("${ROOT_DIR}/bin/format" -l)"
if [[ ${files_needing_reformat} = *[![:space:]]* ]]; then
echo "Error: some files require formatting (below)"
echo "${files_needing_reformat}"
echo "Error: some files require formatting (above)"
echo "=> run 'bin/format -w' to reformat with 'goimports'"
echo " see: https://pkg.go.dev/golang.org/x/tools/cmd/goimports"
exit 1
fi

"${ROOT_DIR}/bin/lint" # TODO: this should be called in parallel via Concourse
echo -e "\n Running linter..." # TODO: should CI do this in parallel?
"${ROOT_DIR}/bin/lint"

for os in windows linux; do
echo -e "\n build-ing with GOOS=${os} to confirm everything compiles..."
GOOS="${os}" "${ROOT_DIR}/bin/build" # TODO: this should be called in parallel via Concourse
GOOS="${os}" "${ROOT_DIR}/bin/build" # TODO: should CI do this in parallel?
done

echo -e "\n Testing packages..."
Expand Down

0 comments on commit 3c5a45a

Please sign in to comment.