Skip to content

Update install-and-build-with-sdk.sh #2

Update install-and-build-with-sdk.sh

Update install-and-build-with-sdk.sh #2

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: 286, Col: 5): 'name' is already defined, (Line: 287, Col: 5): 'if' is already defined, (Line: 288, Col: 5): 'runs-on' is already defined, (Line: 289, Col: 5): 'strategy' is already defined, (Line: 294, Col: 5): 'container' is already defined, (Line: 296, Col: 5): 'steps' is already defined
on:
workflow_call:
inputs:
macos_xcode_versions:
type: string
description: "Xcode version list (JSON)"
default: "[\"16.2\", \"16.3\"]"
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\"]"
linux_swift_versions:
type: string
description: "Include Linux Swift version list (JSON)"
default: "[ \"5.9\", \"5.10\", \"6.0\", \"6.1\", \"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-6.2\"]"
wasm_sdk_versions:
type: string
description: "Wasm Swift SDK version list (JSON)"
default: "[\"nightly\", \"nightly-6.2\"]"
windows_swift_versions:
type: string
description: "Include Windows Swift version list (JSON)"
default: "[\"5.9\", \"6.0\", \"6.1\", \"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: ""
embedded_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"
linux_build_command:
type: string
description: "Linux command to build and test the package"
default: "swift test"
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: "swift test"
macos_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_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
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: 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
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: 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: 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) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --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 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 }}
which curl || (apt -q update && apt -yq install curl)
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" ${{ 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) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --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 }}
which curl || (apt -q update && apt -yq install curl)
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" ${{ matrix.swift_version }} 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) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --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 }}
which curl || (apt -q update && apt -yq install curl)
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 cd $Source
${{ inputs.windows_pre_build_command }}
Invoke-Program ${{ 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