Modernize Swift UI (SpriteKit) repository #21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Xcode - Build and Test | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
name: Build and test using xcodebuild | |
runs-on: macos-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Xcode | |
uses: maxim-lobanov/setup-xcode@v1 | |
with: | |
xcode-version: latest-stable | |
- name: Determine Default Scheme | |
run: | | |
# Get the default scheme from the target list | |
scheme=$(xcodebuild -list -json | jq -r '.project.targets[0]') | |
echo "Default scheme detected: $scheme" | |
echo "scheme=$scheme" >> $GITHUB_ENV | |
- name: Identify Xcode Project or Workspace | |
run: | | |
# Check if workspace or project exists, and set the build target | |
if [[ -n "$(ls *.xcworkspace 2>/dev/null)" ]]; then | |
filetype="workspace" | |
file_to_build=$(ls *.xcworkspace | head -n 1) | |
elif [[ -n "$(ls *.xcodeproj 2>/dev/null)" ]]; then | |
filetype="project" | |
file_to_build=$(ls *.xcodeproj | head -n 1) | |
else | |
echo "No .xcworkspace or .xcodeproj found." >&2 | |
exit 1 | |
fi | |
echo "Detected Xcode $filetype: $file_to_build" | |
echo "filetype=$filetype" >> $GITHUB_ENV | |
echo "file_to_build=$file_to_build" >> $GITHUB_ENV | |
- name: Build for iOS | |
env: | |
scheme: ${{ env.scheme }} | |
filetype: ${{ env.filetype }} | |
file_to_build: ${{ env.file_to_build }} | |
run: | | |
# Clean and build the iOS target | |
xcodebuild clean build -scheme "$scheme" -"$filetype" "$file_to_build" -destination "platform=iOS Simulator,name=iPhone 15" | xcpretty && exit ${PIPESTATUS[0]} | |
- name: Test | |
env: | |
scheme: ${{ env.scheme }} | |
filetype: ${{ env.filetype }} | |
file_to_build: ${{ env.file_to_build }} | |
run: | | |
# Run tests | |
xcodebuild test -scheme "$scheme" -"$filetype" "$file_to_build" -destination "platform=iOS Simulator,name=iPhone 15" -testPlan "tictactoeTests" | xcpretty && exit ${PIPESTATUS[0]} | |
- name: Build for macOS | |
env: | |
scheme: ${{ env.scheme }} | |
filetype: ${{ env.filetype }} | |
file_to_build: ${{ env.file_to_build }} | |
run: | | |
# Build the macOS target | |
xcodebuild clean build -scheme "$scheme" -"$filetype" "$file_to_build" -destination "platform=macOS" | xcpretty && exit ${PIPESTATUS[0]} |