Skip to content

Commit 49a4009

Browse files
authored
Enable Tuist Xcode caching and build insights in CI (#232)
1 parent d39facb commit 49a4009

11 files changed

Lines changed: 190 additions & 11 deletions

File tree

‎.github/workflows/compatibility_tests.yml‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
jobs:
1010
compatibility_tests_macos:
1111
name: Execute compatibility tests
12+
permissions:
13+
contents: read
14+
id-token: write
1215
strategy:
1316
fail-fast: false
1417
matrix:
@@ -31,6 +34,16 @@ jobs:
3134
uses: OpenSwiftUIProject/setup-xcode@v2
3235
with:
3336
xcode-version: ${{ matrix.xcode-version }}
37+
- name: Set up mise
38+
uses: jdx/mise-action@v2
39+
with:
40+
install: false
41+
cache: false
42+
- name: Set up Tuist cache
43+
run: |
44+
source Scripts/Tuist/common.sh
45+
tuist_ci_setup
46+
shell: bash
3447
- name: Set up build environment
3548
run: Scripts/CI/darwin_setup_build.sh
3649
shell: bash
@@ -42,7 +55,10 @@ jobs:
4255
--build-path .build-compatibility-test-debug
4356
- name: Run tests against Apple's AttributeGraph on macOS via Xcode
4457
run: |
45-
xcodebuild test \
58+
source Scripts/Tuist/common.sh
59+
tuist_xcodebuild \
60+
"${RUNNER_TEMP:-/tmp}/openattributegraph-compatibility-macos-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT:-0}.xcresult" \
61+
test \
4662
-workspace .swiftpm/xcode/package.xcworkspace \
4763
-scheme OpenAttributeGraph-Package \
4864
-sdk macosx \

‎.github/workflows/compute.yml‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ jobs:
5656

5757
compute_ios_build:
5858
name: Build with Compute (binary) on iOS
59+
permissions:
60+
contents: read
61+
id-token: write
5962
strategy:
6063
fail-fast: false
6164
matrix:
@@ -78,9 +81,22 @@ jobs:
7881
uses: OpenSwiftUIProject/setup-xcode@v2
7982
with:
8083
xcode-version: ${{ matrix.xcode-version }}
84+
- name: Set up mise
85+
uses: jdx/mise-action@v2
86+
with:
87+
install: false
88+
cache: false
89+
- name: Set up Tuist cache
90+
run: |
91+
source Scripts/Tuist/common.sh
92+
tuist_ci_setup
93+
shell: bash
8194
- name: Build in debug mode on iOS Simulator
8295
run: |
83-
xcodebuild build \
96+
source Scripts/Tuist/common.sh
97+
tuist_xcodebuild \
98+
"${RUNNER_TEMP:-/tmp}/openattributegraph-compute-ios-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT:-0}.xcresult" \
99+
build \
84100
-workspace .swiftpm/xcode/package.xcworkspace \
85101
-scheme OpenAttributeGraph \
86102
-configuration Debug \

‎.github/workflows/ios.yml‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
jobs:
1010
ios_test:
1111
name: Execute tests on iOS
12+
permissions:
13+
contents: read
14+
id-token: write
1215
strategy:
1316
fail-fast: false
1417
matrix:
@@ -33,13 +36,26 @@ jobs:
3336
uses: OpenSwiftUIProject/setup-xcode@v2
3437
with:
3538
xcode-version: ${{ matrix.xcode-version }}
39+
- name: Set up mise
40+
uses: jdx/mise-action@v2
41+
with:
42+
install: false
43+
cache: false
44+
- name: Set up Tuist cache
45+
run: |
46+
source Scripts/Tuist/common.sh
47+
tuist_ci_setup
48+
shell: bash
3649
- name: Set up build environment
3750
run: Scripts/CI/darwin_setup_build.sh
3851
shell: bash
3952
- name: Build in debug mode on iOS
4053
run: |
54+
source Scripts/Tuist/common.sh
4155
# Swift 6.2.4 crashes while indexing C++ interop test targets.
42-
xcodebuild build \
56+
tuist_xcodebuild \
57+
"${RUNNER_TEMP:-/tmp}/openattributegraph-ios-build-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT:-0}.xcresult" \
58+
build \
4359
-workspace .swiftpm/xcode/package.xcworkspace \
4460
-scheme OpenAttributeGraph-Package \
4561
-configuration Debug \
@@ -51,8 +67,11 @@ jobs:
5167
OTHER_SWIFT_FLAGS="-warnings-as-errors"
5268
- name: Build and run tests in debug mode with coverage on iOS Simulator
5369
run: |
70+
source Scripts/Tuist/common.sh
5471
# Swift 6.2.4 crashes while indexing C++ interop test targets.
55-
xcodebuild test \
72+
tuist_xcodebuild \
73+
"${RUNNER_TEMP:-/tmp}/openattributegraph-ios-test-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT:-0}.xcresult" \
74+
test \
5675
-workspace .swiftpm/xcode/package.xcworkspace \
5776
-scheme OpenAttributeGraph-Package \
5877
-configuration Debug \

‎.github/workflows/release.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
runs-on: macos-15
1212
permissions:
1313
contents: write
14+
id-token: write
1415
env:
1516
GH_TOKEN: ${{ github.token }}
1617
steps:
@@ -22,6 +23,16 @@ jobs:
2223
uses: OpenSwiftUIProject/setup-xcode@v2
2324
with:
2425
xcode-version: "26.3"
26+
- name: Set up mise
27+
uses: jdx/mise-action@v2
28+
with:
29+
install: false
30+
cache: false
31+
- name: Set up Tuist cache
32+
run: |
33+
source Scripts/Tuist/common.sh
34+
tuist_ci_setup
35+
shell: bash
2536
- name: Build XCFramework
2637
run: ./Scripts/build_xcframework.sh
2738
- name: Compute Checksum

‎.github/workflows/xcframework.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
jobs:
1010
build_xcframework:
1111
name: Build XCFramework
12+
permissions:
13+
contents: read
14+
id-token: write
1215
strategy:
1316
fail-fast: false
1417
matrix:
@@ -25,6 +28,16 @@ jobs:
2528
uses: OpenSwiftUIProject/setup-xcode@v2
2629
with:
2730
xcode-version: ${{ matrix.xcode-version }}
31+
- name: Set up mise
32+
uses: jdx/mise-action@v2
33+
with:
34+
install: false
35+
cache: false
36+
- name: Set up Tuist cache
37+
run: |
38+
source Scripts/Tuist/common.sh
39+
tuist_ci_setup
40+
shell: bash
2841
- name: Build XCFramework
2942
run: ./Scripts/build_xcframework.sh
3043
- name: Upload XCFramework

‎Example/Tuist.swift‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import ProjectDescription
22

33
let tuist = Tuist(
4-
project: .tuist()
4+
fullHandle: "OpenSwiftUIProject/openattributegraph",
5+
xcodeCache: .xcodeCache(
6+
upload: Environment.isCI
7+
),
8+
project: .tuist(
9+
generationOptions: .options(
10+
enableCaching: Environment.isCI
11+
)
12+
)
513
)

‎Example/mise.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[tools]
2-
tuist = "4.193.0"
2+
tuist = "4.203.1"

‎Scripts/Tuist/common.sh‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env bash
2+
3+
TUIST_REPOSITORY_ROOT="$(
4+
cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null 2>&1
5+
pwd -P
6+
)"
7+
TUIST_CACHE_SOCKET_PATH="${TUIST_CACHE_SOCKET_PATH:-${XDG_STATE_HOME:-$HOME/.local/state}/tuist/OpenSwiftUIProject_openattributegraph.sock}"
8+
9+
tuist_cache_service_is_ready() {
10+
[[ -S "$TUIST_CACHE_SOCKET_PATH" ]] || return 1
11+
12+
if command -v lsof >/dev/null 2>&1; then
13+
lsof "$TUIST_CACHE_SOCKET_PATH" >/dev/null 2>&1
14+
fi
15+
}
16+
17+
tuist_wait_for_cache_service() {
18+
local attempt
19+
for ((attempt = 0; attempt < 40; attempt++)); do
20+
if tuist_cache_service_is_ready; then
21+
return 0
22+
fi
23+
sleep 0.25
24+
done
25+
26+
echo "Tuist cache service is not listening at $TUIST_CACHE_SOCKET_PATH." >&2
27+
echo "If Tuist reported a different socket, set TUIST_CACHE_SOCKET_PATH to that path." >&2
28+
return 69
29+
}
30+
31+
tuist_ci_setup() (
32+
set -e
33+
34+
cd "$TUIST_REPOSITORY_ROOT"
35+
mise trust mise.toml
36+
mise install
37+
mise exec -- tuist auth login
38+
mise exec -- tuist setup cache --path "$TUIST_REPOSITORY_ROOT"
39+
tuist_wait_for_cache_service
40+
)
41+
42+
tuist_xcodebuild() (
43+
set -e
44+
45+
if [[ $# -lt 2 ]]; then
46+
echo "Usage: tuist_xcodebuild <result-bundle.xcresult> <action> [arguments ...]" >&2
47+
return 64
48+
fi
49+
50+
local result_bundle_path="$1"
51+
local action="$2"
52+
shift 2
53+
54+
if [[ -z "$result_bundle_path" || "$result_bundle_path" != *.xcresult ]]; then
55+
echo "Tuist result bundle path must end in .xcresult: $result_bundle_path" >&2
56+
return 64
57+
fi
58+
59+
if [[ "$result_bundle_path" != /* ]]; then
60+
result_bundle_path="$PWD/$result_bundle_path"
61+
fi
62+
63+
local cache_settings=()
64+
if tuist_cache_service_is_ready; then
65+
cache_settings=(
66+
COMPILATION_CACHE_ENABLE_CACHING=YES
67+
"COMPILATION_CACHE_REMOTE_SERVICE_PATH=$TUIST_CACHE_SOCKET_PATH"
68+
COMPILATION_CACHE_ENABLE_PLUGIN=YES
69+
COMPILATION_CACHE_ENABLE_DIAGNOSTIC_REMARKS=YES
70+
)
71+
elif [[ -n "${CI:-}" ]]; then
72+
echo "Tuist cache service is unavailable at $TUIST_CACHE_SOCKET_PATH." >&2
73+
return 69
74+
else
75+
echo "Tuist cache service is unavailable; building without compilation caching." >&2
76+
echo "Run 'mise exec -- tuist setup cache' to enable it locally." >&2
77+
cache_settings=(
78+
COMPILATION_CACHE_ENABLE_CACHING=NO
79+
COMPILATION_CACHE_ENABLE_PLUGIN=NO
80+
)
81+
fi
82+
83+
rm -rf "$result_bundle_path"
84+
mise exec -- tuist xcodebuild "$action" \
85+
-resultBundlePath "$result_bundle_path" \
86+
"$@" \
87+
"${cache_settings[@]}"
88+
)

‎Scripts/build_xcframework.sh‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ set -e
55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)"
66
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
77

8+
# shellcheck source=Scripts/Tuist/common.sh
9+
source "$SCRIPT_DIR/Tuist/common.sh"
10+
811
BUILD_DIR="$PROJECT_ROOT/.build/Xcode"
912
SCHEME="OpenAttributeGraph"
1013

1114
# Generate Xcode project via Tuist
1215
pushd "$PROJECT_ROOT" > /dev/null
13-
tuist generate --no-open
16+
mise exec -- tuist generate --no-open
1417
popd > /dev/null
1518

1619
XCODEPROJ="$PROJECT_ROOT/OpenAttributeGraph.xcodeproj"
@@ -42,21 +45,21 @@ done
4245
echo "Building xcframework for $SCHEME (debug info: $DEBUG_INFO)"
4346

4447
# Archive for each platform using the Tuist-generated xcodeproj
45-
xcodebuild archive \
48+
tuist_xcodebuild "$BUILD_DIR/Archives/$SCHEME-macOS.xcresult" archive \
4649
-project "$XCODEPROJ" \
4750
-scheme "$SCHEME" \
4851
-destination "generic/platform=macOS" \
4952
-archivePath "$BUILD_DIR/Archives/$SCHEME-macOS.xcarchive" \
5053
ENABLE_USER_SCRIPT_SANDBOXING=NO
5154

52-
xcodebuild archive \
55+
tuist_xcodebuild "$BUILD_DIR/Archives/$SCHEME-iOS.xcresult" archive \
5356
-project "$XCODEPROJ" \
5457
-scheme "$SCHEME" \
5558
-destination "generic/platform=iOS" \
5659
-archivePath "$BUILD_DIR/Archives/$SCHEME-iOS.xcarchive" \
5760
ENABLE_USER_SCRIPT_SANDBOXING=NO
5861

59-
xcodebuild archive \
62+
tuist_xcodebuild "$BUILD_DIR/Archives/$SCHEME-iOS-Simulator.xcresult" archive \
6063
-project "$XCODEPROJ" \
6164
-scheme "$SCHEME" \
6265
-destination "generic/platform=iOS Simulator" \

‎Tuist.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import ProjectDescription
22

33
let tuist = Tuist(
4+
fullHandle: "OpenSwiftUIProject/openattributegraph",
5+
xcodeCache: .xcodeCache(
6+
upload: Environment.isCI
7+
),
48
project: .tuist(
59
generationOptions: .options(
10+
enableCaching: Environment.isCI,
611
manifestEnvironment: [
712
"OPENSWIFTUI_*",
813
"OPENATTRIBUTEGRAPH_*",

0 commit comments

Comments
 (0)