Skip to content

Commit

Permalink
[githooks][pre-push] Run steps in parallel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshlf committed Feb 23, 2024
1 parent 022feb4 commit bfa108b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ci/check_all_toolchains_tested.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ci/check_msrv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -eo pipefail

# Usage: msrv <crate-name>
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)
Expand Down
2 changes: 1 addition & 1 deletion ci/check_readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
4 changes: 2 additions & 2 deletions ci/check_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -eo pipefail

# Usage: version <crate-name>
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)
Expand All @@ -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"
}

Expand Down
18 changes: 11 additions & 7 deletions githooks/pre-push
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bfa108b

Please sign in to comment.