From 1814c4b07c55098d4061fffffc3ae4279661a065 Mon Sep 17 00:00:00 2001 From: Gorlesunilkumar Date: Wed, 26 Nov 2025 01:07:08 +0530 Subject: [PATCH] ci: improve safety and reliability of integration logcat script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- scripts/runCombinedTest.sh | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/scripts/runCombinedTest.sh b/scripts/runCombinedTest.sh index e588938f68df..a8c8009ebfef 100755 --- a/scripts/runCombinedTest.sh +++ b/scripts/runCombinedTest.sh @@ -1,20 +1,23 @@ #!/bin/bash +set -euo pipefail # SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors # SPDX-FileCopyrightText: 2021-2023 Tobias Kaminsky # SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only -DRONE_PULL_REQUEST=$1 -LOG_USERNAME=$2 -LOG_PASSWORD=$3 -DRONE_BUILD_NUMBER=$4 +DRONE_PULL_REQUEST="$1" +LOG_USERNAME="$2" +LOG_PASSWORD="$3" +DRONE_BUILD_NUMBER="$4" function upload_logcat() { log_filename="${DRONE_PULL_REQUEST}_logcat.txt.xz" log_file="app/build/${log_filename}" upload_path="https://nextcloud.kaminsky.me/remote.php/webdav/android-logcat/$log_filename" + xz logcat.txt mv logcat.txt.xz "$log_file" + curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "$upload_path" --upload-file "$log_file" echo >&2 "Uploaded logcat to https://www.kaminsky.me/nc-dev/android-logcat/$log_filename" } @@ -22,7 +25,6 @@ function upload_logcat() { scripts/deleteOldComments.sh "master" "IT" "$DRONE_PULL_REQUEST" ./gradlew assembleGplayDebugAndroidTest - scripts/wait_for_emulator.sh || exit 1 ./gradlew installGplayDebugAndroidTest @@ -32,22 +34,26 @@ scripts/wait_for_server.sh "server" || exit 1 adb logcat -c adb logcat > logcat.txt & LOGCAT_PID=$! + ./gradlew createGplayDebugCoverageReport \ --Pcoverage -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest \ --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" + -Pcoverage \ + -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest \ + -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" stat=$? -# stop saving logcat -kill $LOGCAT_PID -if [ ! $stat -eq 0 ]; then +# safely stop logcat +wait "$LOGCAT_PID" 2>/dev/null || true +kill "$LOGCAT_PID" 2>/dev/null || true + +if [ "$stat" -ne 0 ]; then upload_logcat bash scripts/uploadReport.sh "$LOG_USERNAME" "$LOG_PASSWORD" "$DRONE_BUILD_NUMBER" "master" "IT" "$DRONE_PULL_REQUEST" fi curl -Os https://uploader.codecov.io/latest/linux/codecov chmod +x codecov -./codecov -t fc506ba4-33c3-43e4-a760-aada38c24fd5 -F integration +./codecov -t "$CODECOV_TOKEN" -F integration -echo "Exit with: " $stat -exit $stat +echo "Exit with: $stat" +exit "$stat"