| 1 |
name: FreeBSD |
| 2 |
|
| 3 |
# spell-checker:ignore sshfs usesh vmactions taiki esac fdescfs fdesc nextest copyback logind |
| 4 |
|
| 5 |
env: |
| 6 |
# * style job configuration |
| 7 |
STYLE_FAIL_ON_FAULT: true ## (bool) fail the build if a style job contains a fault (error or warning); may be overridden on a per-job basis |
| 8 |
|
| 9 |
on: |
| 10 |
pull_request: |
| 11 |
push: |
| 12 |
branches: |
| 13 |
- '*' |
| 14 |
|
| 15 |
permissions: |
| 16 |
contents: read # to fetch code (actions/checkout) |
| 17 |
|
| 18 |
# End the current execution if there is a new changeset in the PR. |
| 19 |
concurrency: |
| 20 |
group: ${{ github.workflow }}-${{ github.ref }} |
| 21 |
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 22 |
|
| 23 |
jobs: |
| 24 |
style: |
| 25 |
name: Style and Lint |
| 26 |
runs-on: ${{ matrix.job.os }} |
| 27 |
timeout-minutes: 45 |
| 28 |
strategy: |
| 29 |
fail-fast: false |
| 30 |
matrix: |
| 31 |
job: |
| 32 |
- { os: ubuntu-24.04 , features: unix } |
| 33 |
steps: |
| 34 |
- uses: actions/[email protected] |
| 35 |
with: |
| 36 |
persist-credentials: false |
| 37 |
- name: Prepare, build and test |
| 38 |
uses: vmactions/[email protected] |
| 39 |
with: |
| 40 |
usesh: true |
| 41 |
sync: rsync |
| 42 |
copyback: false |
| 43 |
# We need jq and GNU coreutils to run show-utils.sh and bash to use inline shell string replacement |
| 44 |
prepare: pkg install -y curl sudo jaq coreutils bash python3 |
| 45 |
run: | |
| 46 |
## Prepare, build, and test |
| 47 |
sudo ln -s $(command -v jaq) /usr/local/bin/jq |
| 48 |
# implementation modelled after ref: <https://github.com/rust-lang/rustup/pull/2783> |
| 49 |
# * NOTE: All steps need to be run in this block, otherwise, we are operating back on the mac host |
| 50 |
set -e |
| 51 |
# |
| 52 |
TEST_USER=tester |
| 53 |
REPO_NAME=${GITHUB_WORKSPACE##*/} |
| 54 |
WORKSPACE_PARENT="/home/runner/work/${REPO_NAME}" |
| 55 |
WORKSPACE="${WORKSPACE_PARENT}/${REPO_NAME}" |
| 56 |
# |
| 57 |
pw adduser -n ${TEST_USER} -d /root/ -g wheel -c "Coreutils user to build" -w random |
| 58 |
chown -R ${TEST_USER}:wheel /root/ "${WORKSPACE_PARENT}"/ |
| 59 |
whoami |
| 60 |
# |
| 61 |
# Further work needs to be done in a sudo as we are changing users |
| 62 |
sudo -i -u ${TEST_USER} bash << EOF |
| 63 |
set -e |
| 64 |
whoami |
| 65 |
curl https://sh.rustup.rs -sSf --output rustup.sh |
| 66 |
sh rustup.sh -y -c rustfmt,clippy --profile=minimal -t stable |
| 67 |
. ${HOME}/.cargo/env |
| 68 |
## VARs setup |
| 69 |
cd "${WORKSPACE}" |
| 70 |
unset FAIL_ON_FAULT ; case '${{ env.STYLE_FAIL_ON_FAULT }}' in |
| 71 |
''|0|f|false|n|no|off) FAULT_TYPE=warning ;; |
| 72 |
*) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;; |
| 73 |
esac; |
| 74 |
FAULT_PREFIX=\$(echo "\${FAULT_TYPE}" | tr '[:lower:]' '[:upper:]') |
| 75 |
# * determine sub-crate utility list |
| 76 |
UTILITY_LIST="\$(./util/show-utils.sh --features ${{ matrix.job.features }})" |
| 77 |
## Info |
| 78 |
# environment |
| 79 |
echo "## environment" |
| 80 |
echo "CI='${CI}'" |
| 81 |
echo "REPO_NAME='${REPO_NAME}'" |
| 82 |
echo "TEST_USER='${TEST_USER}'" |
| 83 |
echo "WORKSPACE_PARENT='${WORKSPACE_PARENT}'" |
| 84 |
echo "WORKSPACE='${WORKSPACE}'" |
| 85 |
echo "FAULT_PREFIX='\${FAULT_PREFIX}'" |
| 86 |
echo "UTILITY_LIST='\${UTILITY_LIST}'" |
| 87 |
env | sort |
| 88 |
# tooling info |
| 89 |
echo "## tooling info" |
| 90 |
cargo -V |
| 91 |
rustc -V |
| 92 |
# |
| 93 |
# To ensure that files are cleaned up, we don't want to exit on error |
| 94 |
set +e |
| 95 |
unset FAULT |
| 96 |
export CARGO_INCREMENTAL=0 |
| 97 |
## cargo fmt testing |
| 98 |
echo "## cargo fmt testing" |
| 99 |
# * convert any errors/warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message> |
| 100 |
S=\$(cargo fmt -- --check) && printf "%s\n" "\$S" || { printf "%s\n" "\$S" ; printf "%s\n" "\$S" | sed -E -n -e "s/^Diff[[:space:]]+in[[:space:]]+\${PWD//\//\\\\/}\/(.*)[[:space:]]+at[[:space:]]+[^0-9]+([0-9]+).*\$/::\${FAULT_TYPE} file=\1,line=\2::\${FAULT_PREFIX}: \\\`cargo fmt\\\`: style violation (file:'\1', line:\2; use \\\`cargo fmt -- \"\1\"\\\`)/p" ; FAULT=true ; } |
| 101 |
## cargo clippy lint testing |
| 102 |
if [ -z "\${FAULT}" ]; then |
| 103 |
echo "## cargo clippy lint testing" |
| 104 |
CLIPPY_ARGS="--features ${{ matrix.job.features }} --fault-type \${FAULT_TYPE}" |
| 105 |
if [ -n "\${FAIL_ON_FAULT}" ]; then CLIPPY_ARGS="\${CLIPPY_ARGS} --fail-on-fault"; fi |
| 106 |
python3 util/run-clippy.py \${CLIPPY_ARGS} || FAULT=true |
| 107 |
fi |
| 108 |
# Clean to avoid to rsync back the files |
| 109 |
cargo clean |
| 110 |
if [ -n "\${FAIL_ON_FAULT}" ] && [ -n "\${FAULT}" ]; then exit 1 ; fi |
| 111 |
EOF |
| 112 |
|
| 113 |
test: |
| 114 |
name: Tests |
| 115 |
runs-on: ${{ matrix.job.os }} |
| 116 |
timeout-minutes: 45 |
| 117 |
strategy: |
| 118 |
fail-fast: false |
| 119 |
matrix: |
| 120 |
job: |
| 121 |
- { os: ubuntu-24.04 , features: unix } |
| 122 |
env: |
| 123 |
mem: 4096 |
| 124 |
steps: |
| 125 |
- uses: actions/[email protected] |
| 126 |
with: |
| 127 |
persist-credentials: false |
| 128 |
- name: Avoid no space left on device (Ubuntu runner) |
| 129 |
shell: bash |
| 130 |
run: sudo rm -rf /usr/share/dotnet /usr/local/lib/android & |
| 131 |
- name: Prepare, build and test |
| 132 |
uses: vmactions/[email protected] |
| 133 |
with: |
| 134 |
usesh: true |
| 135 |
sync: rsync |
| 136 |
copyback: false |
| 137 |
prepare: pkg install -y curl gmake sudo jaq |
| 138 |
run: | |
| 139 |
## Prepare, build, and test |
| 140 |
sudo ln -s $(command -v jaq) /usr/local/bin/jq |
| 141 |
# implementation modelled after ref: <https://github.com/rust-lang/rustup/pull/2783> |
| 142 |
# * NOTE: All steps need to be run in this block, otherwise, we are operating back on the mac host |
| 143 |
set -e |
| 144 |
# |
| 145 |
# We need a file-descriptor file system to test test_ls::test_ls_io_errors |
| 146 |
mount -t fdescfs fdesc /dev/fd |
| 147 |
# |
| 148 |
TEST_USER=tester |
| 149 |
REPO_NAME=${GITHUB_WORKSPACE##*/} |
| 150 |
WORKSPACE_PARENT="/home/runner/work/${REPO_NAME}" |
| 151 |
WORKSPACE="${WORKSPACE_PARENT}/${REPO_NAME}" |
| 152 |
# |
| 153 |
pw adduser -n ${TEST_USER} -d /root/ -g wheel -c "Coreutils user to build" -w random |
| 154 |
chown -R ${TEST_USER}:wheel /root/ "${WORKSPACE_PARENT}"/ |
| 155 |
whoami |
| 156 |
# |
| 157 |
# Further work needs to be done in a sudo as we are changing users |
| 158 |
sudo -i -u ${TEST_USER} sh << EOF |
| 159 |
set -e |
| 160 |
whoami |
| 161 |
curl https://sh.rustup.rs -sSf --output rustup.sh |
| 162 |
sh rustup.sh -y --profile=minimal |
| 163 |
. $HOME/.cargo/env |
| 164 |
# Install nextest |
| 165 |
mkdir -p ~/.cargo/bin |
| 166 |
curl -LsSf https://get.nexte.st/latest/freebsd | tar zxf - -C ~/.cargo/bin |
| 167 |
## Info |
| 168 |
# environment |
| 169 |
echo "## environment" |
| 170 |
echo "CI='${CI}'" |
| 171 |
echo "REPO_NAME='${REPO_NAME}'" |
| 172 |
echo "TEST_USER='${TEST_USER}'" |
| 173 |
echo "WORKSPACE_PARENT='${WORKSPACE_PARENT}'" |
| 174 |
echo "WORKSPACE='${WORKSPACE}'" |
| 175 |
env | sort |
| 176 |
# tooling info |
| 177 |
echo "## tooling info" |
| 178 |
cargo -V |
| 179 |
cargo nextest --version |
| 180 |
rustc -V |
| 181 |
# |
| 182 |
# To ensure that files are cleaned up, we don't want to exit on error |
| 183 |
set +e |
| 184 |
cd "${WORKSPACE}" |
| 185 |
unset FAULT |
| 186 |
export CARGO_INCREMENTAL=0 |
| 187 |
export RUSTFLAGS="-C strip=symbols" # for disk space |
| 188 |
cargo build || FAULT=1 |
| 189 |
export PATH=~/.cargo/bin:${PATH} |
| 190 |
export RUST_BACKTRACE=1 |
| 191 |
export CARGO_TERM_COLOR=always |
| 192 |
if (test -z "\$FAULT"); then cargo nextest run --hide-progress-bar --profile ci --features '${{ matrix.job.features }}' || FAULT=1 ; fi |
| 193 |
# There is no systemd-logind on FreeBSD, so test all features except feat_systemd_logind ( https://github.com/rust-lang/cargo/issues/3126#issuecomment-2523441905 ) |
| 194 |
if (test -z "\$FAULT"); then |
| 195 |
UUCORE_FEATURES=\$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "uucore") | .features | keys | .[]' | grep -v "feat_systemd_logind" | paste -s -d "," -) |
| 196 |
cargo nextest run --hide-progress-bar --profile ci --features "\$UUCORE_FEATURES" -p uucore || FAULT=1 |
| 197 |
fi |
| 198 |
# Test building with make |
| 199 |
if (test -z "\$FAULT"); then make || FAULT=1 ; fi |
| 200 |
# Clean to avoid to rsync back the files |
| 201 |
cargo clean |
| 202 |
if (test -n "\$FAULT"); then exit 1 ; fi |
| 203 |
EOF |