|
| 1 | +name: iOS starter workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + name: Build and Test default scheme using any available iPhone simulator |
| 12 | + runs-on: macos-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + - name: Set Default Scheme |
| 18 | + run: | |
| 19 | + scheme_list=$(xcodebuild -list -json | tr -d "\n") |
| 20 | + default=$(echo $scheme_list | ruby -e "require 'json'; puts JSON.parse(STDIN.gets)['project']['targets'][0]") |
| 21 | + echo $default | cat >default |
| 22 | + echo Using default scheme: $default |
| 23 | + - name: Build |
| 24 | + env: |
| 25 | + scheme: ${{ 'default' }} |
| 26 | + platform: ${{ 'iOS Simulator' }} |
| 27 | + run: | |
| 28 | + # xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959) |
| 29 | + device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"` |
| 30 | + if [ $scheme = default ]; then scheme=$(cat default); fi |
| 31 | + if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi |
| 32 | + file_to_build=`echo $file_to_build | awk '{$1=$1;print}'` |
| 33 | + xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device" |
| 34 | + - name: Test |
| 35 | + env: |
| 36 | + scheme: ${{ 'default' }} |
| 37 | + platform: ${{ 'iOS Simulator' }} |
| 38 | + run: | |
| 39 | + # xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959) |
| 40 | + device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"` |
| 41 | + if [ $scheme = default ]; then scheme=$(cat default); fi |
| 42 | + if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi |
| 43 | + file_to_build=`echo $file_to_build | awk '{$1=$1;print}'` |
| 44 | + xcodebuild test-without-building -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device" |
0 commit comments