Skip to content

Commit bafcd23

Browse files
committed
Add FreeBSD build job to swift_package_test workflow
Adds a new freebsd-build job using vmactions/freebsd-vm to run Swift builds and tests inside a FreeBSD VM on Ubuntu runners. Configurable via freebsd_swift_versions, freebsd_os_versions, freebsd_host_archs, freebsd_pre_build_command, freebsd_build_command, freebsd_env_vars, and enable_freebsd_checks inputs. Supports cross-PR testing, nightly flag selection, and multi-arch runner selection matching the existing Linux job pattern.
1 parent f84da04 commit bafcd23

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

.github/workflows/swift_package_test.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ on:
9191
type: string
9292
description: "Windows OS version label list (JSON)"
9393
default: "[\"windows-2022\"]"
94+
freebsd_swift_versions:
95+
type: string
96+
description: "FreeBSD Swift version list (JSON)"
97+
default: "[\"nightly-main\"]"
98+
freebsd_exclude_swift_versions:
99+
type: string
100+
description: "Exclude FreeBSD Swift version list (JSON)"
101+
default: "[{\"swift_version\": \"\"}]"
102+
freebsd_os_versions:
103+
type: string
104+
description: "FreeBSD OS version list (JSON)"
105+
default: "[\"14.3\"]"
106+
freebsd_host_archs:
107+
type: string
108+
description: "FreeBSD host arch list (JSON)"
109+
default: "[\"x86_64\"]"
94110
swift_flags:
95111
type: string
96112
description: "Swift flags for release version"
@@ -178,6 +194,14 @@ on:
178194
type: number
179195
description: "The default step timeout in minutes"
180196
default: 60
197+
freebsd_pre_build_command:
198+
type: string
199+
description: "FreeBSD command to execute before building the Swift package"
200+
default: ""
201+
freebsd_build_command:
202+
type: string
203+
description: "FreeBSD command to build and test the package"
204+
default: "swift test"
181205
macos_env_vars:
182206
description: "Newline separated list of environment variables"
183207
type: string
@@ -190,6 +214,9 @@ on:
190214
windows_env_vars:
191215
description: "Newline separated list of environment variables"
192216
type: string
217+
freebsd_env_vars:
218+
description: "Newline separated list of environment variables"
219+
type: string
193220
enable_linux_checks:
194221
type: boolean
195222
description: "Boolean to enable linux testing. Defaults to true"
@@ -230,6 +257,10 @@ on:
230257
type: boolean
231258
description: "Boolean to enable running build in windows docker container. Defaults to true"
232259
default: true
260+
enable_freebsd_checks:
261+
type: boolean
262+
description: "Boolean to enable FreeBSD testing. Defaults to false"
263+
default: false
233264
needs_token:
234265
type: boolean
235266
description: "Boolean to enable providing the GITHUB_TOKEN to downstream job."
@@ -828,3 +859,101 @@ jobs:
828859
timeout-minutes: ${{ inputs.windows_build_timeout }}
829860
if: ${{ !inputs.enable_windows_docker }}
830861
run: powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode
862+
863+
freebsd-build:
864+
name: FreeBSD (${{ matrix.swift_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }})
865+
if: ${{ inputs.enable_freebsd_checks }}
866+
runs-on: ${{ matrix.runner }}
867+
strategy:
868+
fail-fast: false
869+
matrix:
870+
swift_version: ${{ fromJson(inputs.freebsd_swift_versions) }}
871+
os_version: ${{ fromJson(inputs.freebsd_os_versions) }}
872+
arch: ${{ fromJson(inputs.freebsd_host_archs) }}
873+
runner: ${{
874+
fromJson(
875+
contains(fromJson(inputs.freebsd_host_archs), 'x86_64') && !contains(fromJson(inputs.freebsd_host_archs), 'aarch64')
876+
&& '["ubuntu-24.04"]'
877+
|| contains(fromJson(inputs.freebsd_host_archs), 'aarch64') && !contains(fromJson(inputs.freebsd_host_archs), 'x86_64')
878+
&& '["ubuntu-24.04-arm"]'
879+
|| '["ubuntu-24.04","ubuntu-24.04-arm"]'
880+
)
881+
}}
882+
exclude:
883+
- ${{ fromJson(inputs.freebsd_exclude_swift_versions) }}
884+
- arch: x86_64
885+
runner: ubuntu-24.04-arm
886+
- arch: aarch64
887+
runner: ubuntu-24.04
888+
steps:
889+
- name: Checkout repository
890+
uses: actions/checkout@v6
891+
- name: Checkout swiftlang/github-workflows repository
892+
if: ${{ github.repository != 'swiftlang/github-workflows' }}
893+
uses: actions/checkout@v6
894+
with:
895+
repository: swiftlang/github-workflows
896+
path: github-workflows
897+
- name: Validate host architecture
898+
env:
899+
ARCH: ${{ matrix.arch }}
900+
run: |
901+
if [[ "$ARCH" != "x86_64" ]]; then
902+
echo "::error::FreeBSD builds currently only support x86_64 host architecture"
903+
exit 1
904+
fi
905+
- name: Determine Swift download URL
906+
id: swift_url
907+
env:
908+
SWIFT_VERSION: ${{ matrix.swift_version }}
909+
run: |
910+
if [[ "$SWIFT_VERSION" != "nightly-main" ]]; then
911+
echo "::error::FreeBSD builds currently only support nightly-main Swift version"
912+
exit 1
913+
fi
914+
echo "url=https://download.swift.org/tmp-ci-nightly/development/freebsd-14_ci_latest.tar.gz" >> $GITHUB_OUTPUT
915+
- name: Provide token
916+
if: ${{ inputs.needs_token }}
917+
run: |
918+
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
919+
- name: Build / Test
920+
# zizmor: ignore[template-injection]
921+
uses: vmactions/freebsd-vm@v1
922+
env:
923+
SWIFT_WEB_URL: ${{ steps.swift_url.outputs.url }}
924+
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
925+
FREEBSD_ENV_VARS: ${{ inputs.freebsd_env_vars }}
926+
with:
927+
envs: 'SWIFT_WEB_URL BUILD_FLAGS FREEBSD_ENV_VARS GITHUB_TOKEN'
928+
release: "${{ matrix.os_version }}"
929+
arch: "${{ matrix.arch }}"
930+
sync: rsync
931+
copyback: false
932+
usesh: true
933+
prepare: |
934+
fetch -o /tmp/swift.tar.gz "$SWIFT_WEB_URL"
935+
mkdir -p /opt/swift
936+
tar -xzf /tmp/swift.tar.gz -C /opt/swift
937+
pkg install -y git sqlite3 libuuid python3 curl brotli bash
938+
git config --global init.defaultBranch 'main'
939+
/opt/swift/usr/bin/swift --version
940+
run: |
941+
export PATH="/opt/swift/usr/bin:$PATH"
942+
swift --version
943+
if [ -n "$FREEBSD_ENV_VARS" ]; then
944+
printf '%s\n' "$FREEBSD_ENV_VARS" > /tmp/.env_vars
945+
while IFS= read -r _line || [ -n "$_line" ]; do
946+
export "$_line"
947+
done < /tmp/.env_vars
948+
fi
949+
if [ "${{ inputs.enable_cross_pr_testing && github.event_name == 'pull_request' }}" = "true" ]; then
950+
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
951+
SCRIPT_ROOT="."
952+
else
953+
SCRIPT_ROOT="github-workflows"
954+
fi
955+
cat "$SCRIPT_ROOT/.github/workflows/scripts/cross-pr-checkout.swift" > /tmp/cross-pr-checkout.swift
956+
swift /tmp/cross-pr-checkout.swift "${{ github.repository }}" "${{ github.event.number }}"
957+
fi
958+
${{ inputs.freebsd_pre_build_command }}
959+
${{ inputs.freebsd_build_command }} $BUILD_FLAGS

0 commit comments

Comments
 (0)