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.
This commit is contained in:
Tobin C. Harding 2024-03-27 10:08:57 +11:00
parent 9df59639ce
commit 3fa3d37c21
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
6 changed files with 13 additions and 6 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -euo pipefail
# Generates the label configuration using crates in the repository. # Generates the label configuration using crates in the repository.
# The label configuration is appended to the labeler config file. # The label configuration is appended to the labeler config file.

View File

@ -3,7 +3,7 @@
# Check that we can publish crates in their current form if there are changes on top of the tip of # 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. # master that imply that we are about to do a release.
set -ex set -euox pipefail
main () { main () {
for crate in "internals" "hashes" "bitcoin"; do for crate in "internals" "hashes" "bitcoin"; do

View File

@ -1,6 +1,6 @@
#!/bin/env bash #!/bin/env bash
set -ex set -euox pipefail
# Make all cargo invocations verbose. # Make all cargo invocations verbose.
export CARGO_TERM_VERBOSE=true export CARGO_TERM_VERBOSE=true
@ -165,6 +165,10 @@ do_lint() {
# We should not have any duplicate dependencies. This catches mistakes made upgrading dependencies # 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). # in one crate and not in another (e.g. upgrade bitcoin_hashes in bitcoin but not in secp).
do_dup_deps() { 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=$( duplicate_dependencies=$(
# Only show the actual duplicated deps, not their reverse tree, then # Only show the actual duplicated deps, not their reverse tree, then
# whitelist the 'syn' crate which is duplicated but it's not our fault. # 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 cargo tree --target=all --all-features --duplicates
exit 1 exit 1
fi fi
set -o pipefail
} }
# Build the docs with a nightly toolchain, in unison with the function # Build the docs with a nightly toolchain, in unison with the function

View File

@ -5,7 +5,8 @@
# #
# For hfuzz options see https://github.com/google/honggfuzz/blob/master/docs/USAGE.md # 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) REPO_DIR=$(git rev-parse --show-toplevel)
# shellcheck source=./fuzz-util.sh # shellcheck source=./fuzz-util.sh
source "$REPO_DIR/fuzz/fuzz-util.sh" source "$REPO_DIR/fuzz/fuzz-util.sh"

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -ex set -euox pipefail
REPO_DIR=$(git rev-parse --show-toplevel) REPO_DIR=$(git rev-parse --show-toplevel)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -euo pipefail
REPO_DIR=$(git rev-parse --show-toplevel) REPO_DIR=$(git rev-parse --show-toplevel)