|
| 1 | +# workflows/lint-bash.yml |
| 2 | +# |
| 3 | +# Lint Bash |
| 4 | +# Lint and enforce good practices for Bash scripts. |
| 5 | + |
| 6 | +name: Lint Bash |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request: |
| 10 | + types: [opened, synchronize, reopened, ready_for_review] |
| 11 | + paths: |
| 12 | + - "**/*.sh" |
| 13 | + - ".github/workflows/lint-bash.yml" |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: lint-bash-${{ github.head_ref || github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + lint-bash: |
| 22 | + name: Lint Bash Scripts |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout Git Repository |
| 27 | + uses: actions/checkout@v6 |
| 28 | + |
| 29 | + - name: Set up Python Environment |
| 30 | + uses: actions/setup-python@v6 |
| 31 | + with: |
| 32 | + python-version: "3.11" |
| 33 | + |
| 34 | + - name: Install Bash Linters |
| 35 | + run: | |
| 36 | + pip install beautysh |
| 37 | + sudo apt-get update |
| 38 | + sudo apt-get install -y shellcheck |
| 39 | +
|
| 40 | + - name: Run Beautysh |
| 41 | + run: | |
| 42 | + shopt -s globstar nullglob |
| 43 | + if compgen -G "**/*.sh" > /dev/null; then |
| 44 | + beautysh **/*.sh --indent-size 2 --check |
| 45 | + fi |
| 46 | + shopt -u globstar nullglob |
| 47 | +
|
| 48 | + - name: Check Bash Script Shebang |
| 49 | + run: | |
| 50 | + while IFS= read -r -d '' file; do |
| 51 | + if head -n 1 "$file" | grep -Eq '^#!/usr/bin/env bash$|^#!/bin/bash$'; then |
| 52 | + echo "[bash shebang -> Present] $file" |
| 53 | + else |
| 54 | + echo "[bash shebang -> NOT FOUND] $file" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + done < <(find . -name '*.sh' -print0) |
| 58 | +
|
| 59 | + - name: Check Bash Scripts for Pipefail |
| 60 | + run: | |
| 61 | + while IFS= read -r -d '' file; do |
| 62 | + if grep -q \ |
| 63 | + -e "^[[:space:]]*set -euo pipefail$" \ |
| 64 | + -e "^[[:space:]]*set -Eeuo pipefail$" \ |
| 65 | + -e "^[[:space:]]*# @paradedb-skip-check-pipefail$" \ |
| 66 | + "$file"; then |
| 67 | + echo "[pipefail -> Present] $file" |
| 68 | + else |
| 69 | + echo "[pipefail -> NOT FOUND] $file" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + done < <(find . -name '*.sh' -print0) |
| 73 | +
|
| 74 | + - name: Run ShellCheck |
| 75 | + run: | |
| 76 | + while IFS= read -r -d '' file; do |
| 77 | + shellcheck -x "$file" |
| 78 | + done < <(find . -name '*.sh' -print0) |
0 commit comments