Repository Public
1#!/usr/bin/env bash2# Fabri-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="${FABRIKA_SIM:-FabriKa 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 (tests hors ligne et API de développement en http://127.0.0.1)18 cp FabriKa/Resources/Info.plist FabriKa/Resources/Info-Debug.plist19 /usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsLocalNetworking true" FabriKa/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 FabriKa.xcodeproj -scheme FabriKa -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 FabriKa.xcodeproj -scheme FabriKa -configuration Release -destination "generic/platform=iOS Simulator" -derivedDataPath "$DD" build 2>&1 | tee build/logs/release.log | filter ;;30 device)31 generate32 xcodebuild -project FabriKa.xcodeproj -scheme FabriKa -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 FabriKa.xcodeproj -scheme FabriKa -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" -only-testing:FabriKaTests "$@" test 2>&1 | tee build/logs/test.log | filter ;;36 uitest)37 shift || true; generate38 # l'app sous test parle à la préproduction de la v239 curl -fsS -m 10 https://fabrika-v2.51-161-112-61.sslip.io/api/version >/dev/null || { echo "API de préproduction injoignable"; exit 1; }40 mkdir -p build/results41 rm -rf "build/results/uitest-${SIM// /_}.xcresult"42 xcodebuild -project FabriKa.xcodeproj -scheme FabriKa -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath "$DD" -only-testing:FabriKaUITests -parallel-testing-enabled NO \43 -resultBundlePath "build/results/uitest-${SIM// /_}.xcresult" "$@" test 2>&1 | tee build/logs/uitest.log | filter44 rm -rf "build/shots/uitest-${SIM// /_}"; mkdir -p "build/shots/uitest-${SIM// /_}"45 xcrun xcresulttool export attachments --path "build/results/uitest-${SIM// /_}.xcresult" --output-path "build/shots/uitest-${SIM// /_}" >/dev/null 2>&1 || true ;;46 run)47 # installe et lance l'app sur le simulateur ; arguments suivants = arguments de lancement48 U="$(udid)"; xcrun simctl boot "$U" 2>/dev/null; xcrun simctl bootstatus "$U" >/dev/null 2>&149 xcrun simctl install "$U" "$DD/Build/Products/Debug-iphonesimulator/FabriKa.app" && xcrun simctl terminate "$U" com.spboucher.fabrika.v2 >/dev/null 2>&150 xcrun simctl launch "$U" com.spboucher.fabrika.v2 "${@:2}" ;;51 shot)52 U="$(udid)"; xcrun simctl io "$U" screenshot "build/shots/${2:-capture}.png" >/dev/null 2>&1 && echo "build/shots/${2:-capture}.png" ;;53 *) echo "usage: build.sh generate|debug|release|device|test|uitest|run [args]|shot <nom>"; exit 2 ;;54esac55