Repository Public
1#!/usr/bin/env bash2# Auto-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="${AUTOKA_SIM:-AutoKa v2 iPhone}"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 de développement par le tunnel http://127.0.0.1:18098)18 cp AutoKa/Resources/Info.plist AutoKa/Resources/Info-Debug.plist19 /usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsLocalNetworking true" AutoKa/Resources/Info-Debug.plist20}21udid() { xcrun simctl list devices | grep -F "$SIM (" | head -1 | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/'; }22case "${1:-debug}" in23 generate) generate && echo "projet généré" ;;24 debug)25 generate26 xcodebuild -project AutoKa.xcodeproj -scheme AutoKa -configuration Debug -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" build 2>&1 | tee build/logs/debug.log | filter ;;27 release)28 generate29 xcodebuild -project AutoKa.xcodeproj -scheme AutoKa -configuration Release -destination "generic/platform=iOS Simulator" -derivedDataPath "$DD" build 2>&1 | tee build/logs/release.log | filter ;;30 device)31 generate32 xcodebuild -project AutoKa.xcodeproj -scheme AutoKa -configuration Debug -destination "generic/platform=iOS" -derivedDataPath "$DD" -allowProvisioningUpdates build 2>&1 | tee build/logs/device.log | filter ;;33 test)34 shift || true; generate35 xcodebuild -project AutoKa.xcodeproj -scheme AutoKa -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" -only-testing:AutoKaTests "$@" test 2>&1 | tee build/logs/test.log | filter ;;36 uitest)37 shift || true; generate38 # l'app sous test choisit son service seule (tunnel de développement, sinon préproduction) ; un vrai véhicule39 # (voiture avec verdict, photos et kilométrage) est passé au test de la fiche40 API="$(curl -fsS -m 3 http://127.0.0.1:18098/api/version >/dev/null 2>&1 && echo http://127.0.0.1:18098 || echo https://autoka-v2.51-161-112-61.sslip.io)"41 export TEST_RUNNER_AUTOKA_TEST_UID="$(curl -s -m 30 "$API/api/search?make=toyota&avec_photos=1&page_size=40" | python3 -c "import json,sys; d=json.load(sys.stdin); print(next(l['uid'] for l in d['listings'] if l.get('price_verdict') and l.get('mileage_km') and l.get('photos_reelles', 0) > 3))")"42 [ -n "$TEST_RUNNER_AUTOKA_TEST_UID" ] || { echo "aucun véhicule d'essai (API injoignable : $API)"; exit 1; }43 mkdir -p build/results44 rm -rf "build/results/uitest-${SIM// /_}.xcresult"45 xcodebuild -project AutoKa.xcodeproj -scheme AutoKa -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" -only-testing:AutoKaUITests -parallel-testing-enabled NO \46 -resultBundlePath "build/results/uitest-${SIM// /_}.xcresult" "$@" test 2>&1 | tee build/logs/uitest.log | filter47 rm -rf "build/shots/uitest-${SIM// /_}"; mkdir -p "build/shots/uitest-${SIM// /_}"48 xcrun xcresulttool export attachments --path "build/results/uitest-${SIM// /_}.xcresult" --output-path "build/shots/uitest-${SIM// /_}" >/dev/null 2>&1 || true ;;49 run)50 # installe et lance l'app sur le simulateur ; arguments suivants = arguments de lancement51 U="$(udid)"; xcrun simctl boot "$U" 2>/dev/null; xcrun simctl bootstatus "$U" >/dev/null 2>&152 xcrun simctl install "$U" "$DD/Build/Products/Debug-iphonesimulator/AutoKa.app" && xcrun simctl terminate "$U" com.spboucher.autoka.v2 >/dev/null 2>&153 xcrun simctl launch "$U" com.spboucher.autoka.v2 "${@:2}" ;;54 shot)55 U="$(udid)"; xcrun simctl io "$U" screenshot "build/shots/${2:-capture}.png" >/dev/null 2>&1 && echo "build/shots/${2:-capture}.png" ;;56 *) echo "usage: build.sh generate|debug|release|device|test|uitest|run [args]|shot <nom>"; exit 2 ;;57esac58