Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.5] chore: enable strict mode for test CI #15558

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
- env:
TARGET: ${{ matrix.target }}
run: |
set -euo pipefail

echo "${TARGET}"
case "${TARGET}" in
linux-amd64-e2e)
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
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log
PASSES='build release e2e' MANUAL_VER=v3.4.7 CPU='4' EXPECT_DEBUG='true' COVER='false' RACE='true' ./test.sh
;;
linux-386-e2e)
GOARCH=386 PASSES='build e2e' CPU='4' EXPECT_DEBUG='true' COVER='false' RACE='true' ./test.sh 2>&1 | tee test.log
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log
GOARCH=386 PASSES='build e2e' CPU='4' EXPECT_DEBUG='true' COVER='false' RACE='true' ./test.sh
;;
*)
echo "Failed to find target"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/functional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
- env:
TARGET: ${{ matrix.target }}
run: |
set -euo pipefail

echo "${TARGET}"
case "${TARGET}" in
linux-amd64-functional)
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/grpcproxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ jobs:
- env:
TARGET: ${{ matrix.target }}
run: |
set -euo pipefail

echo "${TARGET}"
case "${TARGET}" in
linux-amd64-grpcproxy)
PASSES='build grpcproxy' CPU='4' COVER='false' RACE='true' ./test.sh 2>&1 | tee test.log
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log
PASSES='build grpcproxy' CPU='4' COVER='false' RACE='true' ./test.sh
;;
*)
echo "Failed to find target"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
- env:
TARGET: ${{ matrix.target }}
run: |
set -euo pipefail

echo "${TARGET}"
case "${TARGET}" in
linux-amd64-fmt)
Expand Down
2 changes: 2 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

echo -e "\\e[91mDEPRECATED!!! Use build.sh script instead.\\e[0m\\n"
sleep 1

Expand Down
30 changes: 18 additions & 12 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/usr/bin/env bash

set -euo pipefail

source ./scripts/test_lib.sh

GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")
if [[ -n "$FAILPOINTS" ]]; then
if [[ -n "${FAILPOINTS:-}" ]]; then
GIT_SHA="$GIT_SHA"-FAILPOINTS
fi

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

# use go env if noset
GOOS=${GOOS:-$(go env GOOS)}
GOARCH=${GOARCH:-$(go env GOARCH)}

# Set GO_LDFLAGS="-s" for building without symbols for debugging.
# shellcheck disable=SC2206
GO_LDFLAGS=(${GO_LDFLAGS} "-X=${VERSION_SYMBOL}=${GIT_SHA}")
GO_BUILD_ENV=("CGO_ENABLED=0" "GO_BUILD_FLAGS=${GO_BUILD_FLAGS}" "GOOS=${GOOS}" "GOARCH=${GOARCH}")
GO_LDFLAGS=(${GO_LDFLAGS:-} "-X=${VERSION_SYMBOL}=${GIT_SHA}")
GO_BUILD_ENV=("CGO_ENABLED=0" "GO_BUILD_FLAGS=${GO_BUILD_FLAGS:-}" "GOOS=${GOOS}" "GOARCH=${GOARCH}")

# enable/disable failpoints
toggle_failpoints() {
Expand All @@ -27,21 +33,21 @@ toggle_failpoints() {

toggle_failpoints_default() {
mode="disable"
if [[ -n "$FAILPOINTS" ]]; then mode="enable"; fi
if [[ -n "${FAILPOINTS:-}" ]]; then mode="enable"; fi
toggle_failpoints "$mode"
}

etcd_build() {
out="bin"
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
if [[ -n "${BINDIR:-}" ]]; then out="${BINDIR}"; fi
toggle_failpoints_default

run rm -f "${out}/etcd"
(
cd ./server
# Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
# shellcheck disable=SC2086
run env "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \
run env "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
-trimpath \
-installsuffix=cgo \
"-ldflags=${GO_LDFLAGS[*]}" \
Expand All @@ -52,7 +58,7 @@ etcd_build() {
# shellcheck disable=SC2086
(
cd ./etcdutl
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
-trimpath \
-installsuffix=cgo \
"-ldflags=${GO_LDFLAGS[*]}" \
Expand All @@ -63,7 +69,7 @@ etcd_build() {
# shellcheck disable=SC2086
(
cd ./etcdctl
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" "${GO_BUILD_ENV[@]}" go build ${GO_BUILD_FLAGS:-} \
-trimpath \
-installsuffix=cgo \
"-ldflags=${GO_LDFLAGS[*]}" \
Expand All @@ -84,7 +90,7 @@ etcd_build() {

tools_build() {
out="bin"
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
if [[ -n "${BINDIR:-}" ]]; then out="${BINDIR}"; fi
tools_path="tools/benchmark
tools/etcd-dump-db
tools/etcd-dump-logs
Expand All @@ -94,7 +100,7 @@ tools_build() {
echo "Building" "'${tool}'"...
run rm -f "${out}/${tool}"
# shellcheck disable=SC2086
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} \
run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" CGO_ENABLED=0 go build ${GO_BUILD_FLAGS:-} \
-trimpath \
-installsuffix=cgo \
"-ldflags=${GO_LDFLAGS[*]}" \
Expand All @@ -105,7 +111,7 @@ tools_build() {

tests_build() {
out="bin"
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
if [[ -n "${BINDIR:-}" ]]; then out="${BINDIR}"; fi
tools_path="
functional/cmd/etcd-agent
functional/cmd/etcd-proxy
Expand All @@ -118,7 +124,7 @@ tests_build() {
run rm -f "../${out}/${tool}"

# shellcheck disable=SC2086
run env CGO_ENABLED=0 GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" go build ${GO_BUILD_FLAGS} \
run env CGO_ENABLED=0 GO_BUILD_FLAGS="${GO_BUILD_FLAGS:-}" go build ${GO_BUILD_FLAGS:-} \
-installsuffix=cgo \
"-ldflags=${GO_LDFLAGS[*]}" \
-o="../${out}/${tool}" "./${tool}" || return 2
Expand Down
11 changes: 5 additions & 6 deletions scripts/build-binary
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/usr/bin/env bash

set -e
set -euo pipefail

source ./scripts/test_lib.sh

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

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

set -u

function setup_env {
local ver=${1}
Expand All @@ -38,7 +37,7 @@ function package {
srcdir="${ccdir}"
fi
local ext=""
if [ "${GOOS}" == "windows" ]; then
if [ "${GOOS:-}" == "windows" ]; then
ext=".exe"
fi
for bin in etcd etcdctl etcdutl; do
Expand All @@ -60,7 +59,7 @@ function main {
cd release
setup_env "${VER}" "${proj}"

tarcmd=tar
local tarcmd=tar
if [[ $(go env GOOS) == "darwin" ]]; then
echo "Please use linux machine for release builds."
exit 1
Expand Down
6 changes: 3 additions & 3 deletions scripts/build-docker
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -euo pipefail

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

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

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

if [ -z "$TAG" ]; then
if [ -z "${TAG:-}" ]; then
# Fix incorrect image "Architecture" using buildkit
# From https://stackoverflow.com/q/72144329/
DOCKER_BUILDKIT=1 docker build -t "gcr.io/etcd-development/etcd:${VERSION}" "${IMAGEDIR}"
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Build all release binaries and images to directory ./release.
# Run from repository root.
#
set -e
set -euo pipefail

source ./scripts/test_lib.sh

VERSION=$1
VERSION=${1:-}
if [ -z "${VERSION}" ]; then
echo "Usage: ${0} VERSION" >> /dev/stderr
exit 255
Expand Down
8 changes: 5 additions & 3 deletions scripts/test_lib.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

ROOT_MODULE="go.etcd.io/etcd"

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

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

# go_srcs_in_module [package]
# go_srcs_in_module
# returns list of all not-generated go sources in the current (dir) module.
function go_srcs_in_module {
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)"
Expand Down Expand Up @@ -171,7 +173,7 @@ function module_dirs() {

# maybe_run [cmd...] runs given command depending on the DRY_RUN flag.
function maybe_run() {
if ${DRY_RUN}; then
if ${DRY_RUN:-}; then
log_warning -e "# DRY_RUN:\\n % ${*}"
else
run "${@}"
Expand Down Expand Up @@ -243,7 +245,7 @@ function go_test {

local goTestFlags=""
local goTestEnv=""
if [ "${VERBOSE}" == "1" ]; then
if [ "${VERBOSE:-}" == "1" ]; then
goTestFlags="-v"
fi

Expand Down
2 changes: 2 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

echo -e "\\e[91mDEPRECATED!!! Use test.sh script instead.\\e[0m\\n"
sleep 1

Expand Down
Loading