Skip to content

Commit 55bce22

Browse files
committed
chore: enable strict mode for test CI
Signed-off-by: Wei Fu <[email protected]>
1 parent 7230b94 commit 55bce22

File tree

13 files changed

+77
-52
lines changed

13 files changed

+77
-52
lines changed

.github/workflows/e2e.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ jobs:
1818
- env:
1919
TARGET: ${{ matrix.target }}
2020
run: |
21+
set -euo pipefail
22+
2123
echo "${TARGET}"
2224
case "${TARGET}" in
2325
linux-amd64-e2e)
24-
PASSES='build release e2e' MANUAL_VER=v3.4.7 CPU='4' EXPECT_DEBUG='true' COVER='false' RACE='true' ./test.sh 2>&1 | tee test.log
25-
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log
26+
PASSES='build release e2e' MANUAL_VER=v3.4.7 CPU='4' EXPECT_DEBUG='true' COVER='false' RACE='true' ./test.sh
2627
;;
2728
linux-386-e2e)
28-
GOARCH=386 PASSES='build e2e' CPU='4' EXPECT_DEBUG='true' COVER='false' RACE='true' ./test.sh 2>&1 | tee test.log
29-
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log
29+
GOARCH=386 PASSES='build e2e' CPU='4' EXPECT_DEBUG='true' COVER='false' RACE='true' ./test.sh
3030
;;
3131
*)
3232
echo "Failed to find target"

.github/workflows/functional.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
- env:
1818
TARGET: ${{ matrix.target }}
1919
run: |
20+
set -euo pipefail
21+
2022
echo "${TARGET}"
2123
case "${TARGET}" in
2224
linux-amd64-functional)

.github/workflows/grpcproxy.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ jobs:
1717
- env:
1818
TARGET: ${{ matrix.target }}
1919
run: |
20+
set -euo pipefail
21+
2022
echo "${TARGET}"
2123
case "${TARGET}" in
2224
linux-amd64-grpcproxy)
23-
PASSES='build grpcproxy' CPU='4' COVER='false' RACE='true' ./test.sh 2>&1 | tee test.log
24-
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log
25+
PASSES='build grpcproxy' CPU='4' COVER='false' RACE='true' ./test.sh
2526
;;
2627
*)
2728
echo "Failed to find target"

.github/workflows/tests.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
- env:
2424
TARGET: ${{ matrix.target }}
2525
run: |
26+
set -euo pipefail
27+
2628
echo "${TARGET}"
2729
case "${TARGET}" in
2830
linux-amd64-fmt)

build

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
35
echo -e "\\e[91mDEPRECATED!!! Use build.sh script instead.\\e[0m\\n"
46
sleep 1
57

build.sh

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
35
source ./scripts/test_lib.sh
46

57
GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")
6-
if [[ -n "$FAILPOINTS" ]]; then
8+
if [[ -n "${FAILPOINTS:-}" ]]; then
79
GIT_SHA="$GIT_SHA"-FAILPOINTS
810
fi
911

1012
VERSION_SYMBOL="${ROOT_MODULE}/api/v3/version.GitSHA"
1113

14+
# use go env if noset
15+
GOOS=${GOOS:-$(go env GOOS)}
16+
GOARCH=${GOARCH:-$(go env GOARCH)}
17+
1218
# Set GO_LDFLAGS="-s" for building without symbols for debugging.
1319
# shellcheck disable=SC2206
14-
GO_LDFLAGS=(${GO_LDFLAGS} "-X=${VERSION_SYMBOL}=${GIT_SHA}")
15-
GO_BUILD_ENV=("CGO_ENABLED=0" "GO_BUILD_FLAGS=${GO_BUILD_FLAGS}" "GOOS=${GOOS}" "GOARCH=${GOARCH}")
20+
GO_LDFLAGS=(${GO_LDFLAGS:-} "-X=${VERSION_SYMBOL}=${GIT_SHA}")
21+
GO_BUILD_ENV=("CGO_ENABLED=0" "GO_BUILD_FLAGS=${GO_BUILD_FLAGS:-}" "GOOS=${GOOS}" "GOARCH=${GOARCH}")
1622

1723
# enable/disable failpoints
1824
toggle_failpoints() {
@@ -27,21 +33,21 @@ toggle_failpoints() {
2733

2834
toggle_failpoints_default() {
2935
mode="disable"
30-
if [[ -n "$FAILPOINTS" ]]; then mode="enable"; fi
36+
if [[ -n "${FAILPOINTS:-}" ]]; then mode="enable"; fi
3137
toggle_failpoints "$mode"
3238
}
3339

3440
etcd_build() {
3541
out="bin"
36-
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
42+
if [[ -n "${BINDIR:-}" ]]; then out="${BINDIR}"; fi
3743
toggle_failpoints_default
3844

3945
run rm -f "${out}/etcd"
4046
(
4147
cd ./server
4248
# Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
4349
# shellcheck disable=SC2086
44-
run env "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \
50+
run env "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
4551
-trimpath \
4652
-installsuffix=cgo \
4753
"-ldflags=${GO_LDFLAGS[*]}" \
@@ -52,7 +58,7 @@ etcd_build() {
5258
# shellcheck disable=SC2086
5359
(
5460
cd ./etcdutl
55-
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \
61+
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
5662
-trimpath \
5763
-installsuffix=cgo \
5864
"-ldflags=${GO_LDFLAGS[*]}" \
@@ -63,7 +69,7 @@ etcd_build() {
6369
# shellcheck disable=SC2086
6470
(
6571
cd ./etcdctl
66-
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \
72+
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
6773
-trimpath \
6874
-installsuffix=cgo \
6975
"-ldflags=${GO_LDFLAGS[*]}" \
@@ -84,7 +90,7 @@ etcd_build() {
8490

8591
tools_build() {
8692
out="bin"
87-
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
93+
if [[ -n "${BINDIR:-}" ]]; then out="${BINDIR}"; fi
8894
tools_path="tools/benchmark
8995
tools/etcd-dump-db
9096
tools/etcd-dump-logs
@@ -94,7 +100,7 @@ tools_build() {
94100
echo "Building" "'${tool}'"...
95101
run rm -f "${out}/${tool}"
96102
# shellcheck disable=SC2086
97-
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} \
103+
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" CGO_ENABLED=0 go build ${GO_BUILD_FLAGS:-} \
98104
-trimpath \
99105
-installsuffix=cgo \
100106
"-ldflags=${GO_LDFLAGS[*]}" \
@@ -105,7 +111,7 @@ tools_build() {
105111

106112
tests_build() {
107113
out="bin"
108-
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
114+
if [[ -n "${BINDIR:-}" ]]; then out="${BINDIR}"; fi
109115
tools_path="
110116
functional/cmd/etcd-agent
111117
functional/cmd/etcd-proxy
@@ -118,7 +124,7 @@ tests_build() {
118124
run rm -f "../${out}/${tool}"
119125

120126
# shellcheck disable=SC2086
121-
run env CGO_ENABLED=0 GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" go build ${GO_BUILD_FLAGS} \
127+
run env CGO_ENABLED=0 GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" go build ${GO_BUILD_FLAGS:-} \
122128
-installsuffix=cgo \
123129
"-ldflags=${GO_LDFLAGS[*]}" \
124130
-o="../${out}/${tool}" "./${tool}" || return 2

scripts/build-binary

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -euo pipefail
44

55
source ./scripts/test_lib.sh
66

7-
VER=$1
7+
VER=${1:-}
88
REPOSITORY="${REPOSITORY:-git@github.com:etcd-io/etcd.git}"
99

10-
if [ -z "$1" ]; then
10+
if [ -z "${VER}" ]; then
1111
echo "Usage: ${0} VERSION" >> /dev/stderr
1212
exit 255
1313
fi
1414

15-
set -u
1615

1716
function setup_env {
1817
local ver=${1}
@@ -38,7 +37,7 @@ function package {
3837
srcdir="${ccdir}"
3938
fi
4039
local ext=""
41-
if [ "${GOOS}" == "windows" ]; then
40+
if [ "${GOOS:-}" == "windows" ]; then
4241
ext=".exe"
4342
fi
4443
for bin in etcd etcdctl etcdutl; do
@@ -60,7 +59,7 @@ function main {
6059
cd release
6160
setup_env "${VER}" "${proj}"
6261

63-
tarcmd=tar
62+
local tarcmd=tar
6463
if [[ $(go env GOOS) == "darwin" ]]; then
6564
echo "Please use linux machine for release builds."
6665
exit 1

scripts/build-docker

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -euo pipefail
44

55
if [ "$#" -ne 1 ]; then
66
echo "Usage: $0 VERSION" >&2
@@ -11,7 +11,7 @@ ARCH=$(go env GOARCH)
1111
VERSION="${1}-${ARCH}"
1212
DOCKERFILE="Dockerfile-release.${ARCH}"
1313

14-
if [ -z "${BINARYDIR}" ]; then
14+
if [ -z "${BINARYDIR:-}" ]; then
1515
RELEASE="etcd-${1}"-$(go env GOOS)-$(go env GOARCH)
1616
BINARYDIR="${RELEASE}"
1717
TARFILE="${RELEASE}.tar.gz"
@@ -34,7 +34,7 @@ cp "${BINARYDIR}"/etcd "${BINARYDIR}"/etcdctl "${BINARYDIR}"/etcdutl "${IMAGEDIR
3434

3535
cat ./"${DOCKERFILE}" > "${IMAGEDIR}"/Dockerfile
3636

37-
if [ -z "$TAG" ]; then
37+
if [ -z "${TAG:-}" ]; then
3838
# Fix incorrect image "Architecture" using buildkit
3939
# From https://stackoverflow.com/q/72144329/
4040
DOCKER_BUILDKIT=1 docker build -t "gcr.io/etcd-development/etcd:${VERSION}" "${IMAGEDIR}"

scripts/build-release.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Build all release binaries and images to directory ./release.
44
# Run from repository root.
55
#
6-
set -e
6+
set -euo pipefail
77

88
source ./scripts/test_lib.sh
99

10-
VERSION=$1
10+
VERSION=${1:-}
1111
if [ -z "${VERSION}" ]; then
1212
echo "Usage: ${0} VERSION" >> /dev/stderr
1313
exit 255

scripts/test_lib.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
35
ROOT_MODULE="go.etcd.io/etcd"
46

57
if [[ "$(go list)" != "${ROOT_MODULE}/v3" ]]; then
@@ -107,7 +109,7 @@ function relativePath {
107109

108110
#### Discovery of files/packages within a go module #####
109111

110-
# go_srcs_in_module [package]
112+
# go_srcs_in_module
111113
# returns list of all not-generated go sources in the current (dir) module.
112114
function go_srcs_in_module {
113115
go list -f "{{with \$c:=.}}{{range \$f:=\$c.GoFiles }}{{\$c.Dir}}/{{\$f}}{{\"\n\"}}{{end}}{{range \$f:=\$c.TestGoFiles }}{{\$c.Dir}}/{{\$f}}{{\"\n\"}}{{end}}{{range \$f:=\$c.XTestGoFiles }}{{\$c.Dir}}/{{\$f}}{{\"\n\"}}{{end}}{{end}}" ./... | grep -vE "(\\.pb\\.go|\\.pb\\.gw.go)"
@@ -171,7 +173,7 @@ function module_dirs() {
171173

172174
# maybe_run [cmd...] runs given command depending on the DRY_RUN flag.
173175
function maybe_run() {
174-
if ${DRY_RUN}; then
176+
if ${DRY_RUN:-}; then
175177
log_warning -e "# DRY_RUN:\\n % ${*}"
176178
else
177179
run "${@}"
@@ -243,7 +245,7 @@ function go_test {
243245

244246
local goTestFlags=""
245247
local goTestEnv=""
246-
if [ "${VERBOSE}" == "1" ]; then
248+
if [ "${VERBOSE:-}" == "1" ]; then
247249
goTestFlags="-v"
248250
fi
249251

test

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
35
echo -e "\\e[91mDEPRECATED!!! Use test.sh script instead.\\e[0m\\n"
46
sleep 1
57

0 commit comments

Comments
 (0)