Debian Codegraph @

.github/workflows/openbsd.yml

raw
1 name: OpenBSD
2
3 # spell-checker:ignore sshfs usesh vmactions taiki 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/[email protected]
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: |
48 # Clean up disk space before installing packages
49 df -h
50 pkg_add curl sudo-- jq coreutils bash rust rust-clippy rust-rustfmt python3
51 rm -rf /usr/share/relink/* /usr/X11R6/* /usr/share/doc/* /usr/share/man/* &
52 # Clean up package cache after installation
53 pkg_delete -a &
54 df -h
55 run: |
56 ## Prepare, build, and test
57 # implementation modelled after ref: <https://github.com/rust-lang/rustup/pull/2783>
58 # * NOTE: All steps need to be run in this block, otherwise, we are operating back on the mac host
59 set -e
60 #
61 export CARGO_INCREMENTAL=0
62 TEST_USER=tester
63 REPO_NAME=${GITHUB_WORKSPACE##*/}
64 WORKSPACE_PARENT="/home/runner/work/${REPO_NAME}"
65 WORKSPACE="${WORKSPACE_PARENT}/${REPO_NAME}"
66 #
67 useradd -m -G wheel ${TEST_USER}
68 chown -R ${TEST_USER}:wheel /root/ "${WORKSPACE_PARENT}"/
69 whoami
70 #
71 # Further work needs to be done in a sudo as we are changing users
72 sudo -i -u ${TEST_USER} bash << EOF
73 set -e
74 whoami
75 # Rust is installed from packages, no need for rustup
76 # Set up PATH for cargo
77 export PATH="/usr/local/bin:$PATH"
78 ## VARs setup
79 cd "${WORKSPACE}"
80 unset FAIL_ON_FAULT ; case '${{ env.STYLE_FAIL_ON_FAULT }}' in
81 ''|0|f|false|n|no|off) FAULT_TYPE=warning ;;
82 *) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;;
83 esac;
84 FAULT_PREFIX=\$(echo "\${FAULT_TYPE}" | tr '[:lower:]' '[:upper:]')
85 # * determine sub-crate utility list
86 UTILITY_LIST="\$(./util/show-utils.sh --features ${{ matrix.job.features }})"
87 ## Info
88 echo "::group::environment"
89 echo "CI='${CI}'"
90 echo "REPO_NAME='${REPO_NAME}'"
91 echo "TEST_USER='${TEST_USER}'"
92 echo "WORKSPACE_PARENT='${WORKSPACE_PARENT}'"
93 echo "WORKSPACE='${WORKSPACE}'"
94 echo "FAULT_PREFIX='\${FAULT_PREFIX}'"
95 echo "UTILITY_LIST='\${UTILITY_LIST}'"
96 env | sort
97 echo "::endgroup::"
98 echo "::group::tooling info"
99 cargo -V
100 rustc -V
101 echo "::endgroup::"
102 #
103 # To ensure that files are cleaned up, we don't want to exit on error
104 set +e
105 unset FAULT
106 ## cargo fmt testing
107 echo "::group::cargo fmt"
108 # * 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>
109 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 ; }
110 echo "::endgroup::"
111 ## cargo clippy lint testing
112 if [ -z "\${FAULT}" ]; then
113 echo "::group::cargo clippy"
114 CLIPPY_ARGS="--features ${{ matrix.job.features }} --fault-type \${FAULT_TYPE}"
115 if [ -n "\${FAIL_ON_FAULT}" ]; then CLIPPY_ARGS="\${CLIPPY_ARGS} --fail-on-fault"; fi
116 python3 util/run-clippy.py \${CLIPPY_ARGS} || FAULT=true
117 echo "::endgroup::"
118 fi
119 # Clean to avoid to rsync back the files and free up disk space
120 cargo clean
121 if [ -n "\${FAIL_ON_FAULT}" ] && [ -n "\${FAULT}" ]; then exit 1 ; fi
122 EOF
123
124 test:
125 name: Tests
126 runs-on: ubuntu-latest
127 timeout-minutes: 60
128 strategy:
129 fail-fast: false
130 matrix:
131 job:
132 - { features: unix }
133 steps:
134 - uses: actions/[email protected]
135 with:
136 persist-credentials: false
137 - name: Avoid no space left on device # shared with guest?
138 shell: bash
139 run: |
140 mkdir /tmp/empty
141 sudo rsync -a --delete /tmp/empty/ /usr/lib/jvm/
142 sudo rsync -a --delete /tmp/empty/ /usr/share/dotnet/
143 sudo rsync -a --delete /tmp/empty/ /usr/local/lib/android/
144 - name: Prepare, build and test
145 uses: vmactions/openbsd-vm@v1
146 with:
147 usesh: true
148 sync: rsync
149 copyback: false
150 mem: 6144
151 # Install rust and build dependencies
152 prepare: |
153 # Clean up disk space before installing packages
154 df -h
155 mkdir -p empty
156 rsync -a --delete empty/ /usr/share/relink/
157 rsync -a --delete empty/ /usr/X11R6/
158 rsync -a --delete empty/ /usr/share/doc/
159 rsync -a --delete empty/ /usr/share/man/
160 pkg_add curl gmake sudo-- jq rust
161 # Clean up package cache after installation
162 pkg_delete -a
163 df -h
164 run: |
165 ## Prepare, build, and test
166 # implementation modelled after ref: <https://github.com/rust-lang/rustup/pull/2783>
167 # * NOTE: All steps need to be run in this block, otherwise, we are operating back on the mac host
168 set -e
169 #
170 export CARGO_INCREMENTAL=0
171 TEST_USER=tester
172 REPO_NAME=${GITHUB_WORKSPACE##*/}
173 WORKSPACE_PARENT="/home/runner/work/${REPO_NAME}"
174 WORKSPACE="${WORKSPACE_PARENT}/${REPO_NAME}"
175 #
176 useradd -m -G wheel ${TEST_USER}
177 chown -R ${TEST_USER}:wheel /root/ "${WORKSPACE_PARENT}"/
178 whoami
179 # Add fake host for reverse DNS lookup (needed for hostname test)
180 printf "10.0.2.15\topenbsd.my.domain openbsd\n" >> /etc/hosts
181 #
182 # Further work needs to be done in a sudo as we are changing users
183 sudo -i -u ${TEST_USER} sh << EOF
184 set -e
185 whoami
186 # Increase max open files (512 by default)
187 ulimit -n 1024
188 # Rust is installed from packages, no need for rustup
189 # Set up PATH for cargo
190 export PATH="/usr/local/bin:$PATH"
191 # Install nextest
192 mkdir -p ~/.cargo/bin
193 # Note: nextest might not have OpenBSD builds, so we'll use regular cargo test
194 ## Info
195 echo "::group::environment"
196 echo "CI='${CI}'"
197 echo "REPO_NAME='${REPO_NAME}'"
198 echo "TEST_USER='${TEST_USER}'"
199 echo "WORKSPACE_PARENT='${WORKSPACE_PARENT}'"
200 echo "WORKSPACE='${WORKSPACE}'"
201 env | sort
202 echo "::endgroup::"
203 echo "::group::tooling info"
204 cargo -V
205 rustc -V
206 echo "::endgroup::"
207 #
208 # To ensure that files are cleaned up, we don't want to exit on error
209 set +e
210 cd "${WORKSPACE}"
211 unset FAULT
212 # openbsd is very slow. Omit duplicated cargo build and do test only
213 export PATH=~/.cargo/bin:${PATH}
214 export RUST_BACKTRACE=1
215 export CARGO_TERM_COLOR=always
216 # Avoid filling disk space
217 export RUSTFLAGS="-C strip=symbols"
218 # Use cargo test since nextest might not support OpenBSD
219 if (test -z "\$FAULT"); then
220 echo "::group::cargo test (workspace)"
221 cargo test --features '${{ matrix.job.features }}' || FAULT=1
222 echo "::endgroup::"
223 fi
224 # There is no systemd-logind on OpenBSD, so test all features except feat_systemd_logind
225 if (test -z "\$FAULT"); then
226 echo "::group::cargo test (uucore)"
227 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 "," -)
228 cargo test --features "\$UUCORE_FEATURES" -p uucore || FAULT=1
229 echo "::endgroup::"
230 fi
231 # Test building with make
232 if (test -z "\$FAULT"); then
233 echo "::group::make MULTICALL=Y"
234 make MULTICALL=Y || FAULT=1
235 echo "::endgroup::"
236 fi
237 # Clean to avoid to rsync back the files and free up disk space
238 cargo clean
239 # Additional cleanup to free disk space
240 if (test -n "\$FAULT"); then exit 1 ; fi
241 EOF