Skip to content

Commit

Permalink
ci: Use gnu-parallel if available (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf authored Sep 3, 2023
1 parent 45233cc commit 9413f9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
submodules: recursive
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: imagemagick cargo
packages: imagemagick cargo parallel
version: 1.0
- name: Install typos-cli from crates.io
uses: baptiste0928/cargo-install@v2
Expand Down
47 changes: 29 additions & 18 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ TYPST_BASE_URL="https://github.com/typst/typst/releases/download"
TYPST_ARCHIVE="typst-x86_64-unknown-linux-musl.tar.xz"

TYPST_ROOT="$(realpath "$DIR/..")"
export TYPST_ROOT
TEST_ROOT="$(realpath "$DIR/../tests")"
export TEST_ROOT

if hash magick 2>/dev/null; then
MAGICK_COMPARE="magick compare"
Expand All @@ -33,11 +35,13 @@ else
>&2 echo "Could not find 'magick' nor 'compare' binary. Make sure you have image magick installed and in your PATH."
exit 1
fi
export MAGICK_COMPARE

function typst_compile()
{
typst compile --root "$TYPST_ROOT" "${@}"
}
export -f typst_compile

function install_typst()
{
Expand Down Expand Up @@ -77,9 +81,13 @@ function img_compare()
{
$MAGICK_COMPARE -metric rmse "$1" "$2" null: 2>&1 | cut -d\ -f1
}
export -f img_compare

function update_test_ref()
{
if [[ "$1" == "$TEST_ROOT" ]]; then
return
fi
(
cd "$1"
local NAME
Expand All @@ -96,12 +104,16 @@ function update_test_ref()
cp "res.png" "ref.png"
)
}
export -f update_test_ref

TEST_FAIL=0
TEST_OK=0

function run_test()
{
if [[ "$1" == "$TEST_ROOT" ]]; then
return
fi
if (
cd "$1"
local NAME
Expand Down Expand Up @@ -129,37 +141,36 @@ function run_test()
TEST_FAIL=$((TEST_FAIL + 1))
fi
}
export -f run_test

echo "Typst: $(typst --version)"

while read -r test
do
if [[ "$test" == "$TEST_ROOT" ]]; then continue; fi
if ! hash parallel 2>/dev/null; then
function parallel() {
xargs -n 1 -I {} bash -c "$1"
}
fi

if [[ "$MODE" == "test" ]]; then
run_test "$test"
elif [[ "$MODE" == "update" ]]; then
update_test_ref "$test"
else
echo "Unknown mode '$MODE'"; exit 1
fi
done < <(find "$TEST_ROOT" -type d)
function tests() {
find "$TEST_ROOT" -type d
}
if [[ "$MODE" == "test" ]]; then
tests | parallel 'run_test {}'
elif [[ "$MODE" == "update" ]]; then
tests | parallel 'update_test_ref {}'
else
echo "Unknown mode '$MODE'"; exit 1
fi

# Optional tests
if hash typos 2>/dev/null; then
echo "[TEST] typos"
if typos --format brief --exclude "/deps/*"; then
echo "[ OK]"
else
echo "[FAIL]"
echo "[WARN]"
fi
else
echo "[SKIP] typos"
echo "[ ] You can install 'typos' via 'cargo install typos-cli'."
fi

echo "Passed: $TEST_OK"
echo "Failed: $TEST_FAIL"
if [[ $TEST_FAIL -gt 0 ]]; then
exit 1
fi

0 comments on commit 9413f9b

Please sign in to comment.