Skip to content

Commit 8d81e95

Browse files
authored
Merge pull request #9196 from sylvestre/ci-openbsd
github action: add openbsd in the ci
2 parents 404257d + f7ea9ac commit 8d81e95

File tree

3 files changed

+208
-13
lines changed

3 files changed

+208
-13
lines changed

.github/workflows/openbsd.yml

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
name: OpenBSD
2+
3+
# spell-checker:ignore sshfs usesh vmactions taiki Swatinem esac fdescfs fdesc sccache nextest copyback logind bindgen libclang
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 llvm--
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 (llvm provides libclang for bindgen)
135+
prepare: pkg_add curl gmake sudo-- jq rust llvm--
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

tests/by-util/test_cp.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static TEST_NONEXISTENT_FILE: &str = "nonexistent_file.txt";
6969
use uutests::util::compare_xattrs;
7070

7171
/// Assert that mode, ownership, and permissions of two metadata objects match.
72-
#[cfg(all(not(windows), not(target_os = "freebsd")))]
72+
#[cfg(all(not(windows), not(target_os = "freebsd"), not(target_os = "openbsd")))]
7373
macro_rules! assert_metadata_eq {
7474
($m1:expr, $m2:expr) => {{
7575
assert_eq!($m1.mode(), $m2.mode(), "mode is different");
@@ -1553,7 +1553,7 @@ fn test_cp_parents_with_permissions_copy_file() {
15531553
.arg(dir)
15541554
.succeeds();
15551555

1556-
#[cfg(all(unix, not(target_os = "freebsd")))]
1556+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
15571557
{
15581558
let p1_metadata = at.metadata("p1");
15591559
let p2_metadata = at.metadata("p1/p2");
@@ -1596,7 +1596,7 @@ fn test_cp_parents_with_permissions_copy_dir() {
15961596
.arg(dir1)
15971597
.succeeds();
15981598

1599-
#[cfg(all(unix, not(target_os = "freebsd")))]
1599+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
16001600
{
16011601
let p1_metadata = at.metadata("p1");
16021602
let p2_metadata = at.metadata("p1/p2");
@@ -1641,7 +1641,7 @@ fn test_cp_preserve_no_args() {
16411641
.arg("--preserve")
16421642
.succeeds();
16431643

1644-
#[cfg(all(unix, not(target_os = "freebsd")))]
1644+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
16451645
{
16461646
// Assert that the mode, ownership, and timestamps are preserved
16471647
// NOTICE: the ownership is not modified on the src file, because that requires root permissions
@@ -1669,7 +1669,7 @@ fn test_cp_preserve_no_args_before_opts() {
16691669
.arg(dst_file)
16701670
.succeeds();
16711671

1672-
#[cfg(all(unix, not(target_os = "freebsd")))]
1672+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
16731673
{
16741674
// Assert that the mode, ownership, and timestamps are preserved
16751675
// NOTICE: the ownership is not modified on the src file, because that requires root permissions
@@ -1695,7 +1695,7 @@ fn test_cp_preserve_all() {
16951695
// Copy
16961696
ucmd.arg(src_file).arg(dst_file).arg(argument).succeeds();
16971697

1698-
#[cfg(all(unix, not(target_os = "freebsd")))]
1698+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
16991699
{
17001700
// Assert that the mode, ownership, and timestamps are preserved
17011701
// NOTICE: the ownership is not modified on the src file, because that requires root permissions
@@ -3028,7 +3028,7 @@ fn test_copy_through_dangling_symlink_no_dereference_permissions() {
30283028
assert!(at.symlink_exists("d2"), "symlink wasn't created");
30293029

30303030
// `-p` means `--preserve=mode,ownership,timestamps`
3031-
#[cfg(all(unix, not(target_os = "freebsd")))]
3031+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
30323032
{
30333033
let metadata1 = at.symlink_metadata("dangle");
30343034
let metadata2 = at.symlink_metadata("d2");
@@ -3749,7 +3749,7 @@ fn test_preserve_hardlink_attributes_in_directory() {
37493749
//
37503750
// A hard link should have the same inode as the target file.
37513751
at.file_exists("dest/src/link");
3752-
#[cfg(all(unix, not(target_os = "freebsd")))]
3752+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
37533753
assert_eq!(
37543754
at.metadata("dest/src/f").ino(),
37553755
at.metadata("dest/src/link").ino()
@@ -3765,7 +3765,7 @@ fn test_hard_link_file() {
37653765
ucmd.args(&["-f", "--link", "src", "dest"])
37663766
.succeeds()
37673767
.no_output();
3768-
#[cfg(all(unix, not(target_os = "freebsd")))]
3768+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
37693769
assert_eq!(at.metadata("src").ino(), at.metadata("dest").ino());
37703770
}
37713771

@@ -4069,7 +4069,7 @@ fn test_cp_dest_no_permissions() {
40694069
}
40704070

40714071
#[test]
4072-
#[cfg(all(unix, not(target_os = "freebsd")))]
4072+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
40734073
fn test_cp_attributes_only() {
40744074
let (at, mut ucmd) = at_and_ucmd!();
40754075
let a = "file_a";
@@ -6537,7 +6537,7 @@ fn test_cp_preserve_selinux() {
65376537
selinux_perm_dest
65386538
);
65396539

6540-
#[cfg(all(unix, not(target_os = "freebsd")))]
6540+
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
65416541
{
65426542
// Assert that the mode, ownership, and timestamps are preserved
65436543
// NOTICE: the ownership is not modified on the src file, because that requires root permissions

tests/by-util/test_hostname.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fn test_hostname() {
1414
assert!(ls_default_res.stdout().len() >= ls_domain_res.stdout().len());
1515
}
1616

17-
// FixME: fails for "MacOS" => "failed to lookup address information"
18-
#[cfg(not(target_os = "macos"))]
17+
// FixME: fails for "MacOS" and "OpenBSD" => "failed to lookup address information"
18+
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
1919
#[test]
2020
fn test_hostname_ip() {
2121
let result = new_ucmd!().arg("-i").succeeds();

0 commit comments

Comments
 (0)