Skip to content

Commit c03a8d8

Browse files
authored
ci: Reduce number of variants built on PRs (#5941)
* ci: Reduce number of variants built on PRs * Use env variable for github output * Use echo * Move script to a file * Checkout code * Update file permissions * Pass sdklist to assemble xcframework * Add script to release.yml trigger * Fix variable name * Build `Sentry-Dynamic` * Add SentrySwiftUI to build list * Fix extra , * Remove `Sentry-Dynamic-WithARM64e` from Package.swift for PR * Add `iphonesimulator` sdk to build list * Add comment * Split slices and variant into base and additional arrays * Add package file input to prepare-package action * Add step to remove newer package files in prepare-package action * Add real devices sdks to variants built on PRs * Build WithoutUIKitOrAppKit on PRs * ci: Build all slices * Update file filters * Use JSON and jq to make script easier to read
1 parent daeb716 commit c03a8d8

File tree

4 files changed

+134
-77
lines changed

4 files changed

+134
-77
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "Prepare Package.swift"
2+
description: "Prepares Package.swift"
3+
inputs:
4+
is-pr:
5+
description: "Whether the build is a PR"
6+
required: true
7+
default: "false"
8+
package-file:
9+
description: "The package file to prepare"
10+
required: true
11+
default: "Package.swift"
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Remove newer package files
16+
# Remove newer package files when processing Package.swift to prevent interference
17+
if: ${{ inputs.package-file == 'Package.swift' }}
18+
shell: bash
19+
run: rm -rf Package@swift*
20+
- name: Remove Sentry-Dynamic-WithARM64e target
21+
# We don't build it on PRs, so we need to remove it from the package.swift file.
22+
if: ${{ inputs.is-pr == 'true' }}
23+
shell: bash
24+
env:
25+
PACKAGE_FILE: ${{ inputs.package-file }}
26+
run: |
27+
sed -i '' '/Sentry-Dynamic-WithARM64e/d' $PACKAGE_FILE
28+
sed -i '' '/^[[:space:]]*\.binaryTarget($/{N;/\n[[:space:]]*),$/d;}' $PACKAGE_FILE
29+
- name: Change path of the framework
30+
shell: bash
31+
env:
32+
PACKAGE_FILE: ${{ inputs.package-file }}
33+
run: |
34+
sed -i '' 's/url.*//g' $PACKAGE_FILE
35+
sed -i '' 's/checksum: ".*" \/\/Sentry-Static/path: "Sentry.xcframework.zip"/g' $PACKAGE_FILE
36+
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic-WithARM64e/path: "Sentry-Dynamic-WithARM64e.xcframework.zip"/g' $PACKAGE_FILE
37+
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic/path: "Sentry-Dynamic.xcframework.zip"/g' $PACKAGE_FILE

.github/file-filters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ run_release_for_prs: &run_release_for_prs # Release-related code
125125
- "scripts/ci-diagnostics.sh"
126126
- "scripts/build-xcframework-slice.sh"
127127
- "scripts/assemble-xcframework.sh"
128+
- "scripts/generate_release_matrix.sh"
128129

129130
# Project files
130131
- "Sentry.xcworkspace/**"

.github/workflows/release.yml

Lines changed: 39 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,29 @@ jobs:
4646
token: ${{ github.token }}
4747
filters: .github/file-filters.yml
4848

49+
setup-matrix:
50+
runs-on: ubuntu-latest
51+
if: github.event_name != 'pull_request' || needs.files-changed.outputs.run_release_for_prs == 'true'
52+
needs: files-changed
53+
steps:
54+
- uses: actions/checkout@v4
55+
- name: Setup matrix combinations
56+
id: setup-matrix-combinations
57+
run: |
58+
./scripts/generate_release_matrix.sh
59+
env:
60+
EVENT_NAME: ${{ github.event_name }}
61+
outputs:
62+
slices: ${{ steps.setup-matrix-combinations.outputs.slices }}
63+
variants: ${{ steps.setup-matrix-combinations.outputs.variants }}
64+
sdk-list-array: ${{ steps.setup-matrix-combinations.outputs.sdk-list-array }}
65+
sdk-list-string: ${{ steps.setup-matrix-combinations.outputs.sdk-list-string }}
66+
4967
build-xcframework-variant-slices:
5068
name: Build XCFramework Slices
5169
# Run the job only for PRs with related changes or non-PR events.
5270
if: github.event_name != 'pull_request' || needs.files-changed.outputs.run_release_for_prs == 'true'
53-
needs: files-changed
71+
needs: [files-changed, setup-matrix]
5472
uses: ./.github/workflows/build-xcframework-variant-slices.yml
5573
with:
5674
name: ${{matrix.variant.name}}
@@ -59,27 +77,13 @@ jobs:
5977
configuration-suffix: ${{matrix.variant.configuration-suffix}}
6078
variant-id: ${{matrix.variant.id}}
6179
release-version: ${{ github.event.inputs.version }}
80+
sdk-list: ${{ needs.setup-matrix.outputs.sdk-list-array }}
6281
strategy:
6382
matrix:
64-
variant:
65-
- name: Sentry
66-
macho-type: mh_dylib
67-
suffix: "-Dynamic"
68-
id: sentry-dynamic
69-
- name: Sentry
70-
macho-type: staticlib
71-
id: sentry-static
72-
- name: SentrySwiftUI
73-
macho-type: mh_dylib
74-
id: sentry-swiftui
75-
- name: Sentry
76-
macho-type: mh_dylib
77-
suffix: "-WithoutUIKitOrAppKit"
78-
configuration-suffix: WithoutUIKit
79-
id: sentry-withoutuikit-dynamic
83+
variant: ${{ fromJson(needs.setup-matrix.outputs.slices) }}
8084

8185
assemble-xcframework-variant:
82-
needs: [files-changed, build-xcframework-variant-slices]
86+
needs: [files-changed, build-xcframework-variant-slices, setup-matrix]
8387
# Run the job only for PRs with related changes or non-PR events.
8488
if: github.event_name != 'pull_request' || needs.files-changed.outputs.run_release_for_prs == 'true'
8589
name: Assemble XCFramework Variant
@@ -94,37 +98,10 @@ jobs:
9498
release-version: ${{ github.event.inputs.version }}
9599
excluded-archs: ${{matrix.variant.excluded-archs}}
96100
override-name: ${{matrix.variant.override-name}}
101+
sdks: ${{ needs.setup-matrix.outputs.sdk-list-string }}
97102
strategy:
98103
matrix:
99-
variant:
100-
- scheme: Sentry
101-
macho-type: mh_dylib
102-
suffix: "-Dynamic"
103-
id: sentry-dynamic
104-
excluded-archs: arm64e
105-
- scheme: Sentry
106-
macho-type: mh_dylib
107-
suffix: "-Dynamic"
108-
id: sentry-dynamic
109-
override-name: Sentry-Dynamic-WithARM64e
110-
- scheme: Sentry
111-
macho-type: staticlib
112-
id: sentry-static
113-
- scheme: SentrySwiftUI
114-
macho-type: mh_dylib
115-
id: sentry-swiftui
116-
- scheme: Sentry
117-
macho-type: mh_dylib
118-
suffix: "-WithoutUIKitOrAppKit"
119-
configuration-suffix: WithoutUIKit
120-
id: sentry-withoutuikit-dynamic
121-
excluded-archs: arm64e
122-
- scheme: Sentry
123-
macho-type: mh_dylib
124-
suffix: "-WithoutUIKitOrAppKit"
125-
configuration-suffix: WithoutUIKit
126-
id: sentry-withoutuikit-dynamic
127-
override-name: Sentry-WithoutUIKitOrAppKit-WithARM64e
104+
variant: ${{ fromJson(needs.setup-matrix.outputs.variants) }}
128105

129106
validate-xcframework:
130107
name: Validate XCFramework
@@ -163,16 +140,11 @@ jobs:
163140
with:
164141
pattern: xcframework-${{github.sha}}-*
165142
merge-multiple: true
166-
- name: Remove newer package files
167-
if: ${{ matrix.package-file.name == 'Package.swift' }}
168-
run: rm -rf Package@swift*
169-
- name: Change path of the framework
170-
run: |
171-
sed -i '' 's/url.*//g' ${{matrix.package-file.name}}
172-
sed -i '' 's/checksum: ".*" \/\/Sentry-Static/path: "Sentry.xcframework.zip"/g' ${{matrix.package-file.name}}
173-
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic-WithARM64e/path: "Sentry-Dynamic-WithARM64e.xcframework.zip"/g' ${{matrix.package-file.name}}
174-
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic/path: "Sentry-Dynamic.xcframework.zip"/g' ${{matrix.package-file.name}}
175-
shell: bash
143+
- name: Prepare Package.swift
144+
uses: ./.github/actions/prepare-package.swift
145+
with:
146+
is-pr: ${{ github.event_name == 'pull_request' }}
147+
package-file: ${{matrix.package-file.name}}
176148
- run: swift build
177149
working-directory: Samples/macOS-SPM-CommandLine
178150
- name: Run CI Diagnostics
@@ -196,16 +168,11 @@ jobs:
196168
with:
197169
pattern: xcframework-${{github.sha}}-*
198170
merge-multiple: true
199-
- name: Remove newer package files
200-
if: ${{ matrix.package-file.name == 'Package.swift' }}
201-
run: rm -rf Package@swift*
202-
- name: Change path of the framework
203-
run: |
204-
sed -i '' 's/url.*//g' ${{matrix.package-file.name}}
205-
sed -i '' 's/checksum: ".*" \/\/Sentry-Static/path: "Sentry.xcframework.zip"/g' ${{matrix.package-file.name}}
206-
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic-WithARM64e/path: "Sentry-Dynamic-WithARM64e.xcframework.zip"/g' ${{matrix.package-file.name}}
207-
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic/path: "Sentry-Dynamic.xcframework.zip"/g' ${{matrix.package-file.name}}
208-
shell: bash
171+
- name: Prepare Package.swift
172+
uses: ./.github/actions/prepare-package.swift
173+
with:
174+
is-pr: ${{ github.event_name == 'pull_request' }}
175+
package-file: ${{matrix.package-file.name}}
209176
- run: swift build
210177
working-directory: Samples/SPM-Dynamic
211178
- name: Run CI Diagnostics
@@ -229,16 +196,11 @@ jobs:
229196
with:
230197
pattern: xcframework-${{github.sha}}-*
231198
merge-multiple: true
232-
- name: Remove newer package files
233-
if: ${{ matrix.package-file.name == 'Package.swift' }}
234-
run: rm -rf Package@swift*
235-
- name: Change path of the framework
236-
run: |
237-
sed -i '' 's/url.*//g' ${{matrix.package-file.name}}
238-
sed -i '' 's/checksum: ".*" \/\/Sentry-Static/path: "Sentry.xcframework.zip"/g' ${{matrix.package-file.name}}
239-
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic-WithARM64e/path: "Sentry-Dynamic-WithARM64e.xcframework.zip"/g' ${{matrix.package-file.name}}
240-
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic/path: "Sentry-Dynamic.xcframework.zip"/g' ${{matrix.package-file.name}}
241-
shell: bash
199+
- name: Prepare Package.swift
200+
uses: ./.github/actions/prepare-package.swift
201+
with:
202+
is-pr: ${{ github.event_name == 'pull_request' }}
203+
package-file: ${{matrix.package-file.name}}
242204
- run: swift build
243205
- name: Run CI Diagnostics
244206
if: failure()

scripts/generate_release_matrix.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
# This script is used to generate the matrix combinations for the release workflow.
4+
# Rewritten to use jq as much as possible for maintainability.
5+
6+
set -euo pipefail
7+
8+
# Slices and Variants only needed on PRs
9+
BASE_SLICES_JSON='[
10+
{"name": "Sentry", "macho-type": "mh_dylib", "suffix": "-Dynamic", "id": "sentry-dynamic"},
11+
{"name": "Sentry", "macho-type": "staticlib", "id": "sentry-static"},
12+
{"name": "SentrySwiftUI", "macho-type": "mh_dylib", "id": "sentry-swiftui"},
13+
{"name": "Sentry", "macho-type": "mh_dylib", "suffix": "-WithoutUIKitOrAppKit", "configuration-suffix": "WithoutUIKit", "id": "sentry-withoutuikit-dynamic"}
14+
]'
15+
BASE_VARIANTS_JSON='[
16+
{"scheme": "Sentry", "macho-type": "mh_dylib", "suffix": "-Dynamic", "id": "sentry-dynamic", "excluded-archs": "arm64e"},
17+
{"scheme": "Sentry", "macho-type": "staticlib", "id": "sentry-static"},
18+
{"scheme": "SentrySwiftUI", "macho-type": "mh_dylib", "id": "sentry-swiftui"},
19+
{"scheme": "Sentry", "macho-type": "mh_dylib", "suffix": "-WithoutUIKitOrAppKit", "configuration-suffix": "WithoutUIKit", "id": "sentry-withoutuikit-dynamic", "excluded-archs": "arm64e"}
20+
]'
21+
BASE_SDKS_JSON='[
22+
"iphoneos",
23+
"iphonesimulator",
24+
"macosx",
25+
"maccatalyst",
26+
"appletvos",
27+
"watchos",
28+
"xros"
29+
]'
30+
31+
# Slices and Variants only needed on main or release
32+
ADDITIONAL_VARIANTS_JSON='[
33+
{"scheme": "Sentry", "macho-type": "mh_dylib", "suffix": "-Dynamic", "id": "sentry-dynamic", "override-name": "Sentry-Dynamic-WithARM64e"},
34+
{"scheme": "Sentry", "macho-type": "mh_dylib", "suffix": "-WithoutUIKitOrAppKit", "configuration-suffix": "WithoutUIKit", "id": "sentry-withoutuikit-dynamic", "override-name": "Sentry-WithoutUIKitOrAppKit-WithARM64e"}
35+
]'
36+
ADDITIONAL_SDKS_JSON='[
37+
"appletvsimulator",
38+
"watchsimulator",
39+
"xrsimulator"
40+
]'
41+
42+
if [ "$EVENT_NAME" = "pull_request" ]; then
43+
SLICES_COMBINATIONS="$BASE_SLICES_JSON"
44+
VARIANTS_COMBINATIONS="$BASE_VARIANTS_JSON"
45+
SDK_LIST="$BASE_SDKS_JSON"
46+
else
47+
SLICES_COMBINATIONS="$BASE_SLICES_JSON"
48+
VARIANTS_COMBINATIONS=$(jq -c -s '.[0] + .[1]' <(echo "$BASE_VARIANTS_JSON") <(echo "$ADDITIONAL_VARIANTS_JSON"))
49+
SDK_LIST=$(jq -c -s '.[0] + .[1]' <(echo "$BASE_SDKS_JSON") <(echo "$ADDITIONAL_SDKS_JSON"))
50+
fi
51+
52+
{
53+
echo "slices=$(echo "$SLICES_COMBINATIONS" | jq -c '.')"
54+
echo "variants=$(echo "$VARIANTS_COMBINATIONS" | jq -c '.')"
55+
echo "sdk-list-array=$(echo "$SDK_LIST" | jq -c '.')"
56+
echo "sdk-list-string=$(echo "$SDK_LIST" | jq -r 'join(",")')"
57+
} >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)