From 3fa3d37c214830986f330624791b70cf1f9258d4 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 27 Mar 2024 10:08:57 +1100 Subject: [PATCH] Add set -euo pipefail Add `euo pipefail` to all non-trial shell scripts, note if `x` is already set we maintain it. Note we have a pipe in `run_task.sh` that relies on grep not finding anything i.e., failing, so we cannot use pipefail there. Disable it and re-enable it after the pipe. --- contrib/gen_label_config.sh | 2 +- contrib/release.sh | 2 +- contrib/run_task.sh | 8 +++++++- fuzz/cycle.sh | 3 ++- fuzz/fuzz.sh | 2 +- fuzz/generate-files.sh | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/contrib/gen_label_config.sh b/contrib/gen_label_config.sh index 066113e3..9ad7e626 100755 --- a/contrib/gen_label_config.sh +++ b/contrib/gen_label_config.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -euo pipefail # Generates the label configuration using crates in the repository. # The label configuration is appended to the labeler config file. diff --git a/contrib/release.sh b/contrib/release.sh index 0de3a5ee..558ba0fb 100755 --- a/contrib/release.sh +++ b/contrib/release.sh @@ -3,7 +3,7 @@ # Check that we can publish crates in their current form if there are changes on top of the tip of # master that imply that we are about to do a release. -set -ex +set -euox pipefail main () { for crate in "internals" "hashes" "bitcoin"; do diff --git a/contrib/run_task.sh b/contrib/run_task.sh index d99042f4..b3a80cc3 100755 --- a/contrib/run_task.sh +++ b/contrib/run_task.sh @@ -1,6 +1,6 @@ #!/bin/env bash -set -ex +set -euox pipefail # Make all cargo invocations verbose. export CARGO_TERM_VERBOSE=true @@ -165,6 +165,10 @@ do_lint() { # We should not have any duplicate dependencies. This catches mistakes made upgrading dependencies # in one crate and not in another (e.g. upgrade bitcoin_hashes in bitcoin but not in secp). do_dup_deps() { + # We can't use pipefail because these grep statements fail by design when there is no duplicate, + # the shell therefore won't pick up mistakes in your pipe - you are on your own. + set +o pipefail + duplicate_dependencies=$( # Only show the actual duplicated deps, not their reverse tree, then # whitelist the 'syn' crate which is duplicated but it's not our fault. @@ -182,6 +186,8 @@ do_dup_deps() { cargo tree --target=all --all-features --duplicates exit 1 fi + + set -o pipefail } # Build the docs with a nightly toolchain, in unison with the function diff --git a/fuzz/cycle.sh b/fuzz/cycle.sh index 7de15c82..b72c44da 100755 --- a/fuzz/cycle.sh +++ b/fuzz/cycle.sh @@ -5,7 +5,8 @@ # # For hfuzz options see https://github.com/google/honggfuzz/blob/master/docs/USAGE.md -set -e +set -euo pipefail + REPO_DIR=$(git rev-parse --show-toplevel) # shellcheck source=./fuzz-util.sh source "$REPO_DIR/fuzz/fuzz-util.sh" diff --git a/fuzz/fuzz.sh b/fuzz/fuzz.sh index 5fc65ae6..f420bd1b 100755 --- a/fuzz/fuzz.sh +++ b/fuzz/fuzz.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex +set -euox pipefail REPO_DIR=$(git rev-parse --show-toplevel) diff --git a/fuzz/generate-files.sh b/fuzz/generate-files.sh index 18cba6a8..bbb36ea4 100755 --- a/fuzz/generate-files.sh +++ b/fuzz/generate-files.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -euo pipefail REPO_DIR=$(git rev-parse --show-toplevel)