1+ name : Pull request
2+
3+ on :
4+ pull_request :
5+ types : [opened, reopened, synchronize, ready_for_review]
6+ push :
7+ branches :
8+ - main
9+
10+ concurrency :
11+ group : ${{ github.workflow }}-${{ github.ref }}
12+ cancel-in-progress : true
13+
14+ env :
15+ XCODE_VERSION : " 16.3"
16+
17+ jobs :
18+ prepare :
19+ runs-on : macos-15
20+ outputs :
21+ platforms : ${{ steps.platforms.outputs.platforms }}
22+ scheme : ${{ steps.scheme.outputs.scheme }}
23+ steps :
24+ - uses : actions/checkout@v4
25+ - name : Setup Xcode
26+ run : sudo xcode-select -s /Applications/Xcode_$XCODE_VERSION.app
27+
28+ - name : Setup mise
29+ env :
30+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
31+ run : |
32+ curl https://mise.run | sh
33+ mise install
34+ - name : Run linters
35+ run : mise lint
36+
37+ - name : Extract platforms
38+ id : platforms
39+ run : |
40+ platforms=$(swift package dump-package | jq -r '[.platforms[].platformName] | unique | @json')
41+ echo "Platforms: $platforms"
42+ echo "platforms=$platforms" >> $GITHUB_OUTPUT
43+
44+ - name : Extract scheme
45+ id : scheme
46+ run : |
47+ repo=$(basename $GITHUB_REPOSITORY)
48+ schemes=$(xcodebuild -list)
49+ echo "$schemes"
50+
51+ if echo "$schemes" | grep -q "$repo-Package"; then
52+ scheme="$repo-Package"
53+ elif echo "$schemes" | grep -q "$repo"; then
54+ scheme="$repo"
55+ else
56+ echo "Unable to select a scheme"
57+ exit 1
58+ fi
59+
60+ echo "Selected scheme: $scheme"
61+ echo "scheme=$scheme" >> $GITHUB_OUTPUT
62+
63+ build-and-test :
64+ needs : prepare
65+ runs-on : macos-15
66+ strategy :
67+ fail-fast : false
68+ matrix :
69+ platform : ${{ fromJSON(needs.prepare.outputs.platforms) }}
70+ steps :
71+ - uses : actions/checkout@v4
72+ - name : Setup Xcode
73+ run : sudo xcode-select -s /Applications/Xcode_$XCODE_VERSION.app
74+
75+ - name : Map destinations
76+ if : ${{ matrix.platform != 'macos' }}
77+ id : destination
78+ run : |
79+ case "${{ matrix.platform }}" in
80+ maccatalyst)
81+ destination="platform=macOS,variant=Mac Catalyst"
82+ ;;
83+ ios)
84+ destination="platform=iOS Simulator,name=iPhone 16 Pro Max,OS=latest"
85+ ;;
86+ tvos)
87+ destination="platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest"
88+ ;;
89+ watchos)
90+ destination="platform=watchOS Simulator,name=Apple Watch Series 10 (46mm),OS=latest"
91+ ;;
92+ visionos)
93+ destination="platform=visionOS Simulator,name=Apple Vision Pro,OS=latest"
94+ ;;
95+ *)
96+ echo "Unknown platform: ${{ matrix.platform }}"
97+ exit 1
98+ ;;
99+ esac
100+ echo "destination=$destination" >> $GITHUB_OUTPUT
101+
102+ - name : Build (SPM)
103+ if : ${{ matrix.platform == 'macos' }}
104+ run : swift build
105+
106+ - name : Build (Xcode)
107+ if : ${{ matrix.platform != 'macos' }}
108+ run : |
109+ set -o pipefail
110+ xcodebuild build \
111+ -scheme ${{ needs.prepare.outputs.scheme }} \
112+ -destination "${{ steps.destination.outputs.destination }}" | \
113+ xcbeautify --renderer github-actions
114+
115+ - name : Test (SPM)
116+ if : ${{ matrix.platform == 'macos' }}
117+ run : |
118+ set -o pipefail
119+ swift test --enable-code-coverage | xcbeautify --renderer github-actions
120+ TEST_BUNDLE=$(find .build/debug/ -name "*.xctest" | head -n 1)
121+ TEST_EXECUTABLE="$TEST_BUNDLE/Contents/MacOS/$(basename "$TEST_BUNDLE" .xctest)"
122+ xcrun llvm-cov export -format="lcov" \
123+ -instr-profile .build/debug/codecov/default.profdata \
124+ "$TEST_EXECUTABLE" > info.lcov
125+
126+ - name : Test (Xcode)
127+ if : ${{ matrix.platform != 'macos' }}
128+ run : |
129+ set -o pipefail
130+ xcodebuild test \
131+ -scheme ${{ needs.prepare.outputs.scheme }} \
132+ -destination "${{ steps.destination.outputs.destination }}" | \
133+ xcbeautify --renderer github-actions
134+
135+ - name : Check coverage (SPM)
136+ if : ${{ matrix.platform == 'macos' }}
137+ uses : codecov/codecov-action@v5
138+ with :
139+ fail_ci_if_error : true
0 commit comments