Files
swift-nio/scripts/install_swift_sdk.sh
Gus Cairo 3d1ee9d45a Add and enable 6.4 workflows (#3750)
### Motivation

* Swift 6.4 has been released, so we should add it to our CI coverage.

### Modifications

* Update `apple/swift-nio/scripts/generate_matrix.sh`
* Update `apple/swift-nio/scripts/check-matrix-job.sh`
* Update reusable adopters of `swift_test_matrix.yml`
* Update end-user adopter workflows of `swift_test_matrix.yml`
* Add Swift 6.4 inputs to `macos_tests.yml` and `macos_benchmarks.yml`
* Add a 6.4 release job to `wasm_swift_sdk.yml`
* Enable the Windows 6.4 unit test job in `main.yml` and
`pull_request.yml`
* Copy benchmark thresholds from 6.3

### Result

* NIO runs Swift 6.4 CI, and downstream repositories can opt-in.

---

- Successful run (minus broken nightlies):
https://github.com/apple/swift-nio/actions/runs/36403423635?pr=3750
2026-09-30 10:05:07 +01:00

278 lines
10 KiB
Bash
Executable File

#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -uo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
# Parameter environment variables
branch="${INSTALL_SWIFT_BRANCH:-""}"
version="${INSTALL_SWIFT_VERSION:-""}"
arch="${INSTALL_SWIFT_ARCH:-"aarch64"}"
os_image="${INSTALL_SWIFT_OS_IMAGE:-"ubuntu22.04"}"
sdk="${INSTALL_SWIFT_SDK:-"static-sdk"}"
swift_sdk_directory="${SWIFT_SDK_DIRECTORY:-"/tmp/swiftsdks"}"
dry_run="${DRY_RUN:-""}"
if [[ ! ( -n "$branch" && -z "$version" ) && ! ( -z "$branch" && -n "$version") ]]; then
fatal "Exactly one of build or version must be defined."
fi
CURL_BIN="${CURL_BIN:-$(which curl 2> /dev/null)}"; test -n "$CURL_BIN" || fatal "CURL_BIN unset and no curl on PATH"
TAR_BIN="${TAR_BIN:-$(which tar 2> /dev/null)}"; test -n "$TAR_BIN" || fatal "TAR_BIN unset and no tar on PATH"
JQ_BIN="${JQ_BIN:-$(which jq 2> /dev/null)}"; test -n "$JQ_BIN" || fatal "JQ_BIN unset and no jq on PATH"
SED_BIN="${SED_BIN:-$(which sed 2> /dev/null)}"; test -n "$SED_BIN" || fatal "SED_BIN unset and no sed on PATH"
SHASUM_BIN="${SHASUM_BIN:-$(which shasum 2> /dev/null)}"; test -n "$SHASUM_BIN" || fatal "SHASUM_BIN unset and no shasum on PATH"
GPG_BIN="${GPG_BIN:-$(which gpg 2> /dev/null)}"; test -n "$GPG_BIN" || fatal "GPG_BIN unset and no gpg on PATH"
ZCAT_BIN="${ZCAT_BIN:-$(which zcat 2> /dev/null)}"; test -n "$ZCAT_BIN" || fatal "ZCAT_BIN unset and no zcat on PATH"
case "$arch" in
"aarch64")
arch_suffix="-$arch" ;;
"x86_64")
arch_suffix="" ;;
*)
fatal "Unexpected architecture: $arch" ;;
esac
case "$sdk" in
"static-sdk")
sdk_dir="static-sdk"
sdk_suffix="_static-linux-0.0.1"
;;
"wasm-sdk")
sdk_dir="wasm-sdk"
sdk_suffix="_wasm"
;;
"android-sdk")
sdk_dir="android-sdk"
sdk_suffix="_android"
;;
*)
fatal "Unexpected Swift SDK: $sdk"
;;
esac
os_image_sanitized="${os_image//./}"
# Function to extract checksum from release info
extract_checksum() {
local release_info="$1"
if [[ -z "$release_info" ]]; then
log "Warning: No release information available"
return
fi
local checksum
# shellcheck disable=SC2016 # Our use of JQ_BIN means that shellcheck can't tell this is a `jq` invocation
checksum=$(echo "$release_info" | "$JQ_BIN" -r --arg platform "$sdk" '.platforms[] | select(.platform == $platform) | .checksum // empty')
if [[ -n "$checksum" ]]; then
log "Found checksum for $sdk: $checksum"
echo "$checksum"
else
log "Warning: No checksum available for $sdk platform"
fi
}
# Function to extract the SDK version from release info (for static-sdk)
extract_static_sdk_version() {
local release_info="$1"
if [[ -z "$release_info" ]]; then
log "Warning: No release information available"
return
fi
local sdk_version
# shellcheck disable=SC2016 # Our use of JQ_BIN means that shellcheck can't tell this is a `jq` invocation
sdk_version=$(echo "$release_info" | "$JQ_BIN" -r '.platforms[] | select(.platform == "static-sdk") | .version // empty')
if [[ -n "$sdk_version" ]]; then
log "Found Static Linux Swift SDK version: $sdk_version"
echo "$sdk_version"
else
log "Warning: No version available for static-sdk platform"
fi
}
if [[ -n "$branch" ]]; then
# Some snapshots may not have all the artefacts we require
log "Discovering branch snapshot for branch $branch"
# Map branch name to download path: "main" uses "development", release branches use their branch name
if [[ "$branch" == "main" ]]; then
download_path="development"
else
download_path="$branch"
fi
# shellcheck disable=SC2016 # Our use of JQ_BIN means that shellcheck can't tell this is a `jq` invocation
snapshots="$("$CURL_BIN" -s "https://www.swift.org/api/v1/install/dev/${branch}/${os_image_sanitized}.json" | "$JQ_BIN" -r --arg arch "$arch" '.[$arch] | unique | reverse | .[].dir')"
if [[ -z "$snapshots" ]]; then
fatal "No snapshots found for branch '$branch' on ${os_image_sanitized}/${arch}. Check the branch name and that swift.org is reachable."
fi
snapshot=""
for snapshot in $snapshots; do
snapshot_url="https://download.swift.org/${download_path}/${os_image_sanitized}${arch_suffix}/${snapshot}/${snapshot}-${os_image}${arch_suffix}.tar.gz"
# check that the files exist
"$CURL_BIN" -sILXGET --fail "$snapshot_url" > /dev/null; snapshot_return_code=$?
if [[ "$sdk" == "static-sdk" ]]; then
static_sdk_versions=("0.1.0" "0.0.1")
else
static_sdk_versions=("")
fi
sdk_return_code=1
for static_sdk_version in "${static_sdk_versions[@]}"; do
if [[ -n "$static_sdk_version" ]]; then
sdk_suffix="_static-linux-${static_sdk_version}"
fi
sdk_url="https://download.swift.org/${download_path}/${sdk_dir}/${snapshot}/${snapshot}${sdk_suffix}.artifactbundle.tar.gz"
"$CURL_BIN" -sILXGET --fail "$sdk_url" > /dev/null; sdk_return_code=$?
if [[ "$sdk_return_code" -eq 0 ]]; then
break
fi
done
if [[ ("$snapshot_return_code" -eq 0) && ("$sdk_return_code" -eq 0) ]]; then
log "Discovered branch snapshot: $snapshot"
break
else
log "Snapshot unavailable: $snapshot (Snapshot return code: $snapshot_return_code, Swift SDK return code: $sdk_return_code)"
snapshot=""
fi
done
if [[ -z "$snapshot" ]]; then
fatal "Failed to discover usable Swift snapshot"
fi
elif [[ -n "$version" ]]; then
if [[ "$version" == "latest" ]]; then
log "Discovering latest version"
release_info=$("$CURL_BIN" -s https://www.swift.org/api/v1/install/releases.json | "$JQ_BIN" -r '.[-1]')
if [[ -z "$release_info" ]]; then
log "Warning: Could not find release information for version $version"
fi
version=$(echo "$release_info" | "$JQ_BIN" -r '.tag' | "$SED_BIN" -E 's/swift-([0-9]+\.[0-9]+\.?[0-9]*)-RELEASE/\1/')
if [[ -z "$version" ]]; then
fatal "Failed to discover latest Swift version"
fi
log "Discovered latest Swift version: $version"
else
# From Swift 6.4 onwards, release tags and download paths always include the patch version (e.g. 6.4.0)
if [[ "$version" =~ ^([0-9]+)\.([0-9]+)$ ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
if (( major > 6 || (major == 6 && minor >= 4) )); then
version="${version}.0"
log "Normalized version to $version"
fi
fi
# For specific versions, we need to fetch the release info
log "Getting release information for version $version"
# shellcheck disable=SC2016 # Our use of JQ_BIN means that shellcheck can't tell this is a `jq` invocation
release_info=$("$CURL_BIN" -s https://www.swift.org/api/v1/install/releases.json | "$JQ_BIN" -r --arg ver "swift-$version-RELEASE" '.[] | select(.tag == $ver)')
if [[ -z "$release_info" ]]; then
log "Warning: Could not find release information for version $version"
fi
fi
expected_checksum=$(extract_checksum "$release_info")
if [[ "$sdk" == "static-sdk" ]]; then
static_sdk_version=$(extract_static_sdk_version "$release_info")
if [[ -n "$static_sdk_version" ]]; then
sdk_suffix="_static-linux-${static_sdk_version}"
fi
fi
snapshot_url="https://download.swift.org/swift-${version}-release/${os_image_sanitized}${arch_suffix}/swift-${version}-RELEASE/swift-${version}-RELEASE-${os_image}${arch_suffix}.tar.gz"
sdk_url="https://download.swift.org/swift-${version}-release/${sdk_dir}/swift-${version}-RELEASE/swift-${version}-RELEASE${sdk_suffix}.artifactbundle.tar.gz"
fi
if [[ -n "$dry_run" ]]; then
log "Dry-run mode: no downloads or installations will be performed"
log "Snapshot URL: $snapshot_url"
log "Swift SDK URL: $sdk_url"
if [[ -n "${expected_checksum:-}" ]]; then
log "Expected Swift SDK checksum: $expected_checksum"
fi
exit 0
fi
log "Obtaining Swift toolchain"
log "Snapshot URL: $snapshot_url"
snapshot_path="/tmp/$(basename "$snapshot_url")"
"$CURL_BIN" -sfL "$snapshot_url" -o "$snapshot_path" || fatal "Failed to download Swift toolchain"
# Import Swift's public key for GPG verification
keys_url="https://swift.org/keys/all-keys.asc"
keys_path="/tmp/all-keys.asc"
"$CURL_BIN" -sL "$keys_url" -o "$keys_path" || fatal "Failed to download Swift's public keys"
"$ZCAT_BIN" -f "$keys_path" | "$GPG_BIN" --import - || fatal "Failed to import Swift's public keys"
# Verify GPG signature for all Swift toolchain downloads
signature_url="${snapshot_url}.sig"
signature_path="${snapshot_path}.sig"
log "Downloading signature from: $signature_url"
echo "$CURL_BIN" -sfL "$signature_url" -o "$signature_path"
"$CURL_BIN" -sfL "$signature_url" -o "$signature_path" || fatal "Failed to download Swift toolchain signature"
# Verify the signature
log "Verifying Swift toolchain GPG signature..."
"$GPG_BIN" --verify "$signature_path" "$snapshot_path" || fatal "Swift toolchain GPG signature verification failed"
# Clean up signature file
rm -f "$signature_path"
log "Installing Swift toolchain"
mkdir -p /tmp/snapshot
"$TAR_BIN" xfz "$snapshot_path" --strip-components 1 -C /
log "Obtaining Swift SDK"
log "Swift SDK URL: $sdk_url"
sdk_path="/tmp/$(basename "$sdk_url")"
"$CURL_BIN" -sfL "$sdk_url" -o "$sdk_path" || fatal "Failed to download Swift SDK"
# Verify SDK checksum if available
if [[ -n "${expected_checksum:-}" ]]; then
log "Verifying Swift SDK checksum..."
actual_checksum=$("$SHASUM_BIN" -a 256 "$sdk_path" | cut -d' ' -f1)
if [[ "$actual_checksum" = "$expected_checksum" ]]; then
log "Swift SDK checksum verified successfully"
else
fatal "Swift SDK checksum mismatch: expected $expected_checksum, got $actual_checksum"
fi
else
log "Skipping checksum verification (no checksum available)"
fi
log "Looking for swift"
which swift || fatal "Failed to locate installed Swift"
log "Checking swift"
swift --version
log "Installing Swift SDK"
log "Using Swift SDK directory: $swift_sdk_directory"
mkdir -p "$swift_sdk_directory/swift-sdks"
swift sdk install --swift-sdks-path "$swift_sdk_directory" "$sdk_path"