Repository Public
1#!/usr/bin/env bash2# SP Drive iOS3# File: Scripts/build.sh4# Description: Generate the Xcode project, build, test (filtered xcodebuild output; full logs in build/logs).5# usage: build.sh generate | debug | release | core | test [args] | uitest [args] | device6# SPDRIVE_SIM selects the simulator (default "SPDrive iPhone"; "SPDrive iPad" for the tablet).7#8# Author: Simon-Pierre Boucher9# Contact: contact@spboucher.ai10set -uo pipefail11cd "$(dirname "$0")/.."12SIM="${SPDRIVE_SIM:-SPDrive iPhone}"13DD="build/DerivedData"14mkdir -p build/logs15filter() { grep -E "error:|warning: unre|warning: var|\*\* |Test Suite .* (passed|failed)|Executed [0-9]+ tests|✘|✔|Testing failed|failed \(|: error|Test run with|Test case .* (passed|failed)" | grep -v "^$" | sed "s|$PWD/||" | awk '!seen[$0]++' | head -"${LINES_MAX:-80}"; }16generate() {17 # Debug Info.plists = production ones + local networking (the disposable test backend is reached at http://localhost through an SSH tunnel)18 for p in Resources FileProviderExtension ShareExtension; do19 cp "$p/Info.plist" "$p/Info-Debug.plist"20 /usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsLocalNetworking true" "$p/Info-Debug.plist"21 done22 xcodegen generate --quiet23}24testenv() {25 # credentials of the disposable backend, handed to the test runner and, through it, to the app under test26 set -a; . "$HOME/.config/spdrive-ios-test/credentials.env"; set +a27 curl -fsS -m 5 "$SPDRIVE_TEST_URL/api/v1/health/live" >/dev/null || { echo "test backend unreachable: Scripts/test-server.sh up (or: tunnel)"; exit 1; }28 export TEST_RUNNER_SPDRIVE_TEST_URL="$SPDRIVE_TEST_URL" TEST_RUNNER_SPDRIVE_TEST_TOKEN="$SPDRIVE_TEST_TOKEN" TEST_RUNNER_SPDRIVE_TEST_TOKEN_B="$SPDRIVE_TEST_TOKEN_B"29 # the app-hosted unit tests run inside the app: it starts signed in to the test backend, from a clean local state30 export TEST_RUNNER_SPDRIVE_BASE_URL="$SPDRIVE_TEST_URL" TEST_RUNNER_SPDRIVE_RESET=131 # simulator tests use the second account (the Mac-side core tests fill the first one with hundreds of folders)32 export TEST_RUNNER_SPDRIVE_TEST_TOKEN="$SPDRIVE_TEST_TOKEN_B"33 # 2.0: a third account plays « someone else » (grants), reached by its exact e-mail address34 export TEST_RUNNER_SPDRIVE_TEST_TOKEN_C="${SPDRIVE_TEST_TOKEN_C:-}" TEST_RUNNER_SPDRIVE_TEST_EMAIL_B="${SPDRIVE_TEST_EMAIL_B:-}" TEST_RUNNER_SPDRIVE_TEST_EMAIL_C="${SPDRIVE_TEST_EMAIL_C:-}"35}36case "${1:-debug}" in37 generate) generate && echo "projet généré" ;;38 debug)39 generate40 xcodebuild -project SPDrive.xcodeproj -scheme SPDrive -configuration Debug -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" build 2>&1 | tee build/logs/debug.log | filter ;;41 release)42 generate43 xcodebuild -project SPDrive.xcodeproj -scheme SPDrive -configuration Release -destination "generic/platform=iOS Simulator" -derivedDataPath "$DD" build 2>&1 | tee build/logs/release.log | filter ;;44 device)45 # signed build for a real device (development signing, Xcode account)46 generate47 xcodebuild -project SPDrive.xcodeproj -scheme SPDrive -configuration Debug -destination "generic/platform=iOS" -derivedDataPath "$DD" -allowProvisioningUpdates build 2>&1 | tee build/logs/device.log | filter ;;48 core)49 # Core + Sync on the Mac, against the disposable backend (fast)50 swift test --no-parallel --scratch-path build/spm "${@:2}" 2>&1 | grep -E "✘|✔|error|recorded|Test run" | cut -c1-400 ;;51 test)52 shift || true; generate; testenv53 xcodebuild -project SPDrive.xcodeproj -scheme SPDrive -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" -only-testing:SPDriveTests "$@" test 2>&1 | tee build/logs/test.log | filter ;;54 uitest)55 shift || true; generate; testenv56 rm -rf "build/results/uitest-${SIM// /_}.xcresult"57 xcodebuild -project SPDrive.xcodeproj -scheme SPDrive -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" -only-testing:SPDriveUITests -parallel-testing-enabled NO \58 -resultBundlePath "build/results/uitest-${SIM// /_}.xcresult" "$@" test 2>&1 | tee build/logs/uitest.log | filter59 rm -rf "build/shots/${SIM// /_}"; mkdir -p "build/shots/${SIM// /_}"60 xcrun xcresulttool export attachments --path "build/results/uitest-${SIM// /_}.xcresult" --output-path "build/shots/${SIM// /_}" >/dev/null 2>&1 || true ;;61 *) echo "usage: build.sh generate|debug|release|device|core|test|uitest"; exit 2 ;;62esac63