github-ci: error on any shell errors
authorAlois Klink <alois@aloisklink.com>
Wed, 23 Nov 2022 18:37:01 +0000 (18:37 +0000)
committerJosef Schlehofer <pepe.schlehofer@gmail.com>
Mon, 23 Oct 2023 15:00:24 +0000 (17:00 +0200)
Enable `errexit` and `nounset` [POSIX shell options][1]
in `.github/workflows/entrypoint.sh` so that the script fails
if any command within the script fails.

[1]: https://pubs.opengroup.org/onlinepubs/9699919799//utilities/V3_chap02.html#set

Reported-by: Marius Dinu <m95d+git@psihoexpert.ro>
Fixes: https://github.com/openwrt/packages/issues/19953
Signed-off-by: Alois Klink <alois@aloisklink.com>
(cherry picked from commit 03ca0722f73c8121521ff59ca9a4ad6358b6a262)

.github/workflows/entrypoint.sh

index d7d4ecd0eb542ae43306aec1b32eaeb84ee0ee7b..b88a6c10cf97469667a21be09e1c74d732f6344e 100755 (executable)
@@ -1,10 +1,14 @@
 #!/bin/sh
 
+# not enabling `errtrace` and `pipefail` since those are bash specific
+set -o errexit # failing commands causes script to fail
+set -o nounset # undefined variables causes script to fail 
+
 mkdir -p /var/lock/
 
 opkg update
 
-[ -n "$CI_HELPER" ] || CI_HELPER="/ci/.github/workflows/ci_helpers.sh"
+[ -n "${CI_HELPER:=''}" ] || CI_HELPER="/ci/.github/workflows/ci_helpers.sh"
 
 for PKG in /ci/*.ipk; do
        tar -xzOf "$PKG" ./control.tar.gz | tar xzf - ./control