Repository Public
1#!/usr/bin/env bash2# Immo-Ka iOS v23# File: Scripts/build.sh4# Description: génération du projet, compilation et tests sur les simulateurs dédiés.5# usage : build.sh generate | debug | release | device | test | uitest | run | shot <nom>6#7# Author: Simon-Pierre Boucher8# Contact: contact@spboucher.ai9set -uo pipefail10cd "$(dirname "$0")/.."11SIM="${IMMOKA_SIM:-ImmoKa-v3}"12DD="build/DerivedData"13mkdir -p build/logs build/shots14filter() { grep -v "CoreData: error\|\[error\] CoreData" | grep -E "error:|warning: unre|\*\* |Executed [0-9]+ tests|✘|✔|Testing failed|failed \(|: error|Test run with|Test [Cc]ase .* (passed|failed)" | grep -v "^$" | sed "s|$PWD/||" | awk '!seen[$0]++' | head -"${LINES_MAX:-60}"; }15generate() {16 xcodegen generate --quiet || return 117 # Info de débogage = Info de production + réseau local (API v2 de développement sur http://127.0.0.1:18097)18 cp ImmoKa/Resources/Info.plist ImmoKa/Resources/Info-Debug.plist19 /usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsLocalNetworking true" ImmoKa/Resources/Info-Debug.plist20}21udid() { xcrun simctl list devices | grep -F "$SIM (" | head -1 | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/'; }22# courtier d'essai de la préproduction (Scripts/courtier-essai.sh) : passé aux tests de messagerie23if [ -f build/courtier.env ]; then24 # shellcheck disable=SC109125 . build/courtier.env26 export TEST_RUNNER_IMMOKA_BROKER_EMAIL="${GE:-}" TEST_RUNNER_IMMOKA_BROKER_PASSWORD="${GPW:-}" TEST_RUNNER_IMMOKA_BROKER_ID="${GBROKER:-64215753413768}"27fi28# préproduction des comptes (tests de compte et de messagerie), thème des captures (IMMOKA_APPEARANCE=dark)29export TEST_RUNNER_IMMOKA_ACCOUNT_BASE_URL="${IMMOKA_ACCOUNT_API:-https://immoka-comptes.51-161-112-61.sslip.io}"30export TEST_RUNNER_IMMOKA_APPEARANCE="${IMMOKA_APPEARANCE:-light}"31case "${1:-debug}" in32 generate) generate && echo "projet généré" ;;33 debug)34 generate35 xcodebuild -project ImmoKa.xcodeproj -scheme ImmoKa -configuration Debug -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" build 2>&1 | tee build/logs/debug.log | filter ;;36 release)37 generate38 xcodebuild -project ImmoKa.xcodeproj -scheme ImmoKa -configuration Release -destination "generic/platform=iOS Simulator" -derivedDataPath "$DD" build 2>&1 | tee build/logs/release.log | filter ;;39 device)40 generate41 xcodebuild -project ImmoKa.xcodeproj -scheme ImmoKa -configuration Debug -destination "generic/platform=iOS" -derivedDataPath "$DD" -allowProvisioningUpdates build 2>&1 | tee build/logs/device.log | filter ;;42 test)43 shift || true; generate44 xcodebuild -project ImmoKa.xcodeproj -scheme ImmoKa -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" -only-testing:ImmoKaTests "$@" test 2>&1 | tee build/logs/test.log | filter ;;45 uitest)46 shift || true; generate47 # l'app sous test choisit son service seule (v2 locale, sinon production) ; un uid réel est passé au test de la fiche48 API="${IMMOKA_BASE_URL:-https://www.immo-ka.com}"49 export TEST_RUNNER_IMMOKA_TEST_UID="$(curl -s -m 30 "$API/api/v3/search?city=Gatineau&limit=60&sort=recent&positioned=1&family=unifamiliale" | python3 -c "import json,sys; d=json.load(sys.stdin); print(next(l['uid'] for l in d['items'] if l.get('n_images') and l.get('url') and (l.get('price') or 0) > 100000 and (l.get('estimate') or {}).get('ask_position')))")"50 [ -n "$TEST_RUNNER_IMMOKA_TEST_UID" ] || { echo "aucune propriété d'essai (API injoignable : $API)"; exit 1; }51 rm -rf "build/results/uitest-${SIM// /_}.xcresult"52 xcodebuild -project ImmoKa.xcodeproj -scheme ImmoKa -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" -only-testing:ImmoKaUITests -parallel-testing-enabled NO \53 -resultBundlePath "build/results/uitest-${SIM// /_}.xcresult" "$@" test 2>&1 | tee build/logs/uitest.log | filter54 rm -rf "build/shots/uitest-${SIM// /_}"; mkdir -p "build/shots/uitest-${SIM// /_}"55 xcrun xcresulttool export attachments --path "build/results/uitest-${SIM// /_}.xcresult" --output-path "build/shots/uitest-${SIM// /_}" >/dev/null 2>&1 || true ;;56 run)57 # installe et lance l'app sur le simulateur ; arguments suivants = arguments de lancement58 U="$(udid)"; xcrun simctl boot "$U" 2>/dev/null; xcrun simctl bootstatus "$U" >/dev/null 2>&159 xcrun simctl install "$U" "$DD/Build/Products/Debug-iphonesimulator/ImmoKa.app" && xcrun simctl terminate "$U" com.spboucher.immoka.v2 >/dev/null 2>&160 xcrun simctl launch "$U" com.spboucher.immoka.v2 "${@:2}" ;;61 shot)62 U="$(udid)"; xcrun simctl io "$U" screenshot "build/shots/${2:-capture}.png" >/dev/null 2>&1 && echo "build/shots/${2:-capture}.png" ;;63 *) echo "usage: build.sh generate|debug|release|device|test|uitest|run [args]|shot <nom>"; exit 2 ;;64esac65