Skip to content

Commit

Permalink
Add euox pipefail check for bash scripts (#266)
Browse files Browse the repository at this point in the history
* Add euox pipefail check
* Make the script panic in case of errors
* Fix linter issues

Signed-off-by: Andrew Nikitin <[email protected]>
  • Loading branch information
askolesov authored and Andrew Nikitin committed Feb 25, 2022
1 parent b3a6eee commit 3f396bb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/scripts/enshure_set_euox_pipefail.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Ensures that all bash scripts in the repository use `set -euox pipefail` or `set -euo pipefail` statement at the beginning.

set -euo pipefail

INVALID_FILES_FOUND=0

for BASH_SCRIPT in $(find . -type f -name "*.sh")
do
if ( ! grep -q "set -euo pipefail" "${BASH_SCRIPT}" ) && ( ! grep -q "set -euox pipefail" "${BASH_SCRIPT}" )
then
echo "${BASH_SCRIPT}"
INVALID_FILES_FOUND=1
fi
done

if [[ INVALID_FILES_FOUND -eq 1 ]]
then
echo ""
echo "The bash scripts above must include either 'set -euo pipefail' or 'set -euox pipefail."
exit 1
fi
2 changes: 2 additions & 0 deletions build-tools/build-deb.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -euox pipefail

if [ -n "$1" ]; then
PKG_NAME=$1
else
Expand Down
2 changes: 2 additions & 0 deletions build-tools/build-tar.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -euox pipefail

if [ -n "$1" ]; then
PKG_NAME=$1
else
Expand Down
2 changes: 2 additions & 0 deletions build-tools/common.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set -euox pipefail

BINARY_NAME=${PKG_NAME}d
PATH_TO_BIN=/home/runner/go/bin/${BINARY_NAME} # TODO: Must be parameters
TMP_DIR=usr/bin
Expand Down
3 changes: 3 additions & 0 deletions tests/networks/docker-compose-localnet/promote-validator.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

set -euox pipefail

sudo chown -R runner:docker ${NODE_CONFIGS_BASE}/client
cheqd-noded keys list --keyring-backend "test" --home ${NODE_CONFIGS_BASE}/client/.cheqdnode/

Expand Down

0 comments on commit 3f396bb

Please sign in to comment.