Skip to content

Add support for Windows on ARM #17

Add support for Windows on ARM

Add support for Windows on ARM #17

name: Swift Matrix

Check failure on line 1 in .github/workflows/swift_package_test.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/swift_package_test.yml

Invalid workflow file

(Line: 687, Col: 9): Unrecognized named-value: 'matrix'. Located at position 67 within expression: inputs.enable_windows_checks && !(inputs.enable_windows_docker && matrix.os_version == 'windows-11-arm')
permissions:
contents: read
on:
workflow_call:
inputs:
macos_xcode_versions:
type: string
description: "Xcode version list (JSON)"
default: "[\"16.3\", \"16.4\", \"26.0\"]"
macos_exclude_xcode_versions:
type: string
description: "Exclude Xcode version list (JSON)"
default: "[{\"xcode_version\": \"\"}]"
macos_versions:
type: string
description: "macOS version list (JSON)"
default: "[\"sequoia\"]"
macos_archs:
type: string
description: "macOS arch list (JSON)"
default: "[\"ARM64\"]"
ios_host_xcode_versions:
type: string
description: "Xcode version list (JSON)"
default: null
ios_host_exclude_xcode_versions:
type: string
description: "Exclude Xcode version list (JSON)"
default: null
ios_host_versions:
type: string
description: "iOS host (macOS) version list (JSON)"
default: null
ios_host_archs:
type: string
description: "iOS host (macOS) arch list (JSON)"
default: null
linux_swift_versions:
type: string
description: "Include Linux Swift version list (JSON)"
default: "[ \"5.9\", \"5.10\", \"6.0\", \"6.1\", \"6.2\", \"nightly-main\", \"nightly-6.2\"]"
linux_exclude_swift_versions:
type: string
description: "Exclude Linux Swift version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
linux_os_versions:
type: string
description: "Linux OS version list (JSON)"
default: "[\"jammy\"]"
linux_static_sdk_versions:
type: string
description: "Static Linux Swift SDK version list (JSON)"
default: "[\"nightly-main\", \"nightly-6.2\", \"6.2\"]"
linux_static_sdk_exclude_swift_versions:
type: string
description: "Exclude Static Linux Swift SDK version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
wasm_sdk_versions:
type: string
description: "Wasm Swift SDK version list (JSON)"
default: "[\"nightly-main\", \"nightly-6.2\", \"6.2\"]"
wasm_exclude_swift_versions:
type: string
description: "Exclude Wasm Swift SDK version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
android_sdk_versions:
type: string
description: "Android Swift SDK version list (JSON)"
default: "[\"nightly-main\"]"
android_exclude_swift_versions:
type: string
description: "Exclude Android Swift SDK version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
windows_swift_versions:
type: string
description: "Include Windows Swift version list (JSON)"
# "5.10" is omitted for Windows because the container image is broken.
default: "[\"5.9\", \"6.0\", \"6.1\", \"6.2\", \"nightly\", \"nightly-6.2\"]"
windows_exclude_swift_versions:
type: string
description: "Exclude Windows Swift version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
windows_os_versions:
type: string
description: "Windows OS version label list (JSON)"
default: "[\"windows-2022\", \"windows-11-arm\"]"
swift_flags:
type: string
description: "Swift flags for release version"
default: ""
swift_nightly_flags:
type: string
description: "Swift flags for nightly version"
default: ""
linux_pre_build_command:
type: string
description: "Linux command to execute before building the Swift package"
default: ""
linux_static_sdk_pre_build_command:
type: string
description: "Linux command to execute before building the Swift package with the Static Linux Swift SDK"
default: ""
wasm_sdk_pre_build_command:
type: string
description: "Linux command to execute before building the Swift package with the Embedded Swift SDK for Wasm"
default: ""
android_sdk_pre_build_command:
type: string
description: "Linux command to execute before building the Swift package with the Embedded Swift SDK for Android"
default: ""
macos_pre_build_command:
type: string
description: "macOS command to execute before building the Swift package"
default: ""
macos_build_command:
type: string
description: "macOS command to build and test the package"
default: "xcrun swift test"
ios_pre_build_command:
type: string
description: "macOS command to execute before building the Swift package for iOS"
default: ""
ios_build_command:
type: string
description: "macOS command to build the package for iOS"
default: "xcrun swift build --build-tests --sdk \"$(xcrun --sdk iphoneos --show-sdk-path)\" --triple arm64-apple-ios"
linux_build_command:
type: string
description: "Linux command to build and test the package"
default: "swift test"
linux_static_sdk_build_command:
type: string
description: "Command to use when building the package with the Static Linux Swift SDK"
default: "swift build"
wasm_sdk_build_command:
type: string
description: "Command to use when building the package with the Swift SDK for Wasm"
default: "swift build"
android_sdk_build_command:
type: string
description: "Command to use when building the package with the Swift SDK for Android"
default: "swift build"
android_sdk_triples:
type: string
description: "The triples to use when building with the Swift SDK for Android"
default: "[\"aarch64-unknown-linux-android28\", \"x86_64-unknown-linux-android28\"]"
android_ndk_versions:
type: string
description: "The NDK versions to use when building with the Swift SDK for Android"
default: "[\"r27d\"]"
windows_pre_build_command:
type: string
description: "Windows Command Prompt command to execute before building the Swift package"
default: ""
windows_build_command:
type: string
description: |
Windows Command Prompt command to build and test the package.
Note that Powershell does not automatically exit if a subcommand fails. The Invoke-Program utility is available to propagate non-zero exit codes.
It is strongly encouraged to run all command using `Invoke-Program` unless you want to continue on error eg. `Invoke-Program git apply patch.diff` instead of `git apply patch.diff`.
default: "Invoke-Program swift test"
macos_env_vars:
description: "Newline separated list of environment variables"
type: string
ios_host_env_vars:
description: "Newline separated list of environment variables"
type: string
linux_env_vars:
description: "Newline separated list of environment variables"
type: string
windows_env_vars:
description: "Newline separated list of environment variables"
type: string
enable_linux_checks:
type: boolean
description: "Boolean to enable linux testing. Defaults to true"
default: true
enable_linux_static_sdk_build:
type: boolean
description: "Boolean to enable building with the Static Linux Swift SDK. Defaults to false"
default: false
enable_wasm_sdk_build:
type: boolean
description: "Boolean to enable building with the Swift SDK for Wasm. Defaults to false"
default: false
enable_embedded_wasm_sdk_build:
type: boolean
description: "Boolean to enable building with the Embedded Swift SDK for Wasm. Defaults to false"
default: false
enable_android_sdk_build:
type: boolean
description: "Boolean to enable building with the Swift SDK for Android. Defaults to false"
default: false
enable_macos_checks:
type: boolean
description: "Boolean to enable macOS testing. Defaults to false"
default: false
enable_ios_checks:
type: boolean
description: "Boolean to enable iOS testing. Defaults to false"
default: false
enable_windows_checks:
type: boolean
description: "Boolean to enable windows testing. Defaults to true"
default: true
enable_windows_docker:
type: boolean
description: "Boolean to enable running build in windows docker container. Defaults to true"
default: true
needs_token:
type: boolean
description: "Boolean to enable providing the GITHUB_TOKEN to downstream job."
default: false
enable_cross_pr_testing:
type: boolean
description: "Whether PRs can be tested in combination with other PRs by mentioning them as `Linked PR: <link to PR>` in the PR description"
default: false
jobs:
macos-build:
name: macOS (Xcode ${{ matrix.xcode_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }})
if: ${{ inputs.enable_macos_checks }}
runs-on: [self-hosted, macos, "${{ matrix.os_version }}", "${{ matrix.arch }}"]
strategy:
fail-fast: false
matrix:
xcode_version: ${{ fromJson(inputs.macos_xcode_versions) }}
os_version: ${{ fromJson(inputs.macos_versions) }}
arch: ${{ fromJson(inputs.macos_archs) }}
exclude:
- ${{ fromJson(inputs.macos_exclude_xcode_versions) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.macos_env_vars }}
run: |
for i in "${{ inputs.macos_env_vars }}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Select Xcode
run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app" >> $GITHUB_ENV
- name: Swift version
run: xcrun swift --version
- name: Clang version
run: xcrun clang --version
- name: Pre-build
run: ${{ inputs.macos_pre_build_command }}
- name: Build / Test
run: ${{ inputs.macos_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
timeout-minutes: 60
ios-build:
name: iOS (Build Only, Xcode ${{ matrix.xcode_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }})
if: ${{ inputs.enable_ios_checks }}
runs-on: [self-hosted, macos, "${{ matrix.os_version }}", "${{ matrix.arch }}"]
strategy:
fail-fast: false
matrix:
xcode_version: ${{ fromJson(inputs.ios_host_xcode_versions || inputs.macos_xcode_versions) }}
os_version: ${{ fromJson(inputs.ios_host_versions || inputs.macos_versions) }}
arch: ${{ fromJson(inputs.ios_host_archs || inputs.macos_archs) }}
exclude:
- ${{ fromJson(inputs.ios_host_exclude_xcode_versions || inputs.macos_exclude_xcode_versions) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.ios_host_env_vars }}
run: |
for i in "${{ inputs.ios_host_env_vars }}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Select Xcode
run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app" >> $GITHUB_ENV
- name: Swift version
run: xcrun swift --version
- name: Pre-build
run: ${{ inputs.ios_pre_build_command }}
- name: Build
run: ${{ inputs.ios_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
timeout-minutes: 60
linux-build:
name: Linux (${{ matrix.swift_version }} - ${{ matrix.os_version }})
if: ${{ inputs.enable_linux_checks }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.linux_swift_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
exclude:
- ${{ fromJson(inputs.linux_exclude_swift_versions) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Check out related PRs
if: ${{ inputs.enable_cross_pr_testing && github.event_name == 'pull_request' }}
run: |
apt-get update && apt-get install -y curl
cat ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/cross-pr-checkout.swift > /tmp/cross-pr-checkout.swift
swift /tmp/cross-pr-checkout.swift "${{ github.repository }}" "${{ github.event.number }}"
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
run: |
for i in "${{ inputs.linux_env_vars }}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
run: ${{ inputs.linux_pre_build_command }}
- name: Build / Test
run: ${{ inputs.linux_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
linux-static-sdk-build:
name: Static Linux Swift SDK Build (${{ matrix.swift_version }} - ${{ matrix.os_version }})
if: ${{ inputs.enable_linux_static_sdk_build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.linux_static_sdk_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
exclude:
- ${{ fromJson(inputs.linux_static_sdk_exclude_swift_versions) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
run: |
for i in "${{ inputs.linux_env_vars }}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
run: ${{ inputs.linux_pre_build_command }}
- name: Install Static Linux Swift SDK and build
env:
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
run: |
${{ inputs.linux_static_sdk_pre_build_command }}
if command -v apt-get >/dev/null 2>&1 ; then # bookworm, noble, jammy, focal
apt-get -q update && apt-get -yq install curl
elif command -v dnf >/dev/null 2>&1 ; then # rhel-ubi9
dnf -y update
dnf -y install curl-minimal
elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2
yum -y update
yum -y install curl
else
echo "Unknown package manager (tried apt-get, dnf, yum)" >&2
exit 1
fi
cat ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh | \
bash -s -- --static --flags="$BUILD_FLAGS" --build-command="${{ inputs.linux_static_sdk_build_command }}" ${{ matrix.swift_version }}
wasm-sdk-build:
name: Swift SDK for Wasm Build (${{ matrix.swift_version }} - ${{ matrix.os_version }})
if: ${{ inputs.enable_wasm_sdk_build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.wasm_sdk_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
exclude:
- ${{ fromJson(inputs.wasm_exclude_swift_versions) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
run: |
for i in "${{ inputs.linux_env_vars }}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
run: ${{ inputs.linux_pre_build_command }}
- name: Install Swift SDK for Wasm and build
env:
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
run: |
${{ inputs.wasm_sdk_pre_build_command }}
if command -v apt-get >/dev/null 2>&1 ; then # bookworm, noble, jammy, focal
apt-get -q update && apt-get -yq install curl
elif command -v dnf >/dev/null 2>&1 ; then # rhel-ubi9
dnf -y update
dnf -y install curl-minimal
elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2
yum -y update
yum -y install curl
else
echo "Unknown package manager (tried apt-get, dnf, yum)" >&2
exit 1
fi
cat ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh | \
bash -s -- --wasm --flags="$BUILD_FLAGS" --build-command="${{ inputs.wasm_sdk_build_command }}" ${{ matrix.swift_version }}
embedded-wasm-sdk-build:
name: Embedded Swift SDK for Wasm Build (${{ matrix.swift_version }} - ${{ matrix.os_version }})
if: ${{ inputs.enable_embedded_wasm_sdk_build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.wasm_sdk_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
exclude:
- ${{ fromJson(inputs.wasm_exclude_swift_versions) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
run: |
for i in "${{ inputs.linux_env_vars }}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
run: ${{ inputs.linux_pre_build_command }}
- name: Install Swift SDK for Wasm and build
env:
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
run: |
${{ inputs.wasm_sdk_pre_build_command }}
if command -v apt-get >/dev/null 2>&1 ; then # bookworm, noble, jammy, focal
apt-get -q update && apt-get -yq install curl
elif command -v dnf >/dev/null 2>&1 ; then # rhel-ubi9
dnf -y update
dnf -y install curl-minimal
elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2
yum -y update
yum -y install curl
else
echo "Unknown package manager (tried apt-get, dnf, yum)" >&2
exit 1
fi
cat ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh | \
bash -s -- --embedded-wasm --flags="$BUILD_FLAGS" ${{ matrix.swift_version }}
android-sdk-build:
name: Swift SDK for Android Build (${{ matrix.swift_version }} - ${{ matrix.os_version }} - NDK ${{ matrix.ndk_version }})
if: ${{ inputs.enable_android_sdk_build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.android_sdk_versions) }}
ndk_version: ${{ fromJson(inputs.android_ndk_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
exclude:
- ${{ fromJson(inputs.android_exclude_swift_versions) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
run: |
for i in "${{ inputs.linux_env_vars }}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
run: ${{ inputs.linux_pre_build_command }}
- name: Install Swift SDK for Android and build
env:
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
run: |
${{ inputs.android_sdk_pre_build_command }}
if command -v apt-get >/dev/null 2>&1 ; then # bookworm, noble, jammy, focal
apt-get -q update && apt-get -yq install curl
elif command -v dnf >/dev/null 2>&1 ; then # rhel-ubi9
dnf -y update
dnf -y install curl-minimal
elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2
yum -y update
yum -y install curl
else
echo "Unknown package manager (tried apt-get, dnf, yum)" >&2
exit 1
fi
cat ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh | \
bash -s -- --android --flags="$BUILD_FLAGS" --build-command="${{ inputs.android_sdk_build_command }}" --android-sdk-triple=${{ join(fromJson(inputs.android_sdk_triples), ' --android-sdk-triple=') }} --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }}
windows-build:
name: Windows (${{ matrix.swift_version }} - ${{ matrix.os_version }})
runs-on: ${{ matrix.os_version }}
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.windows_swift_versions) }}
os_version: ${{ fromJson(inputs.windows_os_versions) }}
exclude:
- ${{ fromJson(inputs.windows_exclude_swift_versions) }}
if: ${{ inputs.enable_windows_checks && !(inputs.enable_windows_docker && matrix.os_version == 'windows-11-arm') }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout swiftlang/github-workflows repository
if: ${{ github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Determine script-root path
id: script_path
run: |
if ("${{ inputs.enable_windows_docker }}" -eq "true") {
$source = "C:\source"
} else {
$source = $env:GITHUB_WORKSPACE
}
if ("${{ github.repository }}" -eq "swiftlang/github-workflows") {
echo "root=$source" >> $env:GITHUB_OUTPUT
} else {
echo "root=$source/github-workflows" >> $env:GITHUB_OUTPUT
}
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Set environment variables
if: ${{ inputs.windows_env_vars }}
run: |
$lines = "${{ inputs.windows_env_vars }}" -split "`r`n"
foreach ($line in $lines) {
echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
- name: Pull Docker image
id: pull_docker_image
if: ${{ inputs.enable_windows_docker }}
run: |
if ("${{ matrix.swift_version }}".Contains("nightly")) {
$Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
} else {
$Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
}
docker pull $Image
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
- name: Install Visual Studio Build Tools
if: ${{ !inputs.enable_windows_docker }}
run: . ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/windows/install-vsb.ps1
- name: Install Swift
if: ${{ !inputs.enable_windows_docker }}
run: . ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/windows/swift/install-swift-${{ matrix.swift_version }}.ps1
- name: Create test script
run: |
mkdir $env:TEMP\test-script
echo @'
Set-PSDebug -Trace 1
if ("${{ inputs.enable_windows_docker }}" -eq "true") {
$Source = "C:\source"
} else {
$Source = $env:GITHUB_WORKSPACE
}
# Run the command following `Invoke-Program`.
# If that command returns a non-zero exit code, return the same exit code from this script.
function Invoke-Program($Executable) {
& $Executable @args
if ($LastExitCode -ne 0) {
exit $LastExitCode
}
}
Invoke-Program swift --version
Invoke-Program swift test --version
Invoke-Program clang --version
Invoke-Program cd $Source
'@ >> $env:TEMP\test-script\run.ps1
if ("${{ inputs.enable_cross_pr_testing && github.event_name == 'pull_request' }}" -eq "true") {
echo @'
# Running in script mode fails on Windows (https://github.com/swiftlang/swift/issues/77263), compile and run the script.
Invoke-Program swiftc -sdk $env:SDKROOT ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/cross-pr-checkout.swift -o $env:TEMP\cross-pr-checkout.exe
Invoke-Program $env:TEMP\cross-pr-checkout.exe "${{ github.repository }}" "${{ github.event.number }}"
'@ >> $env:TEMP\test-script\run.ps1
}
echo @'
${{ inputs.windows_pre_build_command }}
${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
'@ >> $env:TEMP\test-script\run.ps1
# Docker build
- name: Docker Build / Test
timeout-minutes: 60
if: ${{ inputs.enable_windows_docker }}
run: |
docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script ${{ steps.pull_docker_image.outputs.image }} powershell.exe -NoLogo -File C:\test-script\run.ps1
# Docker-less build
- name: Build / Test
timeout-minutes: 60
if: ${{ !inputs.enable_windows_docker }}
run: |
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
RefreshEnv
powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode