1657 allow the contributor to self assign the issue #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# workflows/lint-bash.yml | |
# | |
# Lint Bash | |
# Lint and enforce good practices for Bash scripts. | |
name: Lint Bash | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened, ready_for_review] | |
paths: | |
- "**/*.sh" | |
- ".github/workflows/lint-bash.yml" | |
workflow_dispatch: | |
concurrency: | |
group: lint-bash-${{ github.head_ref || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
lint-bash: | |
name: Lint Bash Scripts | |
runs-on: depot-ubuntu-latest-2 | |
if: github.event.pull_request.draft == false | |
steps: | |
- name: Checkout Git Repository | |
uses: actions/checkout@v4 | |
- name: Set up Python Environment | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install Beautysh | |
run: pip install beautysh | |
- name: Run Beautysh | |
run: | | |
shopt -s globstar nullglob | |
if compgen -G "**/*.sh" > /dev/null; then | |
beautysh **/*.sh --indent-size 2 --check | |
fi | |
shopt -u globstar nullglob | |
- name: Check Bash Scripts for "#!/bin/bash" | |
run: | | |
while read -r file | |
do | |
if [[ "$(head -c 11 "$file")" = "#!/bin/bash" ]] | |
then | |
echo "[#!/bin/bash -> Present] $file" | |
else | |
echo "[#!/bin/bash -> NOT FOUND] $file" && exit 1 | |
fi | |
done < <(find . -name '*.sh') | |
- name: Check Bash Scripts for "set -Eeuo pipefail" | |
run: | | |
while read -r file | |
do | |
if grep -q \ | |
-e "^set -Eeuo pipefail$" \ | |
-e "^# @paradedb-skip-check-pipefail$" \ | |
"$file" | |
then | |
echo "[set -Eeuo pipefail -> Present] $file" | |
else | |
echo "[set -Eeuo pipefail -> NOT FOUND] $file" && exit 1 | |
fi | |
done < <(find . -name '*.sh') | |
- name: Run ShellCheck | |
shell: python {0} | |
run: | | |
import argparse | |
import glob | |
import subprocess | |
import sys | |
sh_files = set(glob.glob("**/*.sh", recursive=True)) | |
for file in sh_files: | |
p = subprocess.run( | |
f"shellcheck {file}", shell=True, capture_output=True, check=False | |
) | |
print(p.stdout.decode()) | |
if p.returncode != 0: | |
print(f"[Shellcheck did not pass] {file}") | |
sys.exit(1) | |
print(f"[Shellcheck passed] {file}") |