Files
TheRock/docs/development/style_guides/bash_style_guide.md
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

1.8 KiB

Bash style guide

Core principles

Warning

Bash is strongly discouraged for nontrivial usage in .yml GitHub Actions workflow files and script files.

Use Python scripts in most cases instead.

Writing and maintaining safe and portable scripts in Bash is significantly harder than it is in Python. When appropriate, we write Bash scripts following some of the guidelines at https://google.github.io/styleguide/shellguide.html.

Those sections are particularly noteworthy:

When to use Bash

Use Bash for:

  • Simple automation scripts with few conditionals
  • Wrapping existing command-line tools
  • Environment setup and configuration
  • Quick one-off tasks

Avoid Bash for:

  • Complex logic with loops and conditionals
  • Data processing and transformation
  • Anything that needs to be tested thoroughly
  • Cross-platform scripts (prefer Python)

Style guidelines

Setting bash modes

Scripts should generally set modes like

set -euo pipefail

Benefits:

  • Fail-fast: Exits immediately on errors
  • Safe variables: Treats undefined variables as errors
  • Pipeline safety: Fails if any command in a pipeline fails
  • Debuggability: With -x, shows exactly what commands are running

Explanation of each mode:

  • set -e Exits if any command has a non-zero exit status
  • set -u Treats undefined variables as errors
  • set -o pipefail Uses the return code of a failing command as the pipeline return code
  • set -x Prints commands to the terminal (useful for debugging and CI logging)

See https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 for an explanation of what each of these options does.