Skip to content

Commit fa91d79

Browse files
authored
Generate matrix nested manifests (#3431)
Generate matrix script finds manifests in subdirs ### Motivation: The genereate matrix script attempts to derive the minimum Swift version supported by the package so that it doesn't run CI on versions which are older than that supported. At the moment it can't cope with repositories with packages in subdirectories like swift-nio-examples. ### Modifications: The script looks for manifests in subdirectories if `FIND_SUBDIRECTORY_MANIFESTS_ENABLED=true`. This is opt-in because by default CI only uses the top-level manifests. ### Result: CI should generate more appropriate jobs. An example of this in action https://github.com/apple/swift-nio/actions/runs/18968739126/job/54171197381?pr=3431
1 parent 3ed0975 commit fa91d79

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

scripts/generate_matrix.sh

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ HEAD_BIN="${HEAD_BIN:-$(which head 2> /dev/null)}"; test -n "$HEAD_BIN" || fatal
2626

2727

2828
# Parameters
29+
find_subdirectory_manifests_enabled="${FIND_SUBDIRECTORY_MANIFESTS_ENABLED:=false}"
30+
2931
linux_command="${MATRIX_LINUX_COMMAND:-}" # required if any Linux pipeline is enabled
3032
linux_setup_command="${MATRIX_LINUX_SETUP_COMMAND:-}"
3133
linux_5_9_enabled="${MATRIX_LINUX_5_9_ENABLED:=false}"
@@ -124,20 +126,38 @@ version_gte() {
124126
}
125127

126128
# Find minimum Swift version across all Package manifests
127-
# Checks Package.swift and all Package@swift-*.swift files
129+
# Checks Package.swift and all Package@swift-*.swift files in current directory and subdirectories
128130
# Returns the minimum tools version found across all manifests
129131
find_minimum_swift_version() {
130132
local min_version=""
131133

132-
# Check default Package.swift
134+
# Check default Package.swift in current directory
133135
local default_version
134136
default_version=$(get_tools_version "Package.swift")
135137
if [[ -n "$default_version" ]]; then
136138
min_version="$default_version"
137139
log "Found Package.swift with tools-version: $default_version"
138140
fi
139141

140-
# Check all version-specific manifests
142+
# Check all Package.swift files in subdirectories (multi-package repository support)
143+
if [[ "$find_subdirectory_manifests_enabled" == "true" ]]; then
144+
while read -r manifest; do
145+
if [[ -f "$manifest" ]]; then
146+
local version
147+
version=$(get_tools_version "$manifest")
148+
if [[ -n "$version" ]]; then
149+
log "Found $manifest with tools-version: $version"
150+
151+
# If this version is less than current minimum, update minimum
152+
if [[ -z "$min_version" ]] || version_gte "$min_version" "$version"; then
153+
min_version="$version"
154+
fi
155+
fi
156+
fi
157+
done < <(ls -1 ./*/Package.swift 2>/dev/null || true)
158+
fi
159+
160+
# Check all version-specific manifests in current directory
141161
for manifest in Package@swift-*.swift; do
142162
if [[ ! -f "$manifest" ]]; then
143163
continue
@@ -157,6 +177,24 @@ find_minimum_swift_version() {
157177
fi
158178
done
159179

180+
# Check all version-specific manifests in subdirectories
181+
if [[ "$find_subdirectory_manifests_enabled" == "true" ]]; then
182+
while read -r manifest; do
183+
if [[ -f "$manifest" ]]; then
184+
local version
185+
version=$(get_tools_version "$manifest")
186+
if [[ -n "$version" ]]; then
187+
log "Found $manifest with tools-version: $version"
188+
189+
# If this version is less than current minimum, update minimum
190+
if [[ -z "$min_version" ]] || version_gte "$min_version" "$version"; then
191+
min_version="$version"
192+
fi
193+
fi
194+
fi
195+
done < <(ls -1 ./*/Package@swift-*.swift 2>/dev/null || true)
196+
fi
197+
160198
if [[ -n "$min_version" ]]; then
161199
echo "$min_version"
162200
else

0 commit comments

Comments
 (0)