Skip to content

Commit 6ad363f

Browse files
ci: Fix build failures for sample apps for release commits (#6689)
Only keep the SentryDistribution target for the Package.swift file when compiling the sample apps.
1 parent a7a6331 commit 6ad363f

File tree

5 files changed

+182
-73
lines changed

5 files changed

+182
-73
lines changed

.github/actions/prepare-package.swift/action.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ jobs:
9898

9999
steps:
100100
- uses: actions/checkout@v5
101+
102+
# As the DistributionSample project uses local SPM, xcodebuild resolves SPM dependencies for all
103+
# sample projects. The Package.swift references binary targets, which in release branch commits points
104+
# to non-existent download URLs. This creates chicken-egg failures when building these sample apps for
105+
# a release commit build. When building these sample apps for a release commit, xcodebuild tries to
106+
# resolve all SPM dependencies, including the binary targets pointing to these non-existent URLs. The
107+
# sample projects don't use SPM for including Sentry. Only the DistributionSample uses local SPM.
108+
# Therefore, we only keep the local DistributionSample reference in the Package.swift as a workaround.
109+
- name: Only keep distribution lib and target in Package.swift
110+
run: ./scripts/prepare-package.sh --only-keep-distribution true
111+
101112
- run: ./scripts/ci-select-xcode.sh 16.4
102113
- run: make init-ci-build
103114
- run: make xcode-ci
@@ -129,12 +140,15 @@ jobs:
129140
build-distribution:
130141
name: Build the distribution framework
131142
runs-on: macos-15
143+
# Don't run this on release branches, cause the SPM Package.swift points to the unreleased versions.
144+
if: startsWith(github.ref, 'refs/heads/release/') == false && (github.event_name != 'pull_request' || needs.files-changed.outputs.run_build_for_prs == 'true')
132145
needs: files-changed
133146
steps:
134147
- uses: actions/checkout@v5
135148

136149
- run: ./scripts/ci-select-xcode.sh 16.4
137150
shell: sh
151+
138152
- run: rm -r Sentry.xcodeproj && rm -r Sentry.xcworkspace
139153
- run: set -o pipefail && NSUnbufferedIO=YES xcodebuild build -scheme SentryDistribution -sdk iphoneos -destination 'generic/platform=iphoneos' | tee raw-build-output-spm.log | xcbeautify
140154
shell: sh

.github/workflows/release.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ jobs:
142142
pattern: xcframework-${{github.sha}}-*
143143
merge-multiple: true
144144
- name: Prepare Package.swift
145-
uses: ./.github/actions/prepare-package.swift
146-
with:
147-
is-pr: ${{ github.event_name == 'pull_request' }}
145+
shell: bash
146+
run: |
147+
./scripts/prepare-package.sh \
148+
--package-file Package.swift \
149+
--is-pr "${{ github.event_name == 'pull_request' }}" \
150+
--change-path true
148151
- run: ./scripts/ci-select-xcode.sh 16.4
149152
- run: swift build
150153
working-directory: Samples/macOS-SPM-CommandLine
@@ -165,9 +168,12 @@ jobs:
165168
pattern: xcframework-${{github.sha}}-*
166169
merge-multiple: true
167170
- name: Prepare Package.swift
168-
uses: ./.github/actions/prepare-package.swift
169-
with:
170-
is-pr: ${{ github.event_name == 'pull_request' }}
171+
shell: bash
172+
run: |
173+
./scripts/prepare-package.sh \
174+
--package-file Package.swift \
175+
--is-pr "${{ github.event_name == 'pull_request' }}" \
176+
--change-path true
171177
- run: ./scripts/ci-select-xcode.sh 16.4
172178
- run: swift build
173179
working-directory: Samples/SPM-Dynamic
@@ -188,9 +194,12 @@ jobs:
188194
pattern: xcframework-${{github.sha}}-*
189195
merge-multiple: true
190196
- name: Prepare Package.swift
191-
uses: ./.github/actions/prepare-package.swift
192-
with:
193-
is-pr: ${{ github.event_name == 'pull_request' }}
197+
shell: bash
198+
run: |
199+
./scripts/prepare-package.sh \
200+
--package-file Package.swift \
201+
--is-pr "${{ github.event_name == 'pull_request' }}" \
202+
--change-path true
194203
- run: ./scripts/ci-select-xcode.sh 16.4
195204
- run: swift build
196205
- name: Run CI Diagnostics
@@ -210,9 +219,12 @@ jobs:
210219
pattern: xcframework-${{github.sha}}-*
211220
merge-multiple: true
212221
- name: Prepare Package.swift
213-
uses: ./.github/actions/prepare-package.swift
214-
with:
215-
is-pr: ${{ github.event_name == 'pull_request' }}
222+
shell: bash
223+
run: |
224+
./scripts/prepare-package.sh \
225+
--package-file Package.swift \
226+
--is-pr "${{ github.event_name == 'pull_request' }}" \
227+
--change-path true
216228
- run: ./scripts/ci-select-xcode.sh 16.4
217229
- run: set -o pipefail &&xcodebuild build -scheme visionOS-SPM -sdk xros -destination 'generic/platform=xros' | tee raw-build-output-spm-visionOS.log | xcbeautify
218230
working-directory: Samples/visionOS-SPM

.github/workflows/test.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ jobs:
100100
steps:
101101
- uses: actions/checkout@v5
102102
- name: Prepare Package.swift
103-
uses: ./.github/actions/prepare-package.swift
104-
with:
105-
is-pr: ${{ github.event_name == 'pull_request' }}
106-
change-path: false
107-
remove-duplicate: true
103+
shell: bash
104+
run: |
105+
./scripts/prepare-package.sh \
106+
--package-file Package.swift \
107+
--is-pr "${{ github.event_name == 'pull_request' }}" \
108+
--remove-duplicate true \
109+
--change-path false
108110
- run: rm -r Sentry.xcodeproj && rm -r Sentry.xcworkspace
109111
- run: set -o pipefail && NSUnbufferedIO=YES SKIP_BINARIES=1 xcodebuild test -scheme Sentry-Package -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=18.4,name=iPhone 16 Pro' | tee raw-test-output-distribution.log | xcbeautify --preserve-unbeautified
110112
shell: sh

scripts/prepare-package.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
usage() {
6+
cat <<'USAGE'
7+
Usage: prepare-package.sh [options]
8+
9+
Options:
10+
--package-file PATH Path to the Package.swift file (default: Package.swift)
11+
--is-pr true|false Whether this run simulates a pull request (default: false)
12+
--remove-duplicate true|false
13+
Whether to strip duplicate targets (default: false)
14+
--change-path true|false Whether to swap SPM binary URLs for local paths (default: false)
15+
--only-keep-distribution true|false
16+
Whether to keep only SentryDistribution product/target (default: false)
17+
-h, --help Show this help message
18+
USAGE
19+
}
20+
21+
is_enabled() {
22+
case "$1" in
23+
true|TRUE|1|yes|YES|on|ON) return 0 ;;
24+
*) return 1 ;;
25+
esac
26+
}
27+
28+
PACKAGE_FILE="Package.swift"
29+
IS_PR="false"
30+
REMOVE_DUPLICATE="false"
31+
CHANGE_PATH="false"
32+
ONLY_KEEP_DISTRIBUTION="false"
33+
34+
while [[ $# -gt 0 ]]; do
35+
case "$1" in
36+
--package-file)
37+
[[ $# -lt 2 ]] && { echo "Missing value for $1" >&2; exit 1; }
38+
PACKAGE_FILE="$2"
39+
shift 2
40+
;;
41+
--is-pr)
42+
[[ $# -lt 2 ]] && { echo "Missing value for $1" >&2; exit 1; }
43+
IS_PR="$2"
44+
shift 2
45+
;;
46+
--remove-duplicate)
47+
[[ $# -lt 2 ]] && { echo "Missing value for $1" >&2; exit 1; }
48+
REMOVE_DUPLICATE="$2"
49+
shift 2
50+
;;
51+
--change-path)
52+
[[ $# -lt 2 ]] && { echo "Missing value for $1" >&2; exit 1; }
53+
CHANGE_PATH="$2"
54+
shift 2
55+
;;
56+
--only-keep-distribution)
57+
[[ $# -lt 2 ]] && { echo "Missing value for $1" >&2; exit 1; }
58+
ONLY_KEEP_DISTRIBUTION="$2"
59+
shift 2
60+
;;
61+
-h|--help)
62+
usage
63+
exit 0
64+
;;
65+
*)
66+
echo "Unknown option: $1" >&2
67+
usage >&2
68+
exit 1
69+
;;
70+
esac
71+
done
72+
73+
if [[ ! -f "$PACKAGE_FILE" ]]; then
74+
echo "Package file not found: $PACKAGE_FILE" >&2
75+
exit 1
76+
fi
77+
78+
if is_enabled "$IS_PR"; then
79+
# Remove Sentry-Dynamic-WithARM64e target definitions and clean up empty binary blocks.
80+
sed -i '' '/Sentry-Dynamic-WithARM64e/d' "$PACKAGE_FILE"
81+
sed -i '' '/Sentry-WithoutUIKitOrAppKit-WithARM64e/d' "$PACKAGE_FILE"
82+
sed -i '' '/^[[:space:]]*\.binaryTarget($/{N;/\n[[:space:]]*),\{0,1\}$/d;}' "$PACKAGE_FILE"
83+
fi
84+
85+
if is_enabled "$REMOVE_DUPLICATE"; then
86+
sed -i '' '/Sentry-Dynamic/d' "$PACKAGE_FILE"
87+
sed -i '' '/Sentry-WithoutUIKitOrAppKit/d' "$PACKAGE_FILE"
88+
sed -i '' '/^[[:space:]]*\.binaryTarget($/{N;/\n[[:space:]]*),\{0,1\}$/d;}' "$PACKAGE_FILE"
89+
fi
90+
91+
if is_enabled "$CHANGE_PATH"; then
92+
# Remove Sentry binary framework URLs and convert checksums to local paths.
93+
sed -i '' 's/url: "https:\/\/github\.com\/getsentry\/sentry-cocoa\/releases\/download\/.*"//g' "$PACKAGE_FILE"
94+
sed -i '' 's/checksum: ".*" \/\/Sentry-Static/path: "Sentry.xcframework.zip"/g' "$PACKAGE_FILE"
95+
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic-WithARM64e/path: "Sentry-Dynamic-WithARM64e.xcframework.zip"/g' "$PACKAGE_FILE"
96+
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic/path: "Sentry-Dynamic.xcframework.zip"/g' "$PACKAGE_FILE"
97+
sed -i '' 's/checksum: ".*" \/\/Sentry-WithoutUIKitOrAppKit-WithARM64e/path: "Sentry-WithoutUIKitOrAppKit-WithARM64e.xcframework.zip"/g' "$PACKAGE_FILE"
98+
sed -i '' 's/checksum: ".*" \/\/Sentry-WithoutUIKitOrAppKit/path: "Sentry-WithoutUIKitOrAppKit.xcframework.zip"/g' "$PACKAGE_FILE"
99+
100+
# Clean up orphaned commas and fix syntax.
101+
sed -i '' '/^[[:space:]]*,$/d' "$PACKAGE_FILE"
102+
sed -i '' 's/name: "Sentry\(-.*\)\?"$/name: "Sentry\1",/g' "$PACKAGE_FILE"
103+
sed -i '' 's/platforms: \[\.iOS(\.v11), \.macOS(\.v10_13), \.tvOS(\.v11), \.watchOS(\.v4)\]$/platforms: [.iOS(.v11), .macOS(.v10_13), .tvOS(.v11), .watchOS(.v4)],/g' "$PACKAGE_FILE"
104+
fi
105+
106+
if is_enabled "$ONLY_KEEP_DISTRIBUTION"; then
107+
# Remove all binary targets.
108+
sed -i '' '/^[[:space:]]*\.binaryTarget(/,/^[[:space:]]*),\{0,1\}$/d' "$PACKAGE_FILE"
109+
110+
# Keep only the SentryDistribution library in the products array.
111+
sed -i '' '/^var products: \[Product\] = \[/,/^]/c\
112+
var products: [Product] = [\
113+
.library(name: "SentryDistribution", targets: ["SentryDistribution"]),\
114+
]\
115+
' "$PACKAGE_FILE"
116+
117+
# Keep only the SentryDistribution target in the targets array.
118+
sed -i '' '/^var targets: \[Target\] = \[/,/^]/c\
119+
var targets: [Target] = [\
120+
.target(name: "SentryDistribution", path: "Sources/SentryDistribution"),\
121+
]\
122+
' "$PACKAGE_FILE"
123+
124+
# Replace dependency declarations with an empty list.
125+
sed -i '' '/^ dependencies: \[/,/^ ],/c\
126+
dependencies: [],\
127+
' "$PACKAGE_FILE"
128+
129+
# Remove conditional append blocks that reintroduce other targets/products.
130+
sed -i '' '/^let env = getenv("EXPERIMENTAL_SPM_BUILDS")/,/^}/d' "$PACKAGE_FILE"
131+
fi
132+
133+
echo
134+
echo "===== $PACKAGE_FILE (after prepare-package.sh) ====="
135+
cat "$PACKAGE_FILE"
136+
echo "===== end of $PACKAGE_FILE (after prepare-package.sh) ====="
137+
echo

0 commit comments

Comments
 (0)