|
| 1 | +name: OpenBSD |
| 2 | + |
| 3 | +# spell-checker:ignore sshfs usesh vmactions taiki Swatinem esac fdescfs fdesc sccache 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: ubuntu-latest |
| 27 | + timeout-minutes: 60 |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + job: |
| 32 | + - { features: unix } |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v5 |
| 35 | + with: |
| 36 | + persist-credentials: false |
| 37 | + - name: Prepare, build and test |
| 38 | + uses: vmactions/openbsd-vm@v1 |
| 39 | + with: |
| 40 | + usesh: true |
| 41 | + sync: rsync |
| 42 | + copyback: false |
| 43 | + mem: 4096 |
| 44 | + # We need jq and GNU coreutils to run show-utils.sh and bash to use inline shell string replacement |
| 45 | + # Use sudo-- to get the default sudo package without ambiguity |
| 46 | + # Install rust and cargo from OpenBSD packages |
| 47 | + prepare: pkg_add curl sudo-- jq coreutils bash rust rust-clippy rust-rustfmt |
| 48 | + run: | |
| 49 | + ## Prepare, build, and test |
| 50 | + # implementation modelled after ref: <https://github.com/rust-lang/rustup/pull/2783> |
| 51 | + # * NOTE: All steps need to be run in this block, otherwise, we are operating back on the mac host |
| 52 | + set -e |
| 53 | + # |
| 54 | + TEST_USER=tester |
| 55 | + REPO_NAME=${GITHUB_WORKSPACE##*/} |
| 56 | + WORKSPACE_PARENT="/home/runner/work/${REPO_NAME}" |
| 57 | + WORKSPACE="${WORKSPACE_PARENT}/${REPO_NAME}" |
| 58 | + # |
| 59 | + useradd -m -G wheel ${TEST_USER} |
| 60 | + chown -R ${TEST_USER}:wheel /root/ "${WORKSPACE_PARENT}"/ |
| 61 | + whoami |
| 62 | + # |
| 63 | + # Further work needs to be done in a sudo as we are changing users |
| 64 | + sudo -i -u ${TEST_USER} bash << EOF |
| 65 | + set -e |
| 66 | + whoami |
| 67 | + # Rust is installed from packages, no need for rustup |
| 68 | + # Set up PATH for cargo |
| 69 | + export PATH="/usr/local/bin:$PATH" |
| 70 | + ## VARs setup |
| 71 | + cd "${WORKSPACE}" |
| 72 | + unset FAIL_ON_FAULT ; case '${{ env.STYLE_FAIL_ON_FAULT }}' in |
| 73 | + ''|0|f|false|n|no|off) FAULT_TYPE=warning ;; |
| 74 | + *) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;; |
| 75 | + esac; |
| 76 | + FAULT_PREFIX=\$(echo "\${FAULT_TYPE}" | tr '[:lower:]' '[:upper:]') |
| 77 | + # * determine sub-crate utility list |
| 78 | + UTILITY_LIST="\$(./util/show-utils.sh --features ${{ matrix.job.features }})" |
| 79 | + CARGO_UTILITY_LIST_OPTIONS="\$(for u in \${UTILITY_LIST}; do echo -n "-puu_\${u} "; done;)" |
| 80 | + ## Info |
| 81 | + # environment |
| 82 | + echo "## environment" |
| 83 | + echo "CI='${CI}'" |
| 84 | + echo "REPO_NAME='${REPO_NAME}'" |
| 85 | + echo "TEST_USER='${TEST_USER}'" |
| 86 | + echo "WORKSPACE_PARENT='${WORKSPACE_PARENT}'" |
| 87 | + echo "WORKSPACE='${WORKSPACE}'" |
| 88 | + echo "FAULT_PREFIX='\${FAULT_PREFIX}'" |
| 89 | + echo "UTILITY_LIST='\${UTILITY_LIST}'" |
| 90 | + env | sort |
| 91 | + # tooling info |
| 92 | + echo "## tooling info" |
| 93 | + cargo -V |
| 94 | + rustc -V |
| 95 | + # |
| 96 | + # To ensure that files are cleaned up, we don't want to exit on error |
| 97 | + set +e |
| 98 | + unset FAULT |
| 99 | + ## cargo fmt testing |
| 100 | + echo "## cargo fmt testing" |
| 101 | + # * 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> |
| 102 | + 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 ; } |
| 103 | + ## cargo clippy lint testing |
| 104 | + if [ -z "\${FAULT}" ]; then |
| 105 | + echo "## cargo clippy lint testing" |
| 106 | + # * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message> |
| 107 | + S=\$(cargo clippy --all-targets \${CARGO_UTILITY_LIST_OPTIONS} -- -D warnings 2>&1) && printf "%s\n" "\$S" || { printf "%s\n" "\$S" ; printf "%s" "\$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*\$/::\${FAULT_TYPE} file=\2,line=\3,col=\4::\${FAULT_PREFIX}: \\\`cargo clippy\\\`: \1 (file:'\2', line:\3)/p;" -e '}' ; FAULT=true ; } |
| 108 | + fi |
| 109 | + # Clean to avoid to rsync back the files |
| 110 | + cargo clean |
| 111 | + if [ -n "\${FAIL_ON_FAULT}" ] && [ -n "\${FAULT}" ]; then exit 1 ; fi |
| 112 | + EOF |
| 113 | +
|
| 114 | + test: |
| 115 | + name: Tests |
| 116 | + runs-on: ubuntu-latest |
| 117 | + timeout-minutes: 60 |
| 118 | + strategy: |
| 119 | + fail-fast: false |
| 120 | + matrix: |
| 121 | + job: |
| 122 | + - { features: unix } |
| 123 | + steps: |
| 124 | + - uses: actions/checkout@v5 |
| 125 | + with: |
| 126 | + persist-credentials: false |
| 127 | + - name: Prepare, build and test |
| 128 | + uses: vmactions/openbsd-vm@v1 |
| 129 | + with: |
| 130 | + usesh: true |
| 131 | + sync: rsync |
| 132 | + copyback: false |
| 133 | + mem: 4096 |
| 134 | + # Install rust and build dependencies from OpenBSD packages |
| 135 | + prepare: pkg_add curl gmake sudo-- jq rust |
| 136 | + run: | |
| 137 | + ## Prepare, build, and test |
| 138 | + # implementation modelled after ref: <https://github.com/rust-lang/rustup/pull/2783> |
| 139 | + # * NOTE: All steps need to be run in this block, otherwise, we are operating back on the mac host |
| 140 | + set -e |
| 141 | + # |
| 142 | + TEST_USER=tester |
| 143 | + REPO_NAME=${GITHUB_WORKSPACE##*/} |
| 144 | + WORKSPACE_PARENT="/home/runner/work/${REPO_NAME}" |
| 145 | + WORKSPACE="${WORKSPACE_PARENT}/${REPO_NAME}" |
| 146 | + # |
| 147 | + useradd -m -G wheel ${TEST_USER} |
| 148 | + chown -R ${TEST_USER}:wheel /root/ "${WORKSPACE_PARENT}"/ |
| 149 | + whoami |
| 150 | + # |
| 151 | + # Further work needs to be done in a sudo as we are changing users |
| 152 | + sudo -i -u ${TEST_USER} sh << EOF |
| 153 | + set -e |
| 154 | + whoami |
| 155 | + # Rust is installed from packages, no need for rustup |
| 156 | + # Set up PATH for cargo |
| 157 | + export PATH="/usr/local/bin:$PATH" |
| 158 | + # Install nextest |
| 159 | + mkdir -p ~/.cargo/bin |
| 160 | + # Note: nextest might not have OpenBSD builds, so we'll use regular cargo test |
| 161 | + ## Info |
| 162 | + # environment |
| 163 | + echo "## environment" |
| 164 | + echo "CI='${CI}'" |
| 165 | + echo "REPO_NAME='${REPO_NAME}'" |
| 166 | + echo "TEST_USER='${TEST_USER}'" |
| 167 | + echo "WORKSPACE_PARENT='${WORKSPACE_PARENT}'" |
| 168 | + echo "WORKSPACE='${WORKSPACE}'" |
| 169 | + env | sort |
| 170 | + # tooling info |
| 171 | + echo "## tooling info" |
| 172 | + cargo -V |
| 173 | + rustc -V |
| 174 | + # |
| 175 | + # To ensure that files are cleaned up, we don't want to exit on error |
| 176 | + set +e |
| 177 | + cd "${WORKSPACE}" |
| 178 | + unset FAULT |
| 179 | + cargo build || FAULT=1 |
| 180 | + export PATH=~/.cargo/bin:${PATH} |
| 181 | + export RUST_BACKTRACE=1 |
| 182 | + export CARGO_TERM_COLOR=always |
| 183 | + # Use cargo test since nextest might not support OpenBSD |
| 184 | + if (test -z "\$FAULT"); then cargo test --features '${{ matrix.job.features }}' || FAULT=1 ; fi |
| 185 | + # There is no systemd-logind on OpenBSD, so test all features except feat_systemd_logind |
| 186 | + if (test -z "\$FAULT"); then |
| 187 | + 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 "," -) |
| 188 | + cargo test --features "\$UUCORE_FEATURES" -p uucore || FAULT=1 |
| 189 | + fi |
| 190 | + # Test building with make |
| 191 | + if (test -z "\$FAULT"); then make PROFILE=ci || FAULT=1 ; fi |
| 192 | + # Clean to avoid to rsync back the files |
| 193 | + cargo clean |
| 194 | + if (test -n "\$FAULT"); then exit 1 ; fi |
| 195 | + EOF |
0 commit comments