Skip to content

Commit d26fe90

Browse files
TSavoclaude
andcommitted
ci(swift): isolate SwiftPM cache per runner to end the prove-swift race
Two self-hosted macOS runners (tsavo-mac-x64 + -2) run under one user on one host, so they share SwiftPM's global cache (~/Library/Caches/ org.swift.swiftpm). When two swift PRs build concurrently — one per runner — both 'swift build' processes write that shared cache and race, failing the prove-swift (macOS) C1-C8 job. Evidence: #1536 passed prove-swift solo; #1537 and #1539 both failed it running concurrently. The .build scratch dir is already per-checkout; only the shared --cache-path was contended. Thread an opt-in SWIFT_CACHE_PATH through the Makefile (build-swift + test-swift) to 'swift build/test --cache-path', and set it to ${{ runner.temp }}/swiftpm-cache on both macOS swift jobs. RUNNER_TEMP is per-runner-instance, so concurrent builds get distinct caches; sequential builds on one runner still reuse it. Unset (local dev) keeps SwiftPM's default — verified behavior-identical via 'make -n build-swift'. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 6b80f3f commit d26fe90

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ jobs:
328328
# (swift, rust) are pre-installed on the runner host.
329329
runs-on: [self-hosted, macOS, X64]
330330
timeout-minutes: 45
331+
env:
332+
# Isolate the SwiftPM shared cache (--cache-path) per runner instance so
333+
# two macOS runners on one host don't race on the shared
334+
# ~/Library/Caches/org.swift.swiftpm — the prove-swift flake. RUNNER_TEMP
335+
# is per-runner, so concurrent swift builds get distinct caches; .build
336+
# (compiled artifacts) is still restored from the GH cache below.
337+
SWIFT_CACHE_PATH: ${{ runner.temp }}/swiftpm-cache
331338

332339
steps:
333340
- name: Checkout
@@ -612,6 +619,12 @@ jobs:
612619
runs-on: [self-hosted, macOS, X64]
613620
timeout-minutes: 20
614621
needs: conformance
622+
env:
623+
# Per-runner SwiftPM cache isolation — see the conformance-macos-swift
624+
# job above. Two macOS runners on one host raced on the shared SwiftPM
625+
# cache (~/Library/Caches/org.swift.swiftpm), failing concurrent
626+
# prove-swift runs; RUNNER_TEMP gives each a distinct --cache-path.
627+
SWIFT_CACHE_PATH: ${{ runner.temp }}/swiftpm-cache
615628

616629
steps:
617630
- name: Checkout

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,16 @@ build-ruby:
288288
# runtime perf is irrelevant. Override with `SWIFT_BUILD_CONFIG=release` if a
289289
# release artifact is ever needed.
290290
SWIFT_BUILD_CONFIG ?= debug
291+
# Per-invocation SwiftPM cache isolation. SwiftPM's *scratch* dir (`.build`)
292+
# is already per-checkout, but its *shared* cache (--cache-path, default
293+
# ~/Library/Caches/org.swift.swiftpm) is per-user. On a host running two
294+
# self-hosted runners under one account, two concurrent `swift build`s race
295+
# on that shared cache and both fail (the prove-swift macOS flake). Set
296+
# SWIFT_CACHE_PATH to a per-runner path (e.g. $RUNNER_TEMP/swiftpm-cache) to
297+
# isolate it. Unset (local dev) keeps SwiftPM's default — behavior unchanged.
298+
SWIFT_CACHE_ARG := $(if $(SWIFT_CACHE_PATH),--cache-path $(SWIFT_CACHE_PATH),)
291299
build-swift:
292-
cd implementations/swift && swift build -c $(SWIFT_BUILD_CONFIG)
300+
cd implementations/swift && swift build -c $(SWIFT_BUILD_CONFIG) $(SWIFT_CACHE_ARG)
293301

294302
# --- Mint targets ------------------------------------------------------------
295303

@@ -808,7 +816,7 @@ test-java: build-java
808816

809817
.PHONY: test-swift
810818
test-swift: build-swift
811-
cd implementations/swift && swift test
819+
cd implementations/swift && swift test $(SWIFT_CACHE_ARG)
812820
cd implementations/swift && swift run conformance
813821
cd implementations/swift && swift run test-swift-lsp
814822
cd implementations/swift && swift run test-swift-crypto

0 commit comments

Comments
 (0)