Skip to content

Commit

Permalink
Fix CI builds on Win and OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
jpikl committed Mar 3, 2024
1 parent d23748b commit 5da625c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
with:
components: clippy

- name: Install coreutils
uses: taiki-e/install-action@coreutils

- name: Install just
uses: taiki-e/install-action@just

Expand All @@ -69,9 +72,12 @@ jobs:
- name: Install toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install tarpaulin
- name: Install cargo-tarpaulin
uses: taiki-e/install-action@cargo-tarpaulin

- name: Install coreutils
uses: taiki-e/install-action@coreutils

- name: Install just
uses: taiki-e/install-action@just

Expand Down
19 changes: 10 additions & 9 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@default:
just --list --unsorted

# Development workflow (format, clippy, test, docs)
dev: format clippy test docs
# Development workflow (format, build, clippy, test, docs)
dev: format build clippy test docs

# Docs development workflow
dev-docs:
Expand All @@ -29,16 +29,17 @@ clippy:
test:
cargo test --package rew --tests --quiet

# Build
build:
cargo build --workspace --exclude fuzz

# Generate docs
docs:
cargo run --package xtask -- docs

# Build
build *ARGS:
cargo build {{ARGS}}

# Install release build to ~/.local/bin/
install: (build "--release")
install:
cargo build --release
mkdir -p ~/.local/bin/
cp target/release/rew ~/.local/bin/

Expand All @@ -58,8 +59,8 @@ fuzz:
coverage format:
cargo tarpaulin \
--packages rew \
--tests \
--engine llvm \
--force-clean \
--exclude-files 'tests/*' \
--exclude-files 'fuzz/*' \
--exclude-files 'xtask/*' \
Expand Down Expand Up @@ -88,4 +89,4 @@ setup:
else \
cargo binstall cargo-binstall; \
fi
cargo binstall mdbook cargo-watch cargo-tarpaulin cargo-fuzz
cargo binstall mdbook coreutils cargo-watch cargo-tarpaulin cargo-fuzz
37 changes: 34 additions & 3 deletions tests/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use assert_cmd::crate_name;
use assert_cmd::prelude::*;
use assert_cmd::Command;
use std::env;
use std::fmt::Write;
use std::process;
use std::sync::mpsc;
use std::sync::mpsc::RecvTimeoutError;
use std::thread;
use std::time::Duration;
use which::which;

#[macro_export]
macro_rules! command_test {
Expand Down Expand Up @@ -75,12 +77,41 @@ pub fn assert_command(name: &str, args: &[&str], stdin: impl Into<Vec<u8>>) -> A

pub fn assert_shell(template: &str, cmd: &str, stdin: impl Into<Vec<u8>>) -> Assert {
let bin = get_bin();
let sh = env::var_os("SHELL").unwrap_or("sh".into());
let sh_cmd = template

let mut sh_cmd = template
.replace("%bin%", &bin)
.replace("%cmd%", &format!("{bin} {cmd}"));

Command::new(sh)
// These will be "polyfilled" by uutils coreutils
let coreutils_all = ["seq", "md5sum", "head", "tail", "wc"];

let coreutils_used = coreutils_all
.iter()
.filter(|util| template.contains(*util))
.collect::<Vec<_>>();

if !coreutils_used.is_empty() {
if let Ok(coreutils) = which("coreutils") {
if let Some(coreutils) = coreutils.to_str() {
let aliases = coreutils_used
.iter()
.fold(String::new(), |mut output, util| {
write!(output, "{util}() {{ {coreutils} {util} \"$@\"; }}; ").unwrap();
output
});

sh_cmd = format!("{aliases}{sh_cmd}");
} else {
eprintln!("Could not convert uutils coreutils path {coreutils:?} to UTF-8, falling back to GNU coreutils!");
eprintln!("Test results might not be reproducible on non-Linux OS!");
}
} else {
eprintln!("Could not find uutils coreutils binary, falling back to GNU coreutils!");
eprintln!("Test results might not be reproducible on non-Linux OS!");
}
}

Command::new("sh")
.arg("-c")
.arg(sh_cmd)
.write_stdin(stdin)
Expand Down

0 comments on commit 5da625c

Please sign in to comment.