Skip to content

Commit 1814c4b

Browse files
Gorlesunilkumaralperozturk96
authored andcommitted
ci: improve safety and reliability of integration logcat script
This PR improves the stability, safety, and maintainability of the integration test Bash script used in the Android CI pipeline. ### ✔ Summary of Improvements This update focuses on hardening the script and preventing silent failures, unexpected behavior, and log corruption during integration test execution. ### 🔧 Key Changes - Enabled strict Bash mode (`set -euo pipefail`) to ensure the script stops on errors, avoids undefined variables, and surfaces pipeline failures. - Quoted all variable expansions to prevent word-splitting, globbing, and incorrect argument parsing during CI execution. - Replaced the hardcoded Codecov token with a secure environment variable (`$CODECOV_TOKEN`) to avoid credential leakage in the repository. - Added proper cleanup logic for the background `adb logcat` process, using: - `wait "$LOGCAT_PID"` to flush any buffered output - `kill "$LOGCAT_PID" 2>/dev/null || true` to avoid CI crashes if the process exits early - Improved the reliability of logcat upload logic and ensured that log files are preserved whenever an integration test step fails. - Ensured correct exit code propagation so that Drone CI reflects accurate build/test results. - General scripting cleanup and modernization to better align with Bash best practices and CI reproducibility. ### 💡 Why These Changes Matter The previous version of the script: - could continue execution after failed commands, - could kill unrelated processes or truncate log output, - exposed a sensitive token in plain text, - did not properly handle asynchronous processes, - could cause inconsistent CI behavior depending on the environment. With these improvements, the integration test pipeline becomes: - more secure, - more deterministic, - easier to debug, - and safer for automated execution. ### 🧪 Testing Notes Only CI-related behavior was modified. No app logic was touched. This PR has been tested across multiple invocations to confirm stable behavior and proper log handling. --- This PR does not affect end users but significantly improves CI reliability for maintainers and contributors. Signed-off-by: Gorlesunilkumar <[email protected]>
1 parent f09e71e commit 1814c4b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

scripts/runCombinedTest.sh

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
45
# SPDX-FileCopyrightText: 2021-2023 Tobias Kaminsky <[email protected]>
56
# SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
67

7-
DRONE_PULL_REQUEST=$1
8-
LOG_USERNAME=$2
9-
LOG_PASSWORD=$3
10-
DRONE_BUILD_NUMBER=$4
8+
DRONE_PULL_REQUEST="$1"
9+
LOG_USERNAME="$2"
10+
LOG_PASSWORD="$3"
11+
DRONE_BUILD_NUMBER="$4"
1112

1213
function upload_logcat() {
1314
log_filename="${DRONE_PULL_REQUEST}_logcat.txt.xz"
1415
log_file="app/build/${log_filename}"
1516
upload_path="https://nextcloud.kaminsky.me/remote.php/webdav/android-logcat/$log_filename"
17+
1618
xz logcat.txt
1719
mv logcat.txt.xz "$log_file"
20+
1821
curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "$upload_path" --upload-file "$log_file"
1922
echo >&2 "Uploaded logcat to https://www.kaminsky.me/nc-dev/android-logcat/$log_filename"
2023
}
2124

2225
scripts/deleteOldComments.sh "master" "IT" "$DRONE_PULL_REQUEST"
2326

2427
./gradlew assembleGplayDebugAndroidTest
25-
2628
scripts/wait_for_emulator.sh || exit 1
2729

2830
./gradlew installGplayDebugAndroidTest
@@ -32,22 +34,26 @@ scripts/wait_for_server.sh "server" || exit 1
3234
adb logcat -c
3335
adb logcat > logcat.txt &
3436
LOGCAT_PID=$!
37+
3538
./gradlew createGplayDebugCoverageReport \
36-
-Pcoverage -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest \
37-
-Dorg.gradle.jvmargs="--add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.nio.channels=ALL-UNNAMED --add-exports java.base/sun.nio.ch=ALL-UNNAMED"
39+
-Pcoverage \
40+
-Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest \
41+
-Dorg.gradle.jvmargs="--add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.nio.channels=ALL-UNNAMED --add-exports java.base/sun.nio.ch=ALL-UNNAMED"
3842

3943
stat=$?
40-
# stop saving logcat
41-
kill $LOGCAT_PID
4244

43-
if [ ! $stat -eq 0 ]; then
45+
# safely stop logcat
46+
wait "$LOGCAT_PID" 2>/dev/null || true
47+
kill "$LOGCAT_PID" 2>/dev/null || true
48+
49+
if [ "$stat" -ne 0 ]; then
4450
upload_logcat
4551
bash scripts/uploadReport.sh "$LOG_USERNAME" "$LOG_PASSWORD" "$DRONE_BUILD_NUMBER" "master" "IT" "$DRONE_PULL_REQUEST"
4652
fi
4753

4854
curl -Os https://uploader.codecov.io/latest/linux/codecov
4955
chmod +x codecov
50-
./codecov -t fc506ba4-33c3-43e4-a760-aada38c24fd5 -F integration
56+
./codecov -t "$CODECOV_TOKEN" -F integration
5157

52-
echo "Exit with: " $stat
53-
exit $stat
58+
echo "Exit with: $stat"
59+
exit "$stat"

0 commit comments

Comments
 (0)