From c1360067e917c374cf62e384e6839a6ac70c407a Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 30 Sep 2022 11:56:12 +1000 Subject: [PATCH] Enable formatting in CI Enable formatting in CI by doing: - Add a section to the `test.sh` scripts to run the formatter (guarded by the env variable `DO_FMT`) for all crates (bitcoin, hashes, internals). - Add `DO_FMT` to the nightly `Tests` CI job. --- .github/workflows/rust.yml | 1 + bitcoin/contrib/test.sh | 10 ++++++++++ hashes/contrib/test.sh | 10 ++++++++++ internals/contrib/test.sh | 10 ++++++++++ 4 files changed, 31 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 067ee137..8d8a978b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -53,6 +53,7 @@ jobs: uses: dtolnay/rust-toolchain@nightly - name: Running test script env: + DO_FMT: true DO_BENCH: true AS_DEPENDENCY: false DO_NO_STD: true diff --git a/bitcoin/contrib/test.sh b/bitcoin/contrib/test.sh index 3d91bd20..adcd1c70 100755 --- a/bitcoin/contrib/test.sh +++ b/bitcoin/contrib/test.sh @@ -111,6 +111,16 @@ then ) fi +# Run formatter if told to. +if [ "$DO_FMT" = true ]; then + if [ "$NIGHTLY" = false ]; then + echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)" + exit 1 + fi + rustup component add rustfmt + cargo fmt --check +fi + # Bench if told to, only works with non-stable toolchain (nightly, beta). if [ "$DO_BENCH" = true ] then diff --git a/hashes/contrib/test.sh b/hashes/contrib/test.sh index 4bea1767..466644a0 100755 --- a/hashes/contrib/test.sh +++ b/hashes/contrib/test.sh @@ -89,6 +89,16 @@ if [ "$DO_ASAN" = true ]; then cargo test --lib --no-default-features --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu fi +# Run formatter if told to. +if [ "$DO_FMT" = true ]; then + if [ "$NIGHTLY" = false ]; then + echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)" + exit 1 + fi + rustup component add rustfmt + cargo fmt --check +fi + # Bench if told to, only works with non-stable toolchain (nightly, beta). if [ "$DO_BENCH" = true ] then diff --git a/internals/contrib/test.sh b/internals/contrib/test.sh index f83302f7..13f2d3d8 100755 --- a/internals/contrib/test.sh +++ b/internals/contrib/test.sh @@ -52,3 +52,13 @@ fi if [ "$DO_DOCS" = true ]; then RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features fi + +# Run formatter if told to. +if [ "$DO_FMT" = true ]; then + if [ "$NIGHTLY" = false ]; then + echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)" + exit 1 + fi + rustup component add rustfmt + cargo fmt --check +fi