Skip to content

Commit 3b5576d

Browse files
Add FreeBSD build job to swift_package_test workflow (#257)
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 b337c7f commit 3b5576d

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
Invoke-Program swift build
6262
enable_windows_docker: false
6363
windows_os_versions: '["windows-2022", "windows-11-arm"]'
64+
# FreeBSD
65+
enable_freebsd_checks: true
6466

6567
tests_macos:
6668
name: Test

.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."
@@ -862,3 +893,101 @@ jobs:
862893
timeout-minutes: ${{ inputs.windows_build_timeout }}
863894
if: ${{ !inputs.enable_windows_docker }}
864895
run: powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode
896+
897+
freebsd-build:
898+
name: FreeBSD (${{ matrix.swift_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }})
899+
if: ${{ inputs.enable_freebsd_checks }}
900+
runs-on: ${{ matrix.runner }}
901+
strategy:
902+
fail-fast: false
903+
matrix:
904+
swift_version: ${{ fromJson(inputs.freebsd_swift_versions) }}
905+
os_version: ${{ fromJson(inputs.freebsd_os_versions) }}
906+
arch: ${{ fromJson(inputs.freebsd_host_archs) }}
907+
runner: ${{
908+
fromJson(
909+
contains(fromJson(inputs.freebsd_host_archs), 'x86_64') && !contains(fromJson(inputs.freebsd_host_archs), 'aarch64')
910+
&& '["ubuntu-24.04"]'
911+
|| contains(fromJson(inputs.freebsd_host_archs), 'aarch64') && !contains(fromJson(inputs.freebsd_host_archs), 'x86_64')
912+
&& '["ubuntu-24.04-arm"]'
913+
|| '["ubuntu-24.04","ubuntu-24.04-arm"]'
914+
)
915+
}}
916+
exclude:
917+
- ${{ fromJson(inputs.freebsd_exclude_swift_versions) }}
918+
- arch: x86_64
919+
runner: ubuntu-24.04-arm
920+
- arch: aarch64
921+
runner: ubuntu-24.04
922+
steps:
923+
- name: Checkout repository
924+
uses: actions/checkout@v6
925+
- name: Checkout swiftlang/github-workflows repository
926+
if: ${{ github.repository != 'swiftlang/github-workflows' }}
927+
uses: actions/checkout@v6
928+
with:
929+
repository: swiftlang/github-workflows
930+
path: github-workflows
931+
- name: Validate host architecture
932+
env:
933+
ARCH: ${{ matrix.arch }}
934+
run: |
935+
if [[ "$ARCH" != "x86_64" ]]; then
936+
echo "::error::FreeBSD builds currently only support x86_64 host architecture"
937+
exit 1
938+
fi
939+
- name: Determine Swift download URL
940+
id: swift_url
941+
env:
942+
SWIFT_VERSION: ${{ matrix.swift_version }}
943+
run: |
944+
if [[ "$SWIFT_VERSION" != "nightly-main" ]]; then
945+
echo "::error::FreeBSD builds currently only support nightly-main Swift version"
946+
exit 1
947+
fi
948+
echo "url=https://download.swift.org/tmp-ci-nightly/development/freebsd-14_ci_latest.tar.gz" >> $GITHUB_OUTPUT
949+
- name: Provide token
950+
if: ${{ inputs.needs_token }}
951+
run: |
952+
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
953+
- name: Build / Test
954+
# zizmor: ignore[template-injection]
955+
uses: vmactions/freebsd-vm@v1
956+
env:
957+
SWIFT_WEB_URL: ${{ steps.swift_url.outputs.url }}
958+
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
959+
FREEBSD_ENV_VARS: ${{ inputs.freebsd_env_vars }}
960+
with:
961+
envs: 'SWIFT_WEB_URL BUILD_FLAGS FREEBSD_ENV_VARS GITHUB_TOKEN'
962+
release: "${{ matrix.os_version }}"
963+
arch: "${{ matrix.arch }}"
964+
sync: rsync
965+
copyback: false
966+
usesh: true
967+
prepare: |
968+
fetch -o /tmp/swift.tar.gz "$SWIFT_WEB_URL"
969+
mkdir -p /opt/swift
970+
tar -xzf /tmp/swift.tar.gz -C /opt/swift
971+
pkg install -y git sqlite3 libuuid python3 curl brotli bash
972+
git config --global init.defaultBranch 'main'
973+
/opt/swift/usr/bin/swift --version
974+
run: |
975+
export PATH="/opt/swift/usr/bin:$PATH"
976+
swift --version
977+
if [ -n "$FREEBSD_ENV_VARS" ]; then
978+
printf '%s\n' "$FREEBSD_ENV_VARS" > /tmp/.env_vars
979+
while IFS= read -r _line || [ -n "$_line" ]; do
980+
export "$_line"
981+
done < /tmp/.env_vars
982+
fi
983+
if [ "${{ inputs.enable_cross_pr_testing && github.event_name == 'pull_request' }}" = "true" ]; then
984+
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
985+
SCRIPT_ROOT="."
986+
else
987+
SCRIPT_ROOT="github-workflows"
988+
fi
989+
cat "$SCRIPT_ROOT/.github/workflows/scripts/cross-pr-checkout.swift" > /tmp/cross-pr-checkout.swift
990+
swift /tmp/cross-pr-checkout.swift "${{ github.repository }}" "${{ github.event.number }}"
991+
fi
992+
${{ inputs.freebsd_pre_build_command }}
993+
${{ inputs.freebsd_build_command }} $BUILD_FLAGS

0 commit comments

Comments
 (0)