Add workflow to build packages for iOS. #16
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Swift Matrix | ||
|
Check failure on line 1 in .github/workflows/swift_package_test.yml
|
||
| 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\": \"\"}]" | ||
| 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\": \"\"}]" | ||
| 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: "" | ||
| 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" | ||
| 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_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: Echo inputs.ios_host_xcode_versions | ||
| run: echo "${{ inputs.ios_host_xcode_versions }}" | ||
| - 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: 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 | ||
| curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.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: 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 | ||
| 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 --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: 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 | ||
| 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 -- --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 | ||
| - 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 | ||
| 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 -- --embedded-wasm --flags="$BUILD_FLAGS" ${{ matrix.swift_version }} | ||
| windows-build: | ||
| name: Windows (${{ matrix.swift_version }} - windows-2022) | ||
| if: ${{ inputs.enable_windows_checks }} | ||
| runs-on: windows-2022 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| swift_version: ${{ fromJson(inputs.windows_swift_versions) }} | ||
| exclude: | ||
| - ${{ fromJson(inputs.windows_exclude_swift_versions) }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - 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: | | ||
| Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/install-vsb.ps1 -OutFile $env:TEMP\install-vsb.ps1 | ||
| . $env:TEMP\install-vsb.ps1 | ||
| del $env:TEMP\install-vsb.ps1 | ||
| - name: Install Swift | ||
| if: ${{ !inputs.enable_windows_docker }} | ||
| run: | | ||
| Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/swift/install-swift.ps1 -OutFile $env:TEMP\install-swift.ps1 | ||
| Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/swift/install-swift-${{ matrix.swift_version }}.ps1 -OutFile $env:TEMP\install-swift-${{ matrix.swift_version }}.ps1 | ||
| . $env:TEMP\install-swift-${{ matrix.swift_version }}.ps1 | ||
| del $env:TEMP\install-swift*.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 @' | ||
| Invoke-WebRequest https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/cross-pr-checkout.swift -OutFile $env:TEMP\cross-pr-checkout.swift | ||
| # 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 $env:TEMP\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 | ||