Skip to content

Commit

Permalink
Got iOS, macOS, Android working for .NET test server (#81)
Browse files Browse the repository at this point in the history
* Got iOS and macOS working for .NET test server

Android is moved but not working fully yet.  I cannot test as I don't have a proper Android device.

* Add iOS teardown and use lockable resource

* Lock android device as well

* Fix mistaken Jenkinsfile and add .NET Android

pwsh should be shell outside of Windows

* Fix up iOS things that make Jenkins annoyed
  • Loading branch information
borrrden authored Nov 1, 2024
1 parent bef3068 commit 1cca0e7
Show file tree
Hide file tree
Showing 29 changed files with 423 additions and 98 deletions.
3 changes: 3 additions & 0 deletions jenkins/pipelines/android/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pipeline {
}
stage('Android') {
agent { label 'mob-e2e-mac-01' }
options {
lock("mob-e2e-android-01")
}
steps {
// Run tests:
echo "Run Android Tests"
Expand Down
3 changes: 3 additions & 0 deletions jenkins/pipelines/c/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pipeline {
expression { return false } // Skip iOS for now
}
agent { label 'mob-e2e-mac-01' }
options {
lock("mob-e2e-iphone-01")
}
environment {
KEYCHAIN_PASSWORD = credentials('mob-e2e-mac-01-keychain-password')
}
Expand Down
3 changes: 2 additions & 1 deletion jenkins/pipelines/dotnet/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dotnet-install.ps1
prepare_dotnet.psm1
prepare_dotnet.psm1
prepare_dotnet.sh
63 changes: 55 additions & 8 deletions jenkins/pipelines/dotnet/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pipeline {
string(name: 'SGW_URL', defaultValue: '', description: "The url of Sync Gateway to download")
}
options {
timeout(time: 30, unit: 'MINUTES')
timeout(time: 120, unit: 'MINUTES')
ansiColor('xterm')
timestamps()
}
Expand All @@ -22,14 +22,61 @@ pipeline {
}
}
}
stage('Windows') {
agent { label 'mob-e2e-win-01' }
stage('Desktop') {
parallel {
stage("Windows") {
agent { label 'mob-e2e-win-01' }
steps {
pwsh "jenkins\\pipelines\\dotnet\\test_winui.ps1 -Edition ${params.CBL_EDITION} -Version ${params.CBL_VERSION} -Build ${params.CBL_BUILD} -SgwUrl ${params.SGW_URL}"
}
post {
always {
pwsh 'jenkins\\pipelines\\dotnet\\teardown_winui.ps1'
}
}
}
stage("Mac Catalyst") {
agent { label 'mob-e2e-mac-01' }
steps {
shell "jenkins\\pipelines\\dotnet\\test_mac.sh ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD} ${params.SGW_URL}"
}
post {
always {
shell 'jenkins\\pipelines\\dotnet\\teardown_mac.sh'
}
}
}
}
}
stage('iOS') {
options {
lock("mob-e2e-iphone-01")
}
environment {
KEYCHAIN_PASSWORD = credentials('mob-e2e-mac-01-keychain-password')
IOS_TEST_SERVER_IP = "10.100.150.123"
}
agent { label 'mob-e2e-mac-01' }
steps {
shell "jenkins\\pipelines\\dotnet\\test_ios.sh ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD} ${params.SGW_URL}"
}
post {
always {
shell 'jenkins\\pipelines\\dotnet\\teardown_ios.sh'
}
}
}
stage('Android') {
options {
lock("mob-e2e-android-01")
}
agent { label 'mob-e2e-mac-01' }
steps {
pwsh "jenkins\\pipelines\\dotnet\\test_winui.ps1 -Edition ${params.CBL_EDITION} -Version ${params.CBL_VERSION} -Build ${params.CBL_BUILD} -SgwUrl ${params.SGW_URL}"
shell "jenkins\\pipelines\\dotnet\\test_android.sh ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD} ${params.SGW_URL}"
}
post {
always {
pwsh 'jenkins\\pipelines\\dotnet\\teardown_winui.ps1'
post {
always {
shell 'jenkins\\pipelines\\dotnet\\teardown_android.sh'
}
}
}
Expand All @@ -39,4 +86,4 @@ pipeline {
mail bcc: '', body: "Project: <a href='${env.BUILD_URL}'>${env.JOB_NAME}</a> has failed!", cc: '', charset: 'UTF-8', from: 'jenkins@couchbase.com', mimeType: 'text/html', replyTo: 'no-reply@couchbase.com', subject: "${env.JOB_NAME} failed", to: "jim.borden@couchbase.com";
}
}
}
}
9 changes: 9 additions & 0 deletions jenkins/pipelines/dotnet/build_android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/prepare_env.sh

banner "Executing build for .NET $DOTNET_VERSION Android"

pushd $SCRIPT_DIR/../../../servers/dotnet/testserver
$HOME/.dotnet/dotnet publish -f net$DOTNET_VERSION-android -v n
12 changes: 12 additions & 0 deletions jenkins/pipelines/dotnet/build_ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/prepare_env.sh

banner "Executing build for .NET $DOTNET_VERSION iOS"

export DEVELOPER_DIR="/Applications/Xcode-16.1.0.app/"
export MD_APPLE_SDK_ROOT=$DEVELOPER_DIR
pushd $SCRIPT_DIR/../../../servers/dotnet/testserver
security unlock-keychain -p $KEYCHAIN_PASSWORD
$HOME/.dotnet/dotnet build -f net$DOTNET_VERSION-ios -c Release -p:RuntimeIdentifier=ios-arm64 -v n
10 changes: 10 additions & 0 deletions jenkins/pipelines/dotnet/build_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/prepare_env.sh

banner "Executing build for .NET $DOTNET_VERSION Mac Catalyst"

export DEVELOPER_DIR="/Applications/Xcode-16.0.0/"
pushd $SCRIPT_DIR/../../../servers/dotnet/testserver
$HOME/.dotnet/dotnet build -f net$DOTNET_VERSION-maccatalyst -c Release -v n
2 changes: 1 addition & 1 deletion jenkins/pipelines/dotnet/build_winui.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Banner -Text "Executing build for .NET $DOTNET_VERSION WinUI"

# Build
Push-Location $PSScriptRoot\..\..\..\servers\dotnet\testserver\
& $env:LOCALAPPDATA\Microsoft\dotnet\dotnet publish .\testserver.csproj -c Release -f net8.0-windows10.0.19041.0
& $env:LOCALAPPDATA\Microsoft\dotnet\dotnet publish .\testserver.csproj -c Release -f net8.0-windows10.0.19041.0 -v n
Pop-Location
8 changes: 4 additions & 4 deletions jenkins/pipelines/dotnet/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"$schema": "https://packages.couchbase.com/couchbase-lite/testserver.schema.json",
"test-servers": ["http://localhost:8080"],
"sync-gateways": [{"hostname": "localhost", "tls": true}],
"couchbase-servers": [{"hostname": "localhost"}],
"test-servers": ["http://{{test-server-ip}}:8080"],
"sync-gateways": [{"hostname": "{{test-client-ip}}", "tls": true}],
"couchbase-servers": [{"hostname": "{{test-client-ip}}"}],
"api-version": 1,
"logslurp": "localhost:8180",
"logslurp": "{{test-client-ip}}:8180",
"greenboard": {"hostname": "jenkins.mobiledev.couchbase.com", "username": "writer", "password": "couchbase2" }
}
24 changes: 24 additions & 0 deletions jenkins/pipelines/dotnet/prepare_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash -e

export DOTNET_ROOT=$HOME/.dotnet
export DOTNET_VERSION="8.0"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

PREPARE_DOTNET_SCRIPT="$SCRIPT_DIR/prepare_dotnet.sh"

if [ ! -f $PREPARE_DOTNET_SCRIPT ]; then
echo "Downloading prepare_dotnet.sh..."
curl -L https://raw.githubusercontent.com/couchbaselabs/couchbase-mobile-tools/refs/heads/master/dotnet_testing_env/prepare_dotnet_new.sh -o $PREPARE_DOTNET_SCRIPT
fi

source $PREPARE_DOTNET_SCRIPT

function copy_datasets() {
banner "Copying dataset resources"

mkdir -p $SCRIPT_DIR/../../../servers/dotnet/testserver/Resources/Raw
pushd $SCRIPT_DIR/../../../servers/dotnet/testserver/Resources/Raw
cp -fv $SCRIPT_DIR/../../../dataset/server/dbs/*.zip .
cp -Rfv $SCRIPT_DIR/../../../dataset/server/blobs .
popd
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ $# -lt 1 ]; then
exit 1
fi

pushd $SCRIPT_DIR/../testserver
pushd $SCRIPT_DIR/../../../servers/dotnet/testserver

source $SCRIPT_DIR/prepare_env.sh
apk_location=$(find bin/Release/net8.0-android/publish -name "*.apk")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ if [ $# -lt 1 ]; then
exit 1
fi

pushd $SCRIPT_DIR/../testserver
pushd $SCRIPT_DIR/../../../servers/dotnet/testserver

source $SCRIPT_DIR/prepare_env.sh
app_location=$(find bin/Release/net8.0-ios/ -name "*.app")
if [ -z $app_location ]; then
echo "Unable to find APK to install, was it built?"
echo "Unable to find app to install, was it built?"
exit 2
fi

banner "Installing $app_location to device $1..."
$HOME/.dotnet/tools/xharness apple install -a $app_location -t ios-device -o out --device $1
banner "Installing $app_location to device $1"
$HOME/.dotnet/tools/xharness apple mlaunch -- --devname $1 --installdev $app_location
output=$($HOME/.dotnet/tools/xharness apple mlaunch -- --devname $1 --launchdev $app_location 2> /dev/null)
regex="pid ([0-9]+)"
if [[ $output =~ $regex ]]; then
echo -n "${BASH_REMATCH[1]}" > scripts/ios_pid.txt
echo -n "${BASH_REMATCH[1]}" > $SCRIPT_DIR/ios_pid.txt
fi
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd $SCRIPT_DIR/../testserver
pushd $SCRIPT_DIR/../../../servers/dotnet/testserver

app_location=$(find bin/Release/net8.0-maccatalyst -name "*.app")
app_location=$PWD/bin/Release/net8.0-maccatalyst/testserver.app
if [ -z "$app_location" ]; then
echo "Unable to find app to run, was it built?"
exit 1
fi

source $SCRIPT_DIR/prepare_env.sh
banner "Running $app_location"
open $app_location
File renamed without changes.
27 changes: 27 additions & 0 deletions jenkins/pipelines/dotnet/stop_ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

function usage() {
echo "Usage: stop_ios.sh device-id"
echo " device-id The UUID of the device to stop the test server on"
}

if [ $# -lt 1 ]; then
usage
exit 1
fi

pushd $SCRIPT_DIR

source $SCRIPT_DIR/prepare_env.sh
if [ ! -f ios_pid.txt ]; then
echo "Unable to find ios_pid.txt, was the app started using run_ios.sh?"
exit 2
fi

pid=$(cat ios_pid.txt)
rm ios_pid.txt

banner "Stopping com.couchbase.dotnet.testserver ($pid) on device $1"
output=$($HOME/.dotnet/tools/xharness apple mlaunch -- --devname $1 --killdev $pid 2> /dev/null)
File renamed without changes.
21 changes: 21 additions & 0 deletions jenkins/pipelines/dotnet/teardown_android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

source $SCRIPT_DIR/test_common.sh
source $SCRIPT_DIR/prepare_env.sh

banner "Looking up connected Android device"
android_device=$($HOME/.dotnet/tools/xharness android device)
if [ "$android_device" == "" ]; then
echo "Failed to find Android device"
exit 2
else
echo "Found $android_device"
fi

banner "Shutdown Test Server for Android"
$SCRIPT_DIR/stop_android.sh $android_device

banner "Shutdown Environment"
end_tests
18 changes: 18 additions & 0 deletions jenkins/pipelines/dotnet/teardown_ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

source $SCRIPT_DIR/test_common.sh
source $SCRIPT_DIR/prepare_env.sh

banner "Looking up connected iOS device"

ios_devices=$($HOME/.dotnet/tools/xharness apple device ios-device)
ios_device=$(echo $ios_devices | head -1)
echo "Found device $ios_device..."

banner "Shutdown Test Server for iOS"
$SCRIPT_DIR/stop_ios.sh $ios_device

banner "Shutdown Environment"
end_tests
12 changes: 12 additions & 0 deletions jenkins/pipelines/dotnet/teardown_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

source $SCRIPT_DIR/test_common.sh
source $SCRIPT_DIR/prepare_env.sh

banner "Shutdown Test Server for Mac Catalyst"
$SCRIPT_DIR/stop_mac.sh

banner "Shutdown Environment"
end_tests
42 changes: 42 additions & 0 deletions jenkins/pipelines/dotnet/test_android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

source $SCRIPT_DIR/test_common.sh

sgw_url="$4"
if [ $# -lt 3 ]; then
usage
exit 1
fi

prepare_dotnet

modify_package $2 $3
$SCRIPT_DIR/build_android.sh

banner "Looking up connected Android device"
android_device=$($HOME/.dotnet/tools/xharness android device)
if [ "$android_device" == "" ]; then
echo "Failed to find Android device"
exit 2
else
echo "Found $android_device"
fi

banner "Resolving Test Server IP"
test_server_ip=$($HOME/.dotnet/tools/xharness android adb -- shell ifconfig wlan0 | grep "inet addr" | awk '{print substr($2, 6)}')
if [ "$test_server_ip" == "" ]; then
echo "Failed to find Android test server..."
exit 2
else
echo "Resolved to $test_server_ip!"
fi

my_ip=$(ifconfig en0 | grep "inet " | awk '{print $2}')
echo "Detected TDK client IP as $my_ip"

$SCRIPT_DIR/run_android.sh $android_device
$SCRIPT_DIR/../shared/setup_backend.sh $sgw_url

begin_tests $test_server_ip $my_ip
Loading

0 comments on commit 1cca0e7

Please sign in to comment.