mirror of
https://github.com/storytold/craft-common-actions.git
synced 2026-11-30 18:24:29 +01:00
444 lines
23 KiB
YAML
444 lines
23 KiB
YAML
name: "FreeBSD"
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
architectures:
|
|
description: 'JSON architecture array; empty selects x86_64 for PRs and both architectures otherwise'
|
|
type: string
|
|
required: false
|
|
default: ""
|
|
craft-fonts-ref:
|
|
# The suite's craft-fonts pin, as in release.yml.
|
|
description: "The commit ref for storytold/craft-fonts. Defaults to the suite's pin; empty builds without craft-fonts"
|
|
type: string
|
|
required: false
|
|
default: "bfcbf714e45a3ea8e98f88ab2b7971372a576414"
|
|
require-craft-fonts:
|
|
description: "Require the supplied craft-fonts checkout during builds and tests"
|
|
type: boolean
|
|
required: false
|
|
default: false
|
|
freebsd-release:
|
|
description: "FreeBSD OS release version to run in the VM"
|
|
type: string
|
|
required: false
|
|
default: "15.1-STABLE"
|
|
build-jobs:
|
|
description: "Concurrent Cargo builds (1-4); lower for memory-heavy crates, without changing test selection"
|
|
type: number
|
|
required: false
|
|
default: 4
|
|
cargo-test-extra-args:
|
|
description: "Extra arguments to append to cargo test (shell-style quoting, no shell expansion)"
|
|
type: string
|
|
required: false
|
|
default: ""
|
|
cargo-build-extra-args:
|
|
description: "Extra arguments to append to cargo build (shell-style quoting, no shell expansion)"
|
|
type: string
|
|
required: false
|
|
default: ""
|
|
skip-tests:
|
|
description: "Skip running tests (e.g. if the VM lacks GPU/oracle dependencies)"
|
|
type: boolean
|
|
required: false
|
|
default: false
|
|
run-package-check:
|
|
description: "Run packaging/freebsd/package.sh and verify produced tarball"
|
|
type: boolean
|
|
required: false
|
|
default: false
|
|
custom-test-command:
|
|
description: "Custom test commands to run instead of default cargo test"
|
|
type: string
|
|
required: false
|
|
default: ""
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
freebsd:
|
|
name: FreeBSD 15 ${{ matrix.arch }} (build + test)
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 300
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
arch: ${{ fromJSON(inputs.architectures != '' && inputs.architectures || ((github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && '["x86_64"]' || '["x86_64","aarch64"]')) }}
|
|
env:
|
|
CARGO_BUILD_EXTRA_ARGS: ${{ inputs.cargo-build-extra-args }}
|
|
CARGO_TEST_EXTRA_ARGS: ${{ inputs.cargo-test-extra-args }}
|
|
CUSTOM_TEST_COMMAND: ${{ inputs.custom-test-command }}
|
|
CARGO_HOME: /var/tmp/craft-cargo
|
|
CARGO_TARGET_DIR: /var/tmp/craft-target
|
|
CARGO_INCREMENTAL: 0
|
|
CARGO_BUILD_JOBS: ${{ inputs.build-jobs }}
|
|
steps:
|
|
- name: Harden runner
|
|
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
|
with:
|
|
egress-policy: audit
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
- name: Check out craft-fonts
|
|
if: inputs.craft-fonts-ref != ''
|
|
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@main
|
|
with:
|
|
ref: ${{ inputs.craft-fonts-ref }}
|
|
- name: Check out craft-i18n
|
|
uses: storytold/craft-common-actions/actions/checkout-craft-i18n@main
|
|
# The architecture is interpolated into the guest's shell source below.
|
|
- name: Validate the architecture
|
|
env:
|
|
ARCH: ${{ matrix.arch }}
|
|
run: |
|
|
case "$ARCH" in
|
|
x86_64|aarch64) ;;
|
|
*) echo "::error::unsupported architecture '$ARCH' (use x86_64 or aarch64)"; exit 1 ;;
|
|
esac
|
|
# Validate environment data before starting the VM. Never interpolate it into shell source.
|
|
- name: Validate build concurrency
|
|
shell: bash
|
|
run: |
|
|
case "$CARGO_BUILD_JOBS" in
|
|
1|2|3|4) ;;
|
|
*) echo "::error::build-jobs must be an integer from 1 to 4"; exit 1 ;;
|
|
esac
|
|
# The VM action apt-installs QEMU on the host: give it the mirrors outside ubuntu.com, and
|
|
# drop the image's Microsoft source, which this job never installs from.
|
|
- name: Configure apt mirrors
|
|
uses: storytold/craft-common-actions/actions/configure-apt-mirrors@main
|
|
- name: Drop the Microsoft apt source
|
|
run: sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list /etc/apt/sources.list.d/microsoft-prod.sources
|
|
# The VM disk and the expanded Cargo cache share the hosted Linux filesystem.
|
|
# Reclaim only unused image toolchains, as Gate does, before either can grow.
|
|
# Wait for cleanup: background deletion can race VM/cache allocation (#266).
|
|
- name: Reclaim unused hosted toolchains
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
echo "::group::Host capacity before cleanup"
|
|
df -B1 / "$RUNNER_TEMP" "$GITHUB_WORKSPACE"
|
|
df -i / "$RUNNER_TEMP" "$GITHUB_WORKSPACE"
|
|
echo "::endgroup::"
|
|
sudo rm -rf -- /usr/local/lib/android /usr/share/dotnet /opt/ghc /usr/local/.ghcup /opt/hostedtoolcache/CodeQL
|
|
echo "::group::Host capacity after cleanup"
|
|
df -B1 / "$RUNNER_TEMP" "$GITHUB_WORKSPACE"
|
|
df -i / "$RUNNER_TEMP" "$GITHUB_WORKSPACE"
|
|
echo "::endgroup::"
|
|
- name: Start the FreeBSD VM
|
|
uses: step-security/freebsd-vm@a2f5754275f7b0d5cea7f2762c9960727950f128 # v1.5.9
|
|
with:
|
|
release: ${{ inputs.freebsd-release == '15.1-STABLE' && '15.1' || inputs.freebsd-release }}
|
|
# Always an x86_64 guest, which KVM accelerates: aarch64 is cross-compiled in it,
|
|
# because an emulated aarch64 guest compiles about 23 times slower (#33).
|
|
usesh: true
|
|
cpu: 4
|
|
mem: 12288
|
|
copyback: false
|
|
envs: "CARGO_HOME CARGO_TARGET_DIR CARGO_INCREMENTAL CARGO_BUILD_JOBS CARGO_BUILD_EXTRA_ARGS CARGO_TEST_EXTRA_ARGS CUSTOM_TEST_COMMAND ARCH"
|
|
prepare: |
|
|
# Keep rustup/proxies outside the Cargo data cache.
|
|
unset CARGO_HOME CARGO_TARGET_DIR
|
|
# A large test crate's rustc (photocraft-ui-egui's lib tests) was SIGKILLed when the
|
|
# 12 GB guest ran out of memory late in a run: the image's root is ZFS with no ARC
|
|
# limit, so the ARC kept the target dir's pages. Cap it. (No swap file: swap on a
|
|
# ZFS-backed file can hang FreeBSD under memory pressure; the image has a 1 GB swap
|
|
# partition.) Print disk, swap and memory so the next OOM is easy to diagnose.
|
|
if [ "$(uname -s)" = FreeBSD ]; then
|
|
if sysctl -n vfs.zfs.arc_max >/dev/null 2>&1; then
|
|
sysctl vfs.zfs.arc_max=2147483648 || echo "::warning::could not cap the ZFS ARC"
|
|
fi
|
|
df -h / /var/tmp || true
|
|
swapctl -l || true
|
|
sysctl -n hw.physmem || true
|
|
fi
|
|
if [ "${{ matrix.arch }}" = aarch64 ]; then
|
|
# The host compiler and the aarch64 standard library come from the amd64 and
|
|
# aarch64 lang/rust packages, which must be the same build. "latest" can build
|
|
# them days apart; the quarterly branch keeps them in step.
|
|
mkdir -p /usr/local/etc/pkg/repos
|
|
printf 'FreeBSD-ports: { url: "https://pkg.FreeBSD.org/${ABI}/quarterly" }\n' > /usr/local/etc/pkg/repos/FreeBSD.conf
|
|
pkg update -f -q
|
|
fi
|
|
pkg install -y bash git curl pkgconf cmake-core python3 libxkbcommon wayland libX11 libXcursor libXrandr libXi libxcb mesa-libs vulkan-loader gtk3 webkit2-gtk_41 libsoup3 fontconfig freetype2 alsa-lib dejavu
|
|
# aarch64-unknown-freebsd is a tier-3 Rust target: rustup publishes no toolchain
|
|
# or standard library for it ("installer for platform not found"), so use
|
|
# FreeBSD's lang/rust package.
|
|
if [ "${{ matrix.arch }}" = aarch64 ]; then
|
|
pkg install -y rust
|
|
else
|
|
curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal
|
|
fi
|
|
- name: Set up the aarch64 cross toolchain
|
|
if: matrix.arch == 'aarch64'
|
|
shell: freebsd {0}
|
|
run: |
|
|
set -eu
|
|
# Stable Rust, no -Zbuild-std: the aarch64 standard library is copied from FreeBSD's
|
|
# aarch64 lang/rust package, and C code links with base clang and lld against an
|
|
# arm64 sysroot (base.txz plus the libraries the prepare step installs).
|
|
target=aarch64-unknown-freebsd
|
|
X=/var/tmp/craft-cross
|
|
S=$X/sysroot
|
|
mkdir -p "$X/db" "$X/cache" "$S"
|
|
release=$(freebsd-version -u | sed 's/-p[0-9]*$//')
|
|
P="-o ABI=FreeBSD:${release%%.*}:aarch64 -o OSVERSION=$(uname -U) -o PKG_DBDIR=$X/db -o PKG_CACHEDIR=$X/cache -o IGNORE_OSVERSION=yes"
|
|
pkg $P update -q
|
|
host=$(pkg query %v rust)
|
|
cross=$(pkg $P rquery %v rust)
|
|
if [ "$host" != "$cross" ]; then
|
|
echo "error: lang/rust is $host for amd64 but $cross for aarch64; the standard library must match the compiler" >&2
|
|
exit 1
|
|
fi
|
|
pkg $P fetch -y -q rust
|
|
# pkg links each name-version.pkg to its hashed file.
|
|
tar -xf "$X/cache/rust-$cross.pkg" -C "$X" --include "*usr/local/lib/rustlib/$target/*"
|
|
cp -R "$X/usr/local/lib/rustlib/$target" /usr/local/lib/rustlib/
|
|
base=https://download.freebsd.org/releases/arm64/aarch64/$release
|
|
# Bound transient network retries; never extract an unverified partial file.
|
|
fetch_release_file() {
|
|
url=$1
|
|
destination=$2
|
|
attempt=1
|
|
while [ "$attempt" -le 3 ]; do
|
|
if curl -fL --proto =https --proto-redir =https --connect-timeout 20 --max-time 180 \
|
|
-o "$destination.part" "$url"; then
|
|
mv "$destination.part" "$destination"
|
|
return 0
|
|
fi
|
|
rm -f "$destination.part"
|
|
if [ "$attempt" -eq 3 ]; then
|
|
echo "error: could not fetch $url after $attempt attempts" >&2
|
|
return 1
|
|
fi
|
|
sleep "$((attempt * 5))"
|
|
attempt=$((attempt + 1))
|
|
done
|
|
}
|
|
fetch_release_file "$base/MANIFEST" "$X/MANIFEST"
|
|
fetch_release_file "$base/base.txz" "$X/base.txz"
|
|
if [ "$(awk '$1 == "base.txz" { print $2 }' "$X/MANIFEST")" != "$(sha256 -q "$X/base.txz")" ]; then
|
|
echo "error: arm64 base.txz does not match its MANIFEST" >&2
|
|
exit 1
|
|
fi
|
|
tar -xf "$X/base.txz" -C "$S" ./lib ./usr/lib ./usr/include ./usr/libdata ./usr/share
|
|
# The libraries the prepare step installs; the build tools and fonts stay host-only.
|
|
# xorgproto provides xproto, renderproto, kbproto and xextproto .pc files that
|
|
# GTK's public dependency chain needs, but that are not runtime dependencies.
|
|
pkg $P fetch -y -q -d libxkbcommon wayland libX11 libXcursor libXrandr libXi libxcb mesa-libs vulkan-loader gtk3 webkit2-gtk_41 libsoup3 fontconfig freetype2 alsa-lib xorgproto
|
|
for p in "$X"/cache/*.pkg; do
|
|
# pkg names each fetched archive with a symlink to its hashed cache file.
|
|
# tar follows the link; skipping links here leaves the sysroot without any ports.
|
|
[ -e "$p" ] || continue
|
|
case "$p" in */rust-*) continue ;; esac
|
|
tar -xf "$p" -C "$S" --exclude '+*'
|
|
done
|
|
if [ ! -f "$S/usr/local/libdata/pkgconfig/gdk-3.0.pc" ]; then
|
|
echo "error: aarch64 sysroot is missing gtk3's gdk-3.0.pc" >&2
|
|
exit 1
|
|
fi
|
|
for tool in cc c++; do
|
|
printf '#!/bin/sh\nexec %s --target=%s%s --sysroot=%s -fuse-ld=lld -I%s/usr/local/include -L%s/usr/local/lib -Wl,-rpath-link,%s/usr/local/lib "$@"\n' \
|
|
"$tool" "$target" "${release%%-*}" "$S" "$S" "$S" "$S" > "$X/$tool"
|
|
chmod +x "$X/$tool"
|
|
done
|
|
cat > "$X/env" <<EOF
|
|
export CARGO_BUILD_TARGET=$target
|
|
export CARGO_TARGET_AARCH64_UNKNOWN_FREEBSD_LINKER=$X/cc
|
|
export CC_aarch64_unknown_freebsd=$X/cc CXX_aarch64_unknown_freebsd=$X/c++ AR_aarch64_unknown_freebsd=/usr/bin/ar
|
|
export PKG_CONFIG_ALLOW_CROSS=1 PKG_CONFIG_SYSROOT_DIR=$S
|
|
export PKG_CONFIG_PATH=$S/usr/local/libdata/pkgconfig:$S/usr/local/lib/pkgconfig:$S/usr/local/share/pkgconfig:$S/usr/share/pkgconfig:$S/usr/libdata/pkgconfig
|
|
export PKG_CONFIG_LIBDIR=$S/usr/local/libdata/pkgconfig:$S/usr/local/lib/pkgconfig:$S/usr/local/share/pkgconfig:$S/usr/share/pkgconfig:$S/usr/libdata/pkgconfig
|
|
EOF
|
|
. "$X/env"
|
|
if [ "${CARGO_BUILD_TARGET:-}" != "$target" ]; then
|
|
echo "error: $X/env did not set CARGO_BUILD_TARGET=$target" >&2
|
|
cat "$X/env" >&2 || true
|
|
exit 1
|
|
fi
|
|
if ! pkg-config --exists gdk-3.0; then
|
|
echo "error: pkg-config cannot resolve gdk-3.0 from the aarch64 sysroot" >&2
|
|
ls -l "$S/usr/local/libdata/pkgconfig/gdk-3.0.pc" >&2
|
|
sed -n '1,100p' "$S/usr/local/libdata/pkgconfig/gdk-3.0.pc" >&2
|
|
pkg-config --print-errors --exists gdk-3.0 || true
|
|
pkg-config --debug --print-errors --modversion gdk-3.0 || true
|
|
exit 1
|
|
fi
|
|
rustc --print target-libdir --target "$target"
|
|
- name: Restore FreeBSD Cargo cache
|
|
id: cargo-cache
|
|
continue-on-error: true
|
|
timeout-minutes: 10
|
|
uses: storytold/craft-common-actions/actions/freebsd-cargo-cache@main
|
|
with:
|
|
target: ${{ matrix.arch == 'aarch64' && 'aarch64-unknown-freebsd' || '' }}
|
|
configuration: ${{ toJSON(inputs) }}
|
|
source-hash: ${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', '**/build.rs', '.cargo/**', 'rust-toolchain*', 'packaging/**', '.github/workflows/freebsd.yml') }}
|
|
# Host ENOSPC can kill the runner before it uploads the guest build log.
|
|
# Measure bytes and inodes after the VM and restored cache occupy the host.
|
|
- name: Report host capacity before build
|
|
shell: bash
|
|
run: |
|
|
df -B1 / "$RUNNER_TEMP" "$GITHUB_WORKSPACE"
|
|
df -i / "$RUNNER_TEMP" "$GITHUB_WORKSPACE"
|
|
- name: Build and test
|
|
shell: freebsd {0}
|
|
env:
|
|
ARCH: ${{ matrix.arch }}
|
|
run: |
|
|
set -eu
|
|
# Only rustup writes this; the lang/rust package installs into /usr/local/bin.
|
|
[ ! -f "$HOME/.cargo/env" ] || . "$HOME/.cargo/env"
|
|
# A failed restore may leave partial files. Rebuild from an empty cache.
|
|
if [ "${{ steps.cargo-cache.outcome }}" = failure ]; then
|
|
rm -rf /var/tmp/craft-target /var/tmp/craft-cargo/registry /var/tmp/craft-cargo/git
|
|
fi
|
|
git config --global --add safe.directory "*"
|
|
rustc --version
|
|
if [ -d craft-fonts ]; then
|
|
export CRAFT_FONTS_DIR="$PWD/craft-fonts"
|
|
fi
|
|
if [ "${{ inputs.require-craft-fonts }}" = "true" ]; then
|
|
if [ ! -d craft-fonts ]; then
|
|
echo "error: required craft-fonts checkout is missing" >&2
|
|
exit 1
|
|
fi
|
|
export CRAFT_FONTS_REQUIRED=1
|
|
fi
|
|
if [ -f craft-i18n.rev ]; then export CRAFT_I18N_DIR="$PWD/craft-i18n" CRAFT_I18N_REQUIRED=1; fi
|
|
# Written by "Set up the aarch64 cross toolchain": cargo then builds for aarch64.
|
|
# Fail closed: an incomplete env file (FreeBSD sh may not abort on an unset
|
|
# variable in the unquoted heredoc) would leave CARGO_BUILD_TARGET unset, and
|
|
# package.sh would name an x86_64 archive after uname -m.
|
|
[ ! -f /var/tmp/craft-cross/env ] || . /var/tmp/craft-cross/env
|
|
if [ "$ARCH" = aarch64 ] && [ "${CARGO_BUILD_TARGET:-}" != aarch64-unknown-freebsd ]; then
|
|
echo "error: FreeBSD aarch64 job has CARGO_BUILD_TARGET='${CARGO_BUILD_TARGET:-}'; expected aarch64-unknown-freebsd from /var/tmp/craft-cross/env" >&2
|
|
exit 1
|
|
fi
|
|
# Tests run as an ordinary user: root is never refused a file, so a test that expects
|
|
# "permission denied" fails as root, and a permission bug root would hide goes unseen.
|
|
as_tester() {
|
|
if [ "$(id -u)" -ne 0 ]; then sh -eu; return; fi
|
|
id craft-test >/dev/null 2>&1 || pw useradd craft-test -m -s /bin/sh
|
|
# rustup's toolchains stay under /root; tests write the target, Cargo's cache and the checkout.
|
|
rustup_home=${RUSTUP_HOME:-$HOME/.rustup}
|
|
chmod 755 /root
|
|
chown -R craft-test "$CARGO_TARGET_DIR" "$CARGO_HOME" "$PWD"
|
|
HOME=/home/craft-test RUSTUP_HOME=$rustup_home su -m craft-test -c 'sh -eu'
|
|
}
|
|
# Keep argument data out of shell source, including the tester's shell below.
|
|
CARGO_PROFILE_DEV_DEBUG=0 python3 - <<'PY'
|
|
import os
|
|
import shlex
|
|
|
|
os.execvp("cargo", ["cargo", "build", "--workspace", "--all-targets", "--locked",
|
|
*shlex.split(os.environ["CARGO_BUILD_EXTRA_ARGS"])])
|
|
PY
|
|
if [ "${{ inputs.skip-tests }}" != "true" ]; then
|
|
if [ "$ARCH" = aarch64 ]; then
|
|
# The build above compiled every test target; an x86_64 guest cannot run them.
|
|
echo "::notice title=FreeBSD aarch64::cross-compiled on x86_64: tests built, not run"
|
|
elif [ "${{ inputs.custom-test-command != '' }}" = "true" ]; then
|
|
# Isolate the command list: an early failure in an && chain must not
|
|
# be hidden by a later successful packaging command in this script.
|
|
# The command text travels as data in the environment, never in this script's source.
|
|
printf '%s\n' "$CUSTOM_TEST_COMMAND" | as_tester || exit "$?"
|
|
else
|
|
as_tester <<'CRAFT_TESTS'
|
|
CARGO_PROFILE_DEV_DEBUG=0 python3 - <<'PY'
|
|
import os
|
|
import shlex
|
|
|
|
os.execvp("cargo", ["cargo", "test", "--workspace", "--locked",
|
|
*shlex.split(os.environ["CARGO_TEST_EXTRA_ARGS"])])
|
|
PY
|
|
CRAFT_TESTS
|
|
fi
|
|
fi
|
|
# package.sh builds for the guest's own architecture, so the cross-compiled aarch64
|
|
# leg stops after the build.
|
|
- name: Checkpoint tests and restore the release profile
|
|
id: package-cache
|
|
continue-on-error: true
|
|
timeout-minutes: 10
|
|
if: inputs.run-package-check && matrix.arch != 'aarch64'
|
|
uses: storytold/craft-common-actions/actions/freebsd-cargo-cache@main
|
|
with:
|
|
phase: package
|
|
target: ${{ matrix.arch == 'aarch64' && 'aarch64-unknown-freebsd' || '' }}
|
|
configuration: ${{ toJSON(inputs) }}
|
|
source-hash: ${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', '**/build.rs', '.cargo/**', 'rust-toolchain*', 'packaging/**', '.github/workflows/freebsd.yml') }}
|
|
- name: Build and validate the FreeBSD package
|
|
if: inputs.run-package-check && matrix.arch != 'aarch64'
|
|
shell: freebsd {0}
|
|
env:
|
|
ARCH: ${{ matrix.arch }}
|
|
run: |
|
|
set -eu
|
|
[ ! -f "$HOME/.cargo/env" ] || . "$HOME/.cargo/env"
|
|
# Required even if the optional cache checkpoint failed before cleanup.
|
|
rm -rf /var/tmp/craft-target/debug
|
|
if [ "${{ steps.package-cache.outcome }}" = failure ]; then
|
|
rm -rf /var/tmp/craft-target/release
|
|
fi
|
|
if [ -d craft-fonts ]; then export CRAFT_FONTS_DIR="$PWD/craft-fonts"; fi
|
|
if [ "${{ inputs.require-craft-fonts }}" = true ]; then export CRAFT_FONTS_REQUIRED=1; fi
|
|
if [ -f craft-i18n.rev ]; then export CRAFT_I18N_DIR="$PWD/craft-i18n" CRAFT_I18N_REQUIRED=1; fi
|
|
if [ ! -f packaging/freebsd/package.sh ]; then
|
|
echo "error: requested FreeBSD packaging script is missing" >&2
|
|
exit 1
|
|
fi
|
|
bash packaging/freebsd/package.sh
|
|
# Check every produced archive; an unmatched glob or unreadable tarball
|
|
# must fail instead of turning a requested package check into a no-op.
|
|
for archive in dist/release/*-freebsd-$ARCH.tar.gz; do
|
|
if [ ! -f "$archive" ]; then
|
|
echo "error: no FreeBSD $ARCH package was produced" >&2
|
|
exit 1
|
|
fi
|
|
tar -tzf "$archive"
|
|
done
|
|
- name: Save FreeBSD Cargo cache
|
|
if: github.event_name != 'pull_request' && github.event_name != 'pull_request_target' && steps.cargo-cache.outputs.key != '' && steps.cargo-cache.outputs.cache-hit != 'true'
|
|
continue-on-error: true
|
|
timeout-minutes: 10
|
|
uses: storytold/craft-common-actions/actions/freebsd-cargo-cache@main
|
|
with:
|
|
phase: save
|
|
target: ${{ matrix.arch == 'aarch64' && 'aarch64-unknown-freebsd' || '' }}
|
|
configuration: ${{ toJSON(inputs) }}
|
|
source-hash: ${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', '**/build.rs', '.cargo/**', 'rust-toolchain*', 'packaging/**', '.github/workflows/freebsd.yml') }}
|
|
key: ${{ steps.cargo-cache.outputs.key }}
|
|
|
|
# Exit 137 alone does not distinguish host pressure from a guest OOM.
|
|
# Keep diagnostics bounded and separate so they cannot turn a failed build green.
|
|
- name: Report final host and guest resources
|
|
if: always() && !cancelled()
|
|
continue-on-error: true
|
|
timeout-minutes: 2
|
|
shell: bash
|
|
run: |
|
|
echo "::group::Final host resources"
|
|
df -B1 / "$RUNNER_TEMP" "$GITHUB_WORKSPACE" || true
|
|
df -i / "$RUNNER_TEMP" "$GITHUB_WORKSPACE" || true
|
|
free -b || true
|
|
sudo -n dmesg --color=never | grep -Ei 'out of memory|oom-kill|killed process' | tail -n 30 || true
|
|
echo "::endgroup::"
|
|
# Only fixed read-only commands enter the guest, never caller-provided shell text.
|
|
diagnostics=$(mktemp "$RUNNER_TEMP/freebsd-resources.XXXXXX")
|
|
cat > "$diagnostics" <<'FREEBSD_RESOURCES'
|
|
df -k / /var/tmp
|
|
swapinfo -k
|
|
sysctl hw.physmem vm.stats.vm.v_free_count vm.stats.vm.v_inactive_count vm.stats.vm.v_wire_count
|
|
sysctl kstat.zfs.misc.arcstats.size
|
|
dmesg | grep -Ei 'out of swap|out of memory|killed|swap_pager' | tail -n 30 || true
|
|
FREEBSD_RESOURCES
|
|
# Use the established SSH alias directly: the freebsd wrapper would resync the worktree.
|
|
echo "::group::Final guest resources"
|
|
timeout --kill-after=5s 30s ssh -o BatchMode=yes -o ConnectTimeout=5 freebsd sh < "$diagnostics" || echo "::warning::Guest resource diagnostics unavailable or timed out"
|
|
echo "::endgroup::"
|