Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
uses: ./.github/workflows/swift_package_test.yml
with:
# Linux
linux_os_versions: '["jammy", "rhel-ubi9"]'
linux_build_command: |
mkdir MyPackage
cd MyPackage
Expand Down
45 changes: 40 additions & 5 deletions .github/workflows/scripts/install-and-build-with-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,24 @@ if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
log "Additional build flags: $SWIFT_BUILD_FLAGS"
fi

# Detect package manager
if command -v apt >/dev/null 2>&1; then
INSTALL_PACKAGE_COMMAND="apt update -q && apt install -yq"
elif command -v dnf >/dev/null 2>&1; then
INSTALL_PACKAGE_COMMAND="dnf install -y"
elif command -v yum >/dev/null 2>&1; then
INSTALL_PACKAGE_COMMAND="yum install -y"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the yum branch isn't really needed. yum has been replaced by dnf, and the only distro supported by Swift which hasn't fully moved yet is Amazon Linux 2, but that distro doesn't even work in GitHub actions in general because a number of its constituent components are too old for GitHub to set up its communication pipe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that makes sense, I was using yum when testing locally on AL2 so I included it, but I didn't realize it wasn't supported for GitHub actions. I think I'll probably keep it in the script for now in case there's a need to use it locally in an AL2 container, e.g. running

curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | \
bash -s -- [--static] [--wasm] [--embedded-wasm] --flags="<build-flags>" <swift-version>

else
fatal "No supported package manager found"
fi

install_package() {
eval "$INSTALL_PACKAGE_COMMAND $1"
}

# Install dependencies
command -v curl >/dev/null || (apt update -q && apt install -yq curl)
command -v jq >/dev/null || (apt update -q && apt install -yq jq)
command -v curl >/dev/null || install_package curl
command -v jq >/dev/null || install_package jq

SWIFT_API_INSTALL_ROOT="https://www.swift.org/api/v1/install"

Expand Down Expand Up @@ -295,8 +310,18 @@ initialize_os_info() {
fi

log "✅ Detected OS from /etc/os-release: ${os_id}${version_id}"
OS_NAME="${os_id}${version_id}"
OS_NAME_NO_DOT="${os_id}$(echo "$version_id" | tr -d '.')"
if [[ "$os_id" == "rhel" && "$version_id" == 9* ]]; then
OS_NAME="ubi9"
OS_NAME_NO_DOT="ubi9"
elif [[ "$os_id" == "amzn" && "$version_id" == "2" ]]; then
OS_NAME="amazonlinux2"
OS_NAME_NO_DOT="amazonlinux2"
else
# Ubuntu, Debian, Fedora
OS_NAME="${os_id}${version_id}"
OS_NAME_NO_DOT="${os_id}$(echo "$version_id" | tr -d '.')"
fi
log "Using OS name: $OS_NAME"

local arch
arch=$(uname -m)
Expand Down Expand Up @@ -341,6 +366,8 @@ download_and_verify() {
rm -rf "$GNUPGHOME" "$temp_sig"
}

readonly EXIT_TOOLCHAIN_NOT_FOUND=44

# Downloads and extracts the Swift toolchain for the given snapshot tag
#
# $1 (string): A snapshot tag, e.g. "swift-6.2-DEVELOPMENT-SNAPSHOT-2025-07-29-a"
Expand Down Expand Up @@ -368,7 +395,7 @@ download_and_extract_toolchain() {
log "Toolchain not found: ${toolchain_filename}"
log "Exiting workflow..."
# Don't fail the workflow if we can't find the right toolchain
exit 0
exit $EXIT_TOOLCHAIN_NOT_FOUND
fi

# Create toolchain directory
Expand Down Expand Up @@ -418,6 +445,10 @@ if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
log "Installing Swift toolchain to match Static Linux Swift SDK snapshot: $STATIC_LINUX_SDK_TAG"
initialize_os_info
SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK=$(download_and_extract_toolchain "$STATIC_LINUX_SDK_TAG")
if [[ $? -eq $EXIT_TOOLCHAIN_NOT_FOUND ]]; then
# Don't fail the workflow if we can't find the right toolchain
exit 0
fi
fi
fi

Expand All @@ -429,6 +460,10 @@ if [[ "$INSTALL_WASM" == true ]]; then
log "Installing Swift toolchain to match Wasm Swift SDK snapshot: $WASM_SDK_TAG"
initialize_os_info
SWIFT_EXECUTABLE_FOR_WASM_SDK=$(download_and_extract_toolchain "$WASM_SDK_TAG")
if [[ $? -eq $EXIT_TOOLCHAIN_NOT_FOUND ]]; then
# Don't fail the workflow if we can't find the right toolchain
exit 0
fi
fi
fi

Expand Down
Loading