From bfa108be86c559c876022c389536613728ba59b8 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Fri, 23 Feb 2024 09:06:08 -0800 Subject: [PATCH] [githooks][pre-push] Run steps in parallel While we're here, add `-q` flags to all `cargo` invocations in scripts in the `ci` directory. On my 2020 M1 MacBook Air, this reduces the time to execute `./githooks/pre-push` from 3.9s to 1.4s. --- ci/check_all_toolchains_tested.sh | 2 +- ci/check_msrv.sh | 2 +- ci/check_readme.sh | 2 +- ci/check_versions.sh | 4 ++-- githooks/pre-push | 18 +++++++++++------- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ci/check_all_toolchains_tested.sh b/ci/check_all_toolchains_tested.sh index 2b28be40c5..053d87f59e 100755 --- a/ci/check_all_toolchains_tested.sh +++ b/ci/check_all_toolchains_tested.sh @@ -11,6 +11,6 @@ set -eo pipefail diff \ <(cat .github/workflows/ci.yml | yq '.jobs.build_test.strategy.matrix.toolchain | .[]' | \ sort -u | grep -v '^\(msrv\|stable\|nightly\)$') \ - <(cargo metadata --format-version 1 | \ + <(cargo metadata -q --format-version 1 | \ jq -r ".packages[] | select(.name == \"zerocopy\").metadata.\"build-rs\" | keys | .[]" | \ sort -u) diff --git a/ci/check_msrv.sh b/ci/check_msrv.sh index 6c60d531ac..76f4033345 100755 --- a/ci/check_msrv.sh +++ b/ci/check_msrv.sh @@ -3,7 +3,7 @@ set -eo pipefail # Usage: msrv function msrv { - cargo metadata --format-version 1 | jq -r ".packages[] | select(.name == \"$1\").rust_version" + cargo metadata -q --format-version 1 | jq -r ".packages[] | select(.name == \"$1\").rust_version" } ver_zerocopy=$(msrv zerocopy) diff --git a/ci/check_readme.sh b/ci/check_readme.sh index 8bb614acca..9cdabffab6 100755 --- a/ci/check_readme.sh +++ b/ci/check_readme.sh @@ -4,7 +4,7 @@ set -eo pipefail # Install again in case the installation failed during the # `generate_cache` step. We treat that step as best-effort and # suppress all errors from it. -cargo install cargo-readme --version 3.2.0 -q +cargo install -q cargo-readme --version 3.2.0 diff <(cargo -q run --manifest-path tools/Cargo.toml -p generate-readme) README.md exit $? diff --git a/ci/check_versions.sh b/ci/check_versions.sh index 36dd67f370..ea23c4ee53 100755 --- a/ci/check_versions.sh +++ b/ci/check_versions.sh @@ -3,7 +3,7 @@ set -eo pipefail # Usage: version function version { - cargo metadata --format-version 1 | jq -r ".packages[] | select(.name == \"$1\").version" + cargo metadata -q --format-version 1 | jq -r ".packages[] | select(.name == \"$1\").version" } ver_zerocopy=$(version zerocopy) @@ -13,7 +13,7 @@ ver_zerocopy_derive=$(version zerocopy-derive) function dependency-version { KIND="$1" TARGET="$2" - cargo metadata --format-version 1 \ + cargo metadata -q --format-version 1 \ | jq -r ".packages[] | select(.name == \"zerocopy\").dependencies[] | select((.name == \"zerocopy-derive\") and .kind == $KIND and .target == $TARGET).req" } diff --git a/githooks/pre-push b/githooks/pre-push index c34922d85b..50f14942c7 100755 --- a/githooks/pre-push +++ b/githooks/pre-push @@ -1,10 +1,14 @@ #!/usr/bin/env bash set -eo pipefail echo "Running pre-push git hook: $0" -# forego redirecting stdout to /dev/null on check_fmt.sh because the output -# from cargofmt is useful (and the good stuff is not delivered by stderr) -./ci/check_fmt.sh -./ci/check_job_dependencies.sh > /dev/null -./ci/check_msrv.sh > /dev/null -./ci/check_readme.sh > /dev/null -./ci/check_versions.sh > /dev/null +# Forego redirecting stdout to /dev/null on check_fmt.sh because the output from +# `cargo fmt` is useful (and the good stuff is not delivered by stderr). +# +# Background all jobs and wait for them so they can run in parallel. +./ci/check_fmt.sh & +./ci/check_job_dependencies.sh >/dev/null & +./ci/check_msrv.sh >/dev/null & +./ci/check_readme.sh >/dev/null & +./ci/check_versions.sh >/dev/null & + +wait