코드 폭격기팀에서는 Github Actions를 이용하여 iOS에 대한 빌드 / 테스트 Workflow를 다음 스크립트로 구성했습니다.
name: iOS PR test workflow
on:
pull_request:
branches: [ "iOS/dev" ]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
print_tags:
description: 'True to print to STDOUT'
required: true
type: boolean
tags:
description: 'Test scenario tags'
required: true
type: string
environment:
description: 'Environment to run tests against'
type: environment
required: true
jobs:
build:
name: Build and Test default scheme using any available iPhone simulator
runs-on: macos-13-xlarge
defaults:
run:
working-directory: ./iOS/Layover
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.0.1'
- name: Checkout
uses: actions/checkout@v3
- name: Set Default Scheme
run: |
scheme_list=$(xcodebuild -list -json | tr -d "\\n")
default=$(echo $scheme_list | ruby -e "require 'json'; puts JSON.parse(STDIN.gets)['project']['targets'][0]")
echo $default | cat >default
echo Using default scheme: $default
- name: Build
env:
scheme: ${{ 'default' }}
platform: ${{ 'iOS Simulator' }}
run: |
# xcrun xctrace returns via stderr, not the expected stdout (see <https://developer.apple.com/forums/thread/663959>)
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"`
if [ $scheme = default ]; then scheme=$(cat default); fi
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
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device" -skipPackagePluginValidation -skipMacroValidation
- name: Test
env:
scheme: ${{ 'default' }}
platform: ${{ 'iOS Simulator' }}
run: |
# xcrun xctrace returns via stderr, not the expected stdout (see <https://developer.apple.com/forums/thread/663959>)
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"`
if [ $scheme = default ]; then scheme=$(cat default); fi
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
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild test-without-building -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device" -skipPackagePluginValidation -skipMacroValidation
Github 레포지토리 탭에서 기본으로 제공해주는 iOS 워크플로 파일을 기반으로 해서 저희 팀 프로젝트에 맞게 수정했습니다.
각 워크플로 항목에 대해 설명드리겠습니다.
저희 팀은 PR이 올라오면 해당 PR의 코드에 대해서 빌드가 되는 상태인지, 테스트 코드가 통과된 상태인지 설정해주고 싶었습니다.
그래서 다음과 같이 작성하여 iOS/dev
브랜치를 타겟으로 한 PR이 생성될 경우, 해당 PR에 대해 Workflow를 실행해주도록 설정했습니다.
on:
pull_request:
branches: [ "iOS/dev" ]
이제 어떤 작업을 실행할 지 여러 step으로 구성된 job을 설정합니다.
팀이 로컬에서 Xcode 15.0.1 버전, M1 맥 환경에서 작업하므로, 비슷한 사양에서 빌드, 테스트 하기 위해, runs-on
항목을 macos-13-xlarge로 설정했습니다.
저희 팀은 프로젝트 레포지토리를 iOS와 백엔드가 공유하고, 각각 iOS
, BE
이름의 폴더로 구분하고 있는 상황입니다.
따라서, 각 스텝들은 iOS
폴더 내의 프로젝트를 타겟으로 실행되어야 합니다. defaults
레이블을 이용해 명령어를 실행할 디렉토리를 하위 step들에 지정하였습니다.
jobs:
build:
name: Build and Test default scheme using any available iPhone simulator
runs-on: macos-13-xlarge
defaults:
run:
working-directory: ./iOS/Layover