Skip to content

Commit 67a1331

Browse files
committed
Cleanup jenkins shell scripts
1 parent 5bf2d12 commit 67a1331

File tree

6 files changed

+127
-65
lines changed

6 files changed

+127
-65
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[*.sh]
2+
indent_style = space
3+
indent_size = 4
4+
shell_variant = bash
5+
binary_next_line = false
6+
switch_case_indent = true
7+
space_redirects = true
8+
keep_padding = true
9+
function_next_line = false

.github/workflows/shell.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2025-Present Couchbase, Inc.
2+
#
3+
# Use of this software is governed by the Business Source License included
4+
# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
5+
# in that file, in accordance with the Business Source License, use of this
6+
# software will be governed by the Apache License, Version 2.0, included in
7+
# the file licenses/APL2.txt.
8+
9+
name: shell
10+
permissions:
11+
contents: read
12+
13+
on:
14+
push:
15+
# Only run when we change a shell script
16+
paths:
17+
- "*.sh"
18+
branches:
19+
- "main"
20+
- "release/*"
21+
- "feature/*"
22+
- "CBG*"
23+
- "ci-*"
24+
pull_request:
25+
# Only run when we change a shell script
26+
paths:
27+
- "*.sh"
28+
branches:
29+
- "main"
30+
- "release/*"
31+
32+
concurrency:
33+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
34+
cancel-in-progress: ${{ !contains(github.ref, 'release/')}}
35+
36+
jobs:
37+
shellcheck:
38+
name: Shellcheck
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v5
42+
- name: Run ShellCheck
43+
uses: ludeeus/action-shellcheck@master
44+
with:
45+
ignore_paths: |
46+
./build.sh
47+
./bootstrap.sh
48+
./bench.sh
49+
./integration-test/service-test.sh
50+
./integration-test/service-install-tests.sh
51+
./rewrite-manifest.sh
52+
./snap-manifest.sh
53+
./set-version-stamp.sh
54+
./service/sync_gateway_service_install.sh
55+
./service/sync_gateway_service_uninstall.sh
56+
./service/sync_gateway_service_upgrade.sh
57+
./test-integration-init.sh
58+
./test.sh

integration-test/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ services:
3232
- 18097:18097
3333
- 19102:19102
3434
volumes:
35-
- "${DOCKER_CBS_ROOT_DIR:-.}/cbs:/root"
3635
- "${WORKSPACE_ROOT:-.}:/workspace"
3736
couchbase-replica1:
3837
container_name: couchbase-replica1

integration-test/service-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#/bin/sh
1+
#!/bin/bash
22

33
# Copyright 2024-Present Couchbase, Inc.
44
#

integration-test/start_server.sh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
# software will be governed by the Apache License, Version 2.0, included in
88
# the file licenses/APL2.txt.
99

10-
set -eux -o pipefail
10+
set -eu -o pipefail
1111

1212
function usage() {
1313
echo "Usage: $0 [-m] [-h] containername"
14+
exit 1
1415
}
1516

1617
if [ $# -gt 2 ]; then
1718
echo "Expected maximally two arguments"
18-
exit 1
19+
usage
1920
fi
2021

2122
while [[ $# -gt 0 ]]; do
@@ -26,8 +27,7 @@ while [[ $# -gt 0 ]]; do
2627
shift
2728
;;
2829
-h | --help)
29-
echo "Usage: $0 [-m] [-h] containername"
30-
exit 1
30+
usage
3131
;;
3232
--non-dockerhub)
3333
DOCKERHUB=false
@@ -41,10 +41,6 @@ while [[ $# -gt 0 ]]; do
4141
done
4242

4343
WORKSPACE_ROOT="$(pwd)"
44-
DOCKER_CBS_ROOT_DIR="$(pwd)"
45-
if [ "${CBS_ROOT_DIR:-}" != "" ]; then
46-
DOCKER_CBS_ROOT_DIR="${CBS_ROOT_DIR}"
47-
fi
4844

4945
set +e
5046
AMAZON_LINUX_2=$(grep 'Amazon Linux 2"' /etc/os-release)
@@ -54,36 +50,42 @@ if [[ -n "${AMAZON_LINUX_2}" ]]; then
5450
else
5551
DOCKER_COMPOSE="docker compose"
5652
fi
57-
cd -- "${BASH_SOURCE%/*}/"
58-
${DOCKER_COMPOSE} down || true
53+
echo "Stopping existing Couchbase Server container if it exists..."
5954
export SG_TEST_COUCHBASE_SERVER_DOCKER_NAME=couchbase
60-
# Start CBS
61-
docker stop ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} || true
62-
docker rm ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} || true
63-
# --volume: Makes and mounts a CBS folder for storing a CBCollect if needed
55+
cd -- "${BASH_SOURCE%/*}/"
56+
set +e # do not error on command failure
57+
set -x # Output all executed shell commands
58+
${DOCKER_COMPOSE} down
59+
docker stop ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME}
60+
docker rm ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME}
61+
set +x # Stop outputting all executed shell commands
62+
set -e # Abort on errors
6463

6564
# use dockerhub if no registry is specified, allows for pre-release images from alternative registries
6665
if [[ ! "${COUCHBASE_DOCKER_IMAGE_NAME}" =~ ghcr.io/* && "${DOCKERHUB:-}" != "false" ]]; then
6766
COUCHBASE_DOCKER_IMAGE_NAME="couchbase/server:${COUCHBASE_DOCKER_IMAGE_NAME}"
6867
fi
6968

69+
echo "Creating Couchbase Server container with image: ${COUCHBASE_DOCKER_IMAGE_NAME}"
7070
if [ "${MULTI_NODE:-}" == "true" ]; then
71+
set -x # Output all executed shell commands
7172
${DOCKER_COMPOSE} up -d --force-recreate --renew-anon-volumes --remove-orphans
7273
else
74+
set -x # Output all executed shell commands
7375
# single node
7476
docker run --rm -d --name ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} --volume "${WORKSPACE_ROOT}:/workspace" -p 8091-8097:8091-8097 -p 9102:9102 -p 9123:9123 -p 11207:11207 -p 11210:11210 -p 11211:11211 -p 18091-18097:18091-18097 -p 19102:19102 "${COUCHBASE_DOCKER_IMAGE_NAME}"
7577
fi
7678

7779
# Test to see if Couchbase Server is up
7880
# Each retry min wait 5s, max 10s. Retry 20 times with exponential backoff (delay 0), fail at 120s
79-
curl --retry-all-errors --connect-timeout 5 --max-time 10 --retry 20 --retry-delay 0 --retry-max-time 120 'http://127.0.0.1:8091'
81+
docker exec couchbase curl --fail --silent --retry-all-errors --connect-timeout 5 --max-time 10 --retry 20 --retry-delay 0 --retry-max-time 120 'http://127.0.0.1:8091'
8082

8183
# Set up CBS
8284

8385
docker exec couchbase couchbase-cli cluster-init --cluster-username Administrator --cluster-password password --cluster-ramsize 3072 --cluster-index-ramsize 3072 --cluster-fts-ramsize 256 --services data,index,query
8486
docker exec couchbase couchbase-cli setting-index --cluster couchbase://localhost --username Administrator --password password --index-threads 4 --index-log-level verbose --index-max-rollback-points 10 --index-storage-setting default --index-memory-snapshot-interval 150 --index-stable-snapshot-interval 40000
8587

86-
curl -u Administrator:password -v -X POST http://127.0.0.1:8091/node/controller/rename -d 'hostname=127.0.0.1'
88+
curl -u Administrator:password http://127.0.0.1:8091/node/controller/rename -d 'hostname=127.0.0.1'
8789

8890
if [ "${MULTI_NODE:-}" == "true" ]; then
8991
REPLICA1_NAME=couchbase-replica1

jenkins-integration-build.sh

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,42 @@
1010
DEFAULT_PACKAGE_TIMEOUT="45m"
1111

1212
set -u
13+
set -e # Abort on errors
1314

1415
if [ "${1:-}" == "-m" ]; then
1516
echo "Running in automated master integration mode"
1617
# Set automated setting parameters
17-
SG_COMMIT="master"
1818
TARGET_PACKAGE="..."
1919
TARGET_TEST="ALL"
2020
RUN_WALRUS="true"
21-
USE_GO_MODULES="true"
2221
DETECT_RACES="false"
2322
SG_EDITION="EE"
24-
XATTRS="true"
2523
RUN_COUNT="1"
2624
# CBS server settings
2725
COUCHBASE_SERVER_PROTOCOL="couchbase"
2826
COUCHBASE_SERVER_VERSION="enterprise-7.6.6"
29-
SG_TEST_BUCKET_POOL_SIZE="3"
30-
SG_TEST_BUCKET_POOL_DEBUG="true"
27+
export SG_TEST_BUCKET_POOL_DEBUG="true"
3128
GSI="true"
3229
TLS_SKIP_VERIFY="false"
3330
SG_CBCOLLECT_ALWAYS="false"
3431
fi
3532

36-
set -e # Abort on errors
37-
set -x # Output all executed shell commands
33+
REQUIRED_VARS=(
34+
COUCHBASE_SERVER_PROTOCOL
35+
COUCHBASE_SERVER_VERSION
36+
GSI
37+
TARGET_TEST
38+
TARGET_PACKAGE
39+
TLS_SKIP_VERIFY
40+
SG_EDITION
41+
)
3842

43+
for var in "${REQUIRED_VARS[@]}"; do
44+
if [ -z "${!var:-}" ]; then
45+
echo "${var} environment variable is required to be set."
46+
exit 1
47+
fi
48+
done
3949
# Use Git SSH and define private repos
4050
git config --global --replace-all url."[email protected]:".insteadOf "https://github.com/"
4151
export GOPRIVATE=github.com/couchbaselabs/go-fleecedelta
@@ -44,37 +54,21 @@ export GOPRIVATE=github.com/couchbaselabs/go-fleecedelta
4454
SG_COMMIT_HASH=$(git rev-parse HEAD)
4555
echo "Sync Gateway git commit hash: $SG_COMMIT_HASH"
4656

47-
# Use Go modules (3.1 and above) or bootstrap for legacy Sync Gateway versions (3.0 and below)
48-
if [ "${USE_GO_MODULES:-}" == "false" ]; then
49-
mkdir -p sgw_int_testing # Make the directory if it does not exist
50-
cp bootstrap.sh sgw_int_testing/bootstrap.sh
51-
cd sgw_int_testing
52-
chmod +x bootstrap.sh
53-
./bootstrap.sh -c ${SG_COMMIT} -e ee
54-
export GO111MODULE=off
55-
go get -u -v github.com/tebeka/go2xunit
56-
go get -u -v github.com/axw/gocov/gocov
57-
go get -u -v github.com/AlekSi/gocov-xml
58-
else
59-
# Install tools to use
60-
go install github.com/axw/gocov/gocov@latest
61-
go install github.com/AlekSi/gocov-xml@latest
62-
go install gotest.tools/gotestsum@latest
63-
fi
57+
echo "Downloading tool dependencies..."
58+
go install github.com/axw/gocov/gocov@latest
59+
go install github.com/AlekSi/gocov-xml@latest
60+
go install gotest.tools/gotestsum@latest
6461

65-
if [ "${SG_TEST_X509:-}" == "true" -a "${COUCHBASE_SERVER_PROTOCOL}" != "couchbases" ]; then
62+
if [ "${SG_TEST_X509:-}" == "true" ] && [ "${COUCHBASE_SERVER_PROTOCOL}" != "couchbases" ]; then
6663
echo "Setting SG_TEST_X509 requires using couchbases:// protocol, aborting integration tests"
6764
exit 1
6865
fi
6966

7067
# Set environment vars
71-
GO_TEST_FLAGS="-v -p 1 -count=${RUN_COUNT:-1}"
68+
GO_TEST_FLAGS=(-v -p 1 "-count=${RUN_COUNT:-1}")
7269
INT_LOG_FILE_NAME="verbose_int"
7370

74-
if [ -d "godeps" ]; then
75-
export GOPATH=$(pwd)/godeps
76-
fi
77-
export PATH=$PATH:$(go env GOPATH)/bin:~/go/bin
71+
export PATH=$PATH:~/go/bin
7872
echo "PATH: $PATH"
7973

8074
if [ "${TEST_DEBUG:-}" == "true" ]; then
@@ -83,38 +77,38 @@ if [ "${TEST_DEBUG:-}" == "true" ]; then
8377
fi
8478

8579
if [ "${TARGET_TEST}" != "ALL" ]; then
86-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -run ${TARGET_TEST}"
80+
GO_TEST_FLAGS+=(-run "${TARGET_TEST}")
8781
fi
8882

8983
if [ "${PACKAGE_TIMEOUT:-}" != "" ]; then
90-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -test.timeout=${PACKAGE_TIMEOUT}"
84+
GO_TEST_FLAGS+=(-test.timeout="${PACKAGE_TIMEOUT}")
9185
else
9286
echo "Defaulting package timeout to ${DEFAULT_PACKAGE_TIMEOUT}"
93-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -test.timeout=${DEFAULT_PACKAGE_TIMEOUT}"
87+
GO_TEST_FLAGS+=(-test.timeout="${DEFAULT_PACKAGE_TIMEOUT}")
9488
fi
9589

9690
if [ "${DETECT_RACES:-}" == "true" ]; then
97-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -race"
91+
GO_TEST_FLAGS=(-race)
9892
fi
9993

10094
if [ "${FAIL_FAST:-}" == "true" ]; then
101-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -failfast"
95+
GO_TEST_FLAGS+=(-failfast)
10296
fi
10397

10498
if [ "${SG_TEST_PROFILE_FREQUENCY:-}" == "true" ]; then
10599
export SG_TEST_PROFILE_FREQUENCY=${SG_TEST_PROFILE_FREQUENCY}
106100
fi
107101

108102
if [ "${RUN_WALRUS}" == "true" ]; then
109-
set +e
103+
set +e -x
104+
set -x +e
110105
# EE
111-
gotestsum --junitfile=rosmar-ee.xml --junitfile-project-name rosmar-EE --junitfile-testcase-classname relative --format standard-verbose -- -coverprofile=coverage_walrus_ee.out -coverpkg=github.com/couchbase/sync_gateway/... -tags cb_sg_devmode,cb_sg_enterprise $GO_TEST_FLAGS github.com/couchbase/sync_gateway/${TARGET_PACKAGE} > verbose_unit_ee.out 2>&1
106+
gotestsum --junitfile=rosmar-ee.xml --junitfile-project-name rosmar-EE --junitfile-testcase-classname relative --format standard-verbose -- -coverprofile=coverage_walrus_ee.out -coverpkg=github.com/couchbase/sync_gateway/... -tags cb_sg_devmode,cb_sg_enterprise "${GO_TEST_FLAGS[@]}" "github.com/couchbase/sync_gateway/${TARGET_PACKAGE}" > verbose_unit_ee.out 2>&1
112107
xmlstarlet ed -u '//testcase/@classname' -x 'concat("rosmar-EE-", .)' rosmar-ee.xml > verbose_unit_ee.xml
113108
# CE
114-
gotestsum --junitfile=rosmar-ce.xml --junitfile-project-name rosmar-CE --junitfile-testcase-classname relative --format standard-verbose -- -coverprofile=coverage_walrus_ce.out -coverpkg=github.com/couchbase/sync_gateway/... -tags cb_sg_devmode $GO_TEST_FLAGS github.com/couchbase/sync_gateway/${TARGET_PACKAGE} > verbose_unit_ce.out 2>&1
109+
gotestsum --junitfile=rosmar-ce.xml --junitfile-project-name rosmar-CE --junitfile-testcase-classname relative --format standard-verbose -- -coverprofile=coverage_walrus_ce.out -coverpkg=github.com/couchbase/sync_gateway/... -tags cb_sg_devmode "${GO_TEST_FLAGS[@]}" "github.com/couchbase/sync_gateway/${TARGET_PACKAGE}" > verbose_unit_ce.out 2>&1
115110
xmlstarlet ed -u '//testcase/@classname' -x 'concat("rosmar-CE-", .)' rosmar-ce.xml > verbose_unit_ce.xml
116-
set -e
117-
111+
set -e +x
118112
fi
119113

120114
# Run CBS
@@ -129,26 +123,26 @@ else
129123
fi
130124

131125
# Set up test environment variables for CBS runs
132-
export SG_TEST_USE_XATTRS=${XATTRS}
133126
export SG_TEST_USE_GSI=${GSI}
134127
export SG_TEST_COUCHBASE_SERVER_URL="${COUCHBASE_SERVER_PROTOCOL}://127.0.0.1"
135128
export SG_TEST_BACKING_STORE="Couchbase"
136-
export SG_TEST_BUCKET_POOL_SIZE=${SG_TEST_BUCKET_POOL_SIZE}
137-
export SG_TEST_BUCKET_POOL_DEBUG=${SG_TEST_BUCKET_POOL_DEBUG}
138129
export SG_TEST_TLS_SKIP_VERIFY=${TLS_SKIP_VERIFY}
139130

140131
if [ "${SG_EDITION}" == "EE" ]; then
141-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -tags cb_sg_devmode,cb_sg_enterprise"
132+
GO_TEST_FLAGS+=(-tags "cb_sg_devmode,cb_sg_enterprise")
142133
else
143-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -tags cb_sg_devmode"
134+
GO_TEST_FLAGS+=(-tags cb_sg_devmode)
144135
fi
145136

146-
gotestsum --junitfile=integration.xml --junitfile-project-name integration --junitfile-testcase-classname relative --format standard-verbose -- ${GO_TEST_FLAGS} -coverprofile=coverage_int.out -coverpkg=github.com/couchbase/sync_gateway/... github.com/couchbase/sync_gateway/${TARGET_PACKAGE} 2>&1 | stdbuf -oL tee "${INT_LOG_FILE_NAME}.out" | stdbuf -oL grep -a -E '(--- (FAIL|PASS|SKIP):|github.com/couchbase/sync_gateway(/.+)?\t|TEST: |panic: )'
137+
set -x # Output all executed shell commands
138+
gotestsum --junitfile=integration.xml --junitfile-project-name integration --junitfile-testcase-classname relative --format standard-verbose -- "${GO_TEST_FLAGS[@]}" -coverprofile=coverage_int.out -coverpkg=github.com/couchbase/sync_gateway/... "github.com/couchbase/sync_gateway/${TARGET_PACKAGE}" 2>&1 | stdbuf -oL tee "${INT_LOG_FILE_NAME}.out" | stdbuf -oL grep -a -E '(--- (FAIL|PASS|SKIP):|github.com/couchbase/sync_gateway(/.+)?\t|TEST: |panic: )'
147139
if [ "${PIPESTATUS[0]}" -ne "0" ]; then # If test exit code is not 0 (failed)
148140
echo "Go test failed! Parsing logs to find cause..."
149141
TEST_FAILED=true
150142
fi
151143

144+
set +x # Stop outputting all executed shell commands
145+
152146
# Collect CBS logs if server error occurred
153147
if [ "${SG_CBCOLLECT_ALWAYS:-}" == "true" ] || grep -a -q "server logs for details\|Timed out after 1m0s waiting for a bucket to become available" "${INT_LOG_FILE_NAME}.out"; then
154148
docker exec -t couchbase /opt/couchbase/bin/cbcollect_info /workspace/cbcollect.zip
@@ -163,7 +157,7 @@ fi
163157

164158
# Get coverage
165159
~/go/bin/gocov convert "coverage_int.out" | ~/go/bin/gocov-xml > coverage_int.xml
166-
if [ "${RUN_WALRUS}" == "true" ]; then
160+
if [ "${RUN_WALRUS:-}" == "true" ]; then
167161
~/go/bin/gocov convert "coverage_walrus_ee.out" | ~/go/bin/gocov-xml > "coverage_walrus_ee.xml"
168162
~/go/bin/gocov convert "coverage_walrus_ce.out" | ~/go/bin/gocov-xml > "coverage_walrus_ce.xml"
169163
fi

0 commit comments

Comments
 (0)