Skip to content

[GitHub Actions] Fail fast from the default shells (bash/sh) in Linux/macOS #23853

@iamazeem

Description

@iamazeem

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions

What part(s) of the article would you like to see updated?

The jobs.<job_id>.steps[*].shell lists the default shell commands for Linux/macOS under Command run internally column:

shell command
unspecified bash -e {0}
bash bash --noprofile --norc -eo pipefail {0}
sh sh -e {0}

Screenshot of a test run from ubuntu-latest/ubuntu-22.04 runner:

image

All these variants have -e and according to its description under The Set Builtin section form the Bash manual:

-e: Exit immediately if a pipeline (see Pipelines), which may consist of a single simple command (see Simple Commands), a list (see Lists of Commands), or a compound command (see Compound Commands) returns a non-zero status.

Which is equivalent to the fail fast behavior.

But, according to the Exit codes and error action preference:

bash/sh: Fail-fast behavior using set -eo pipefail: This option is set when shell: bash is explicitly specified. It is not applied by default.

And, that is not the case. This only applies to the -o pipefail part (Bash only) because -e is applied by default.

The -o pipeline only affects the returning of the exit status from Pipelines in Bash:

pipefail: If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully.

The docs should be revised to avoid contradiction when both these sections are read in conjunction.

  • -e is applied by default to sh and bash both.
  • -o pipefail is applied to bash only (i.e. bash -e -o pipefail) when shell: bash is specified; and, not to shell: sh.
  • sh command should also have pipefail but at the moment it doesn't. Also, it has a different syntax i.e. sh -e -pipefail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    actionsThis issue or pull request should be reviewed by the docs actions teamcontentThis issue or pull request belongs to the Docs Content teamhelp wantedAnyone is welcome to open a pull request to fix this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions