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.4] fix: enable strict mode for CI #15504

Merged
merged 1 commit into from
Mar 23, 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
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
with:
go-version: "1.19.7"
- run: |
set -euo pipefail

git config --global user.email "github-action@etcd.io"
git config --global user.name "Github Action"
gpg --batch --gen-key <<EOF
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
- env:
TARGET: ${{ matrix.target }}
run: |
set -euo pipefail

go version
echo ${GOROOT}
echo "${TARGET}"
Expand Down Expand Up @@ -58,8 +60,7 @@ jobs:
GO_BUILD_FLAGS='-v' GOARCH=s390x ./build
;;
linux-amd64-grpcproxy)
PASSES='build grpcproxy' CPU='4' RACE='true' ./test 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' RACE='true' ./test
;;
linux-386-unit)
GOARCH=386 PASSES='unit' ./test
Expand Down
20 changes: 11 additions & 9 deletions build
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/usr/bin/env bash

set -euo pipefail

# set some environment variables
ORG_PATH="go.etcd.io"
REPO_PATH="${ORG_PATH}/etcd"

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

# Set GO_LDFLAGS="-s" for building without symbols for debugging.
GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/version.GitSHA=${GIT_SHA}"
GO_LDFLAGS="${GO_LDFLAGS:-} -X ${REPO_PATH}/version.GitSHA=${GIT_SHA}"

# enable/disable failpoints
toggle_failpoints() {
Expand All @@ -30,7 +32,7 @@ etcd_setup_gopath() {
cd "$CDIR" || return
etcdGOPATH="${CDIR}/gopath"
# preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
if [[ -n "$GOPATH" ]]; then
if [[ -n "${GOPATH:-}" ]]; then
GOPATH=":$GOPATH"
fi
rm -rf "${etcdGOPATH:?}/"
Expand All @@ -42,31 +44,31 @@ etcd_setup_gopath() {

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

# Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
# shellcheck disable=SC2086
CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
CGO_ENABLED=0 go build ${GO_BUILD_FLAGS:-} \
-installsuffix cgo \
-ldflags "$GO_LDFLAGS" \
-o "${out}/etcd" ${REPO_PATH} || return
# shellcheck disable=SC2086
CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
CGO_ENABLED=0 go build ${GO_BUILD_FLAGS:-} \
-installsuffix cgo \
-ldflags "$GO_LDFLAGS" \
-o "${out}/etcdctl" ${REPO_PATH}/etcdctl || return
}

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 @@ -88,7 +90,7 @@ tools_build() {

toggle_failpoints_default

if [[ "${ETCD_SETUP_GOPATH}" == "1" ]]; then
if [[ "${ETCD_SETUP_GOPATH:-}" == "1" ]]; then
etcd_setup_gopath
fi

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

set -euo pipefail

if ! [[ "$0" =~ "functional/build" ]]; then
echo "must be run from repository root"
exit 255
Expand Down
35 changes: 23 additions & 12 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
# Run code coverage
# COVERDIR must either be a absolute path or a relative path to the etcd root
# $ COVERDIR=coverage PASSES="build_cov cov" ./test
set -e
set -euo pipefail

source ./build

PASSES=${PASSES:-}

# build before setting up test GOPATH
if [[ "${PASSES}" == *"functional"* ]]; then
./functional/build
Expand Down Expand Up @@ -82,6 +84,7 @@ fi

# shellcheck disable=SC2206
FMT=($FMT)
VERBOSE=${VERBOSE:-}
if [ "${VERBOSE}" == "1" ]; then
# shellcheck disable=SC2128
echo "Running with FMT:" "${FMT[@]}"
Expand All @@ -108,19 +111,20 @@ if [ "${VERBOSE}" == "1" ]; then
echo "Running with STATIC_ANALYSIS_PATHS:" "${STATIC_ANALYSIS_PATHS[@]}"
fi

GOARCH=${GOARCH:-}
if [ -z "$GOARCH" ]; then
GOARCH=$(go env GOARCH);
fi

# determine the number of CPUs to use for Go tests
TEST_CPUS="1,2,4"
if [ -n "${CPU}" ]; then
if [ -n "${CPU:-}" ]; then
TEST_CPUS="${CPU}"
fi
echo "Running with TEST_CPUS:" "${TEST_CPUS}"

# determine whether target supports race detection
if [ -z "${RACE}" ] ; then
if [ -z "${RACE:-}" ] ; then
if [ "$GOARCH" == "amd64" ]; then
RACE="--race"
else
Expand All @@ -130,11 +134,14 @@ else
RACE="--race=${RACE:-true}"
fi

TESTCASE=${TESTCASE:-}
RUN_ARG=""
if [ -n "${TESTCASE}" ]; then
RUN_ARG="-run=${TESTCASE}"
fi

TIMEOUT=${TIMEOUT:-}

function unit_pass {
echo "Running unit tests..."
GO_TEST_FLAG=""
Expand Down Expand Up @@ -203,9 +210,10 @@ function integration_extra {
}

function functional_pass {
# Clean up any data and logs from previous runs
rm -rf /tmp/etcd-functional-* /tmp/etcd-functional-*.backup
# Clean up any data and logs from previous runs
rm -rf /tmp/etcd-functional-* /tmp/etcd-functional-*.backup

local agent_pids=""
for a in 1 2 3; do
./bin/etcd-agent --network tcp --address 127.0.0.1:${a}9027 &
pid="$!"
Expand Down Expand Up @@ -256,7 +264,7 @@ function cov_pass {
exit 255
fi

if [ -z "$COVERDIR" ]; then
if [ -z "${COVERDIR:-}" ]; then
echo "COVERDIR undeclared"
exit 255
fi
Expand Down Expand Up @@ -357,7 +365,7 @@ function release_pass {
rm -f ./bin/etcd-last-release
# to grab latest patch release; bump this up for every minor release
UPGRADE_VER=$(git tag -l --sort=-version:refname "v3.3.*" | head -1)
if [ -n "$MANUAL_VER" ]; then
if [ -n "${MANUAL_VER:-}" ]; then
# in case, we need to test against different version
UPGRADE_VER=$MANUAL_VER
fi
Expand Down Expand Up @@ -429,13 +437,13 @@ function goword_pass {
# shellcheck disable=SC2206
gofiles=($gofiles)
# only check for broken exported godocs
gowordRes=$(goword -use-spell=false "${gofiles[@]}" | grep godoc-export | sort)
gowordRes=$(goword -use-spell=false "${gofiles[@]}" | grep godoc-export | sort) || true
if [ -n "$gowordRes" ]; then
echo -e "goword checking failed:\\n${gowordRes}"
exit 255
fi
# check some spelling
gowordRes=$(goword -ignore-file=.words clientv3/{*,*/*}.go 2>&1 | grep spell | sort)
gowordRes=$(goword -ignore-file=.words clientv3/{*,*/*}.go 2>&1 | grep spell | sort) || true
if [ -n "$gowordRes" ]; then
echo -e "goword checking failed:\\n${gowordRes}"
exit 255
Expand Down Expand Up @@ -575,7 +583,7 @@ function receiver_name_pass {
# shellcheck disable=SC1117
recvs=$(grep 'func ([^*]' {*,*/*,*/*/*}.go | grep -Ev "(generated|pb/)" | tr ':' ' ' | \
awk ' { print $2" "$3" "$4" "$1 }' | sed "s/[a-zA-Z\.]*go//g" | sort | uniq | \
grep -Ev "(Descriptor|Proto|_)" | awk ' { print $3" "$4 } ' | sort | uniq -c | grep -v ' 1 ' | awk ' { print $2 } ')
grep -Ev "(Descriptor|Proto|_)" | awk ' { print $3" "$4 } ' | sort | uniq -c | grep -v ' 1 ' | awk ' { print $2 } ') || true
if [ -n "${recvs}" ]; then
# shellcheck disable=SC2206
recvs=($recvs)
Expand All @@ -588,6 +596,8 @@ function receiver_name_pass {
}

function commit_title_pass {
# TODO: git rev-parse --abbrev-ref doesn't work in pull-request and it
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# might return "fatal: HEAD does not point to a branch" which can pass.
git log --oneline "$(git merge-base HEAD "$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}")")"...HEAD | while read -r l; do
commitMsg=$(echo "$l" | cut -f2- -d' ')
if [[ "$commitMsg" == Merge* ]]; then
Expand Down Expand Up @@ -637,9 +647,10 @@ function fmt_pass {

function bom_pass {
if ! command -v license-bill-of-materials >/dev/null; then
echo "Skipping bom..."
return
fi
if [ "${GO111MODULE}" == "on" ]; then
if [ "${GO111MODULE:-on}" == "on" ]; then
# license-bill-off-materials calls "go list std cmd" which cannot handle modules
# Please see https://github.com/golang/go/issues/26924
echo "Skipping license-bill-of-materials with go modules..."
Expand Down Expand Up @@ -671,7 +682,7 @@ function dep_pass {

function build_cov_pass {
out="bin"
if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
if [ -n "${BINDIR:-}" ]; then out="${BINDIR}"; fi
go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcd_test"
go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcdctl_test" "${REPO_PATH}/etcdctl"
}
Expand Down