Skip to content

Use set -euxo pipefail in shell scripts (not checkResult $?) #329

@mmathieum

Description

@mmathieum

There are many many shell scripts in the project, but most of them are in this repo.

Currently we are using checkResult $? from commons.sh to check last command result when we want to make sure it passes.

It's better to use set -euxo pipefail at the beginning of bash files to avoid silent issues, especially when running on these scripts on CI.

GitHub Workflows/Actions already use set to fail early.

  • set -e option instructs bash to immediately exit if any command has a non-zero exit status.
  • set -o pipefail option prevents errors in a pipeline from being masked. If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline
  • set -x option enables a mode of the shell where all executed commands are printed to the terminal.
  • set -u option validate reference to any variable you haven't previously defined - with the exceptions of $* and $@ - is an error, and causes the program to immediately exit.

Tasks:

  • list all shell scripts
  • For each shell scripts
    • add set -euxo pipefail after #!/bin/bash
    • remove the checkResult $?
    • check it doesn't break current workflows (pay attention to diff or git diff --exit-code... and other commands that exits with 1 for expected results, not errors)

Links:

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions