Skip to content

Commit 4093dd0

Browse files
committed
update: enhance GitHub Actions workflow to include testing steps and improve caching mechanism
1 parent 70cf7f7 commit 4093dd0

File tree

1 file changed

+59
-29
lines changed

1 file changed

+59
-29
lines changed

.github/workflows/swift.yml

+59-29
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,92 @@
1-
# This workflow builds an iPhone app using Xcode
2-
name: Build iPhone App
1+
name: Build & Test iPhone App
32

43
on:
54
push:
65
branches: [ "main" ]
76
pull_request:
8-
branches: [ "main" ]
97

108
jobs:
119
build:
1210
runs-on: macos-latest
11+
env:
12+
XCODE_VERSION_PATH: "/Applications/Xcode_16.1.app"
13+
WORKSPACE: "ophelia/ophelia.xcodeproj/project.xcworkspace"
14+
SCHEME: "ophelia"
15+
DESTINATION: "platform=iOS Simulator,name=iPhone 16,OS=18.1"
16+
CACHE_KEY_PREFIX: "ophelia-xcode-cache"
1317

1418
steps:
15-
# Check out the repository
1619
- name: Check Out Code
1720
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 1
1823

19-
# Select Xcode 16.1
2024
- name: Select Xcode Version
21-
run: sudo xcode-select -switch /Applications/Xcode_16.1.app
25+
run: sudo xcode-select -switch $XCODE_VERSION_PATH
2226

23-
# Check Xcode version and list simulators
2427
- name: Debug Environment
2528
run: |
2629
echo "Xcode Version:"
2730
xcodebuild -version
2831
echo "Available Simulators:"
2932
xcrun simctl list
3033
31-
# Ensure DerivedData directory exists
32-
- name: Ensure DerivedData Exists
33-
run: mkdir -p ~/Library/Developer/Xcode/DerivedData
34-
35-
# Cache DerivedData
34+
# Use a stable cache key to maximize cache hits based on the project files.
3635
- name: Cache DerivedData
3736
uses: actions/cache@v3
3837
with:
3938
path: ~/Library/Developer/Xcode/DerivedData
40-
key: ${{ runner.os }}-xcode-${{ github.sha }}
39+
key: ${{ env.CACHE_KEY_PREFIX }}-${{ runner.os }}-${{ hashFiles('ophelia/ophelia.xcodeproj/**', 'Package.resolved') }}
4140
restore-keys: |
42-
${{ runner.os }}-xcode-
41+
${{ env.CACHE_KEY_PREFIX }}-${{ runner.os }}-
4342
44-
# List project files for debugging
45-
- name: List Project Directory
46-
run: ls -R ophelia
47-
48-
# Build the app
4943
- name: Build App
5044
run: |
51-
xcodebuild -workspace ophelia/ophelia.xcodeproj/project.xcworkspace \
52-
-scheme ophelia \
53-
-sdk iphonesimulator \
54-
-destination 'platform=iOS Simulator,name=iPhone 16,OS=18.1' \
55-
build
56-
57-
# Debug DerivedData if build fails
58-
- name: Check Derived Data
45+
set -o pipefail && xcodebuild \
46+
-workspace "$WORKSPACE" \
47+
-scheme "$SCHEME" \
48+
-sdk iphonesimulator \
49+
-destination "$DESTINATION" \
50+
build | xcpretty
51+
shell: bash
52+
53+
# Upload logs if build fails for debugging
54+
- name: Upload Logs on Failure
5955
if: failure()
56+
uses: actions/upload-artifact@v3
57+
with:
58+
name: build-logs
59+
path: ~/Library/Logs/DiagnosticReports/
60+
61+
test:
62+
runs-on: macos-latest
63+
needs: build
64+
env:
65+
XCODE_VERSION_PATH: "/Applications/Xcode_16.1.app"
66+
WORKSPACE: "ophelia/ophelia.xcodeproj/project.xcworkspace"
67+
SCHEME: "ophelia"
68+
DESTINATION: "platform=iOS Simulator,name=iPhone 16,OS=18.1"
69+
70+
steps:
71+
- name: Check Out Code
72+
uses: actions/checkout@v4
73+
74+
- name: Select Xcode Version
75+
run: sudo xcode-select -switch $XCODE_VERSION_PATH
76+
77+
- name: Run Tests
6078
run: |
61-
echo "DerivedData Directory:"
62-
ls ~/Library/Developer/Xcode/DerivedData || echo "DerivedData not found"
79+
set -o pipefail && xcodebuild \
80+
-workspace "$WORKSPACE" \
81+
-scheme "$SCHEME" \
82+
-sdk iphonesimulator \
83+
-destination "$DESTINATION" \
84+
test | xcpretty
85+
shell: bash
86+
87+
- name: Upload Test Results on Failure
88+
if: failure()
89+
uses: actions/upload-artifact@v3
90+
with:
91+
name: test-logs
92+
path: ~/Library/Logs/DiagnosticReports/

0 commit comments

Comments
 (0)