Skip to content

Commit a32c4d8

Browse files
committed
Cleanup jenkins scripts
1 parent feebe5a commit a32c4d8

File tree

5 files changed

+130
-73
lines changed

5 files changed

+130
-73
lines changed

.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 an API spec
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: 53 additions & 55 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."git@github.com:".insteadOf "https://github.com/"
4151
export GOPRIVATE=github.com/couchbaselabs/go-fleecedelta
@@ -44,75 +54,63 @@ 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 after job has completed
60-
# go2xunit will fail with 1.23 with name mismatch (try disabling parallel mode), but without any t.Parallel()
61-
go install golang.org/dl/go1.22.8@latest
62-
~/go/bin/go1.22.8 download
63-
~/go/bin/go1.22.8 install -v github.com/tebeka/go2xunit@latest
64-
go install -v github.com/axw/gocov/gocov@latest
65-
go install -v github.com/AlekSi/gocov-xml@latest
66-
fi
67-
68-
if [ "${SG_TEST_X509:-}" == "true" -a "${COUCHBASE_SERVER_PROTOCOL}" != "couchbases" ]; then
57+
echo "Downloading tool dependencies..."
58+
# Install tools to use after job has completed
59+
# go2xunit will fail with 1.23 with name mismatch (try disabling parallel mode), but without any t.Parallel()
60+
set -x # Output all executed shell commands
61+
go install golang.org/dl/go1.22.8@latest
62+
~/go/bin/go1.22.8 download
63+
~/go/bin/go1.22.8 install -v github.com/tebeka/go2xunit@latest
64+
go install -v github.com/axw/gocov/gocov@latest
65+
go install -v github.com/AlekSi/gocov-xml@latest
66+
set +x # Stop outputting all executed shell commands
67+
68+
if [ "${SG_TEST_X509:-}" == "true" ] && [ "${COUCHBASE_SERVER_PROTOCOL}" != "couchbases" ]; then
6969
echo "Setting SG_TEST_X509 requires using couchbases:// protocol, aborting integration tests"
7070
exit 1
7171
fi
7272

7373
# Set environment vars
74-
GO_TEST_FLAGS="-v -p 1 -count=${RUN_COUNT:-1}"
74+
GO_TEST_FLAGS=(-v -p 1 "-count=${RUN_COUNT:-1}")
7575
INT_LOG_FILE_NAME="verbose_int"
7676

77-
if [ -d "godeps" ]; then
78-
export GOPATH=$(pwd)/godeps
79-
fi
80-
export PATH=$PATH:$(go env GOPATH)/bin
81-
echo "PATH: $PATH"
82-
8377
if [ "${TEST_DEBUG:-}" == "true" ]; then
8478
export SG_TEST_LOG_LEVEL="debug"
8579
export SG_TEST_BUCKET_POOL_DEBUG="true"
8680
fi
8781

8882
if [ "${TARGET_TEST}" != "ALL" ]; then
89-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -run ${TARGET_TEST}"
83+
GO_TEST_FLAGS+=(-run "${TARGET_TEST}")
9084
fi
9185

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

9993
if [ "${DETECT_RACES:-}" == "true" ]; then
100-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -race"
94+
GO_TEST_FLAGS=(-race)
10195
fi
10296

10397
if [ "${FAIL_FAST:-}" == "true" ]; then
104-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -failfast"
98+
GO_TEST_FLAGS+=(-failfast)
10599
fi
106100

107101
if [ "${SG_TEST_PROFILE_FREQUENCY:-}" == "true" ]; then
108102
export SG_TEST_PROFILE_FREQUENCY=${SG_TEST_PROFILE_FREQUENCY}
109103
fi
110104

111-
if [ "${RUN_WALRUS}" == "true" ]; then
105+
if [ "${RUN_WALRUS:-}" == "true" ]; then
106+
set +e # Do not abort on errors, so we can run both EE and CE tests
107+
set -x # Output all executed shell commands
112108
# EE
113-
go test -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.raw 2>&1 | true
109+
go test -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.raw 2>&1
114110
# CE
115-
go test -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.raw 2>&1 | true
111+
go test -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.raw 2>&1
112+
set +x
113+
set -e
116114
fi
117115

118116
# Run CBS
@@ -127,45 +125,45 @@ else
127125
fi
128126

129127
# Set up test environment variables for CBS runs
130-
export SG_TEST_USE_XATTRS=${XATTRS}
131128
export SG_TEST_USE_GSI=${GSI}
132129
export SG_TEST_COUCHBASE_SERVER_URL="${COUCHBASE_SERVER_PROTOCOL}://127.0.0.1"
133130
export SG_TEST_BACKING_STORE="Couchbase"
134-
export SG_TEST_BUCKET_POOL_SIZE=${SG_TEST_BUCKET_POOL_SIZE}
135-
export SG_TEST_BUCKET_POOL_DEBUG=${SG_TEST_BUCKET_POOL_DEBUG}
136131
export SG_TEST_TLS_SKIP_VERIFY=${TLS_SKIP_VERIFY}
137132

138133
if [ "${SG_EDITION}" == "EE" ]; then
139-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -tags cb_sg_devmode,cb_sg_enterprise"
134+
GO_TEST_FLAGS+=(-tags "cb_sg_devmode,cb_sg_enterprise")
140135
else
141-
GO_TEST_FLAGS="${GO_TEST_FLAGS} -tags cb_sg_devmode"
136+
GO_TEST_FLAGS+=(-tags cb_sg_devmode)
142137
fi
143138

144-
go test ${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.raw" | stdbuf -oL grep -a -E '(--- (FAIL|PASS|SKIP):|github.com/couchbase/sync_gateway(/.+)?\t|TEST: |panic: )'
139+
set -x # Output all executed shell commands
140+
go test "${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.raw" | stdbuf -oL grep -a -E '(--- (FAIL|PASS|SKIP):|github.com/couchbase/sync_gateway(/.+)?|TEST: |panic: )'
145141
if [ "${PIPESTATUS[0]}" -ne "0" ]; then # If test exit code is not 0 (failed)
146142
echo "Go test failed! Parsing logs to find cause..."
147143
TEST_FAILED=true
148144
fi
149145

146+
set +x # Stop outputting all executed shell commands
147+
150148
# Collect CBS logs if server error occurred
151149
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.raw"; then
152150
docker exec -t couchbase /opt/couchbase/bin/cbcollect_info /workspace/cbcollect.zip
153151
fi
154152

155153
# Generate xunit test report that can be parsed by the JUnit Plugin
156-
LC_CTYPE=C tr -dc [:print:][:space:] < ${INT_LOG_FILE_NAME}.out.raw > ${INT_LOG_FILE_NAME}.out # Strip non-printable characters
154+
LC_CTYPE=C tr -dc "[:print:][:space:]" < ${INT_LOG_FILE_NAME}.out.raw > ${INT_LOG_FILE_NAME}.out # Strip non-printable characters
157155
~/go/bin/go2xunit -input "${INT_LOG_FILE_NAME}.out" -output "${INT_LOG_FILE_NAME}.xml"
158-
if [ "${RUN_WALRUS}" == "true" ]; then
156+
if [ "${RUN_WALRUS:-}" == "true" ]; then
159157
# Strip non-printable characters before xml creation
160-
LC_CTYPE=C tr -dc [:print:][:space:] < "verbose_unit_ee.out.raw" > "verbose_unit_ee.out"
161-
LC_CTYPE=C tr -dc [:print:][:space:] < "verbose_unit_ce.out.raw" > "verbose_unit_ce.out"
158+
LC_CTYPE=C tr -dc "[:print:][:space:]" < "verbose_unit_ee.out.raw" > "verbose_unit_ee.out"
159+
LC_CTYPE=C tr -dc "[:print:][:space:]" < "verbose_unit_ce.out.raw" > "verbose_unit_ce.out"
162160
~/go/bin/go2xunit -input "verbose_unit_ee.out" -output "verbose_unit_ee.xml"
163161
~/go/bin/go2xunit -input "verbose_unit_ce.out" -output "verbose_unit_ce.xml"
164162
fi
165163

166164
# Get coverage
167165
~/go/bin/gocov convert "coverage_int.out" | ~/go/bin/gocov-xml > coverage_int.xml
168-
if [ "${RUN_WALRUS}" == "true" ]; then
166+
if [ "${RUN_WALRUS:-}" == "true" ]; then
169167
~/go/bin/gocov convert "coverage_walrus_ee.out" | ~/go/bin/gocov-xml > "coverage_walrus_ee.xml"
170168
~/go/bin/gocov convert "coverage_walrus_ce.out" | ~/go/bin/gocov-xml > "coverage_walrus_ce.xml"
171169
fi

0 commit comments

Comments
 (0)