Skip to content

Commit 621c2e8

Browse files
chore: standardize lint workflows (#33)
Signed-off-by: Philippe Noël <21990816+philippemnoel@users.noreply.github.com>
1 parent 75adf1f commit 621c2e8

3 files changed

Lines changed: 69 additions & 32 deletions

File tree

.github/workflows/lint-bash.yml

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,69 @@ jobs:
3131
with:
3232
python-version: "3.11"
3333

34-
- name: Install Bash Linters
35-
run: |
36-
pip install beautysh
37-
sudo apt-get update
38-
sudo apt-get install -y shellcheck
34+
- name: Set up uv
35+
uses: astral-sh/setup-uv@v6
36+
with:
37+
enable-cache: true
3938

4039
- name: Run Beautysh
4140
run: |
4241
shopt -s globstar nullglob
4342
if compgen -G "**/*.sh" > /dev/null; then
44-
beautysh **/*.sh --indent-size 2 --check
43+
uv tool run --from beautysh beautysh **/*.sh --indent-size 2 --check
4544
fi
4645
shopt -u globstar nullglob
4746
48-
- name: Check Bash Script Shebang
47+
- name: Check Bash Scripts for bash shebang
4948
run: |
50-
while IFS= read -r -d '' file; do
51-
if head -n 1 "$file" | grep -Eq '^#!/usr/bin/env bash$|^#!/bin/bash$'; then
49+
while read -r file
50+
do
51+
shebang="$(head -n 1 "$file")"
52+
if [[ "$shebang" = "#!/bin/bash" || "$shebang" = "#!/usr/bin/env bash" ]]
53+
then
5254
echo "[bash shebang -> Present] $file"
5355
else
54-
echo "[bash shebang -> NOT FOUND] $file"
55-
exit 1
56+
echo "[bash shebang -> NOT FOUND] $file" && exit 1
5657
fi
57-
done < <(find . -name '*.sh' -print0)
58+
done < <(find . -name '*.sh')
5859
59-
- name: Check Bash Scripts for Pipefail
60+
- name: Check Bash Scripts for strict mode opt-in
6061
run: |
61-
while IFS= read -r -d '' file; do
62+
while read -r file
63+
do
6264
if grep -q \
6365
-e "^[[:space:]]*set -euo pipefail$" \
6466
-e "^[[:space:]]*set -Eeuo pipefail$" \
65-
-e "^[[:space:]]*# @paradedb-skip-check-pipefail$" \
66-
"$file"; then
67-
echo "[pipefail -> Present] $file"
67+
-e "^# @paradedb-skip-check-pipefail$" \
68+
"$file"
69+
then
70+
echo "[strict mode -> Present] $file"
6871
else
69-
echo "[pipefail -> NOT FOUND] $file"
70-
exit 1
72+
echo "[strict mode -> NOT FOUND] $file" && exit 1
7173
fi
72-
done < <(find . -name '*.sh' -print0)
74+
done < <(find . -name '*.sh')
7375
7476
- name: Run ShellCheck
7577
run: |
76-
while IFS= read -r -d '' file; do
77-
shellcheck -x "$file"
78-
done < <(find . -name '*.sh' -print0)
78+
uv run --no-sync python - <<'PY'
79+
import glob
80+
import subprocess
81+
import sys
82+
83+
sh_files = sorted(set(glob.glob("**/*.sh", recursive=True)))
84+
if not sh_files:
85+
print("[Shellcheck skipped] No shell scripts found.")
86+
sys.exit(0)
87+
for file in sh_files:
88+
p = subprocess.run(
89+
f"shellcheck -x -P scripts {file}",
90+
shell=True,
91+
capture_output=True,
92+
check=False,
93+
)
94+
print(p.stdout.decode())
95+
if p.returncode != 0:
96+
print(f"[Shellcheck did not pass] {file}")
97+
sys.exit(1)
98+
print(f"[Shellcheck passed] {len(sh_files)} script(s)")
99+
PY

.github/workflows/lint-format.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# workflows/lint-format.yml
22
#
33
# Lint Format
4-
# Lint file line endings and trailing whitespace.
4+
# Lint the project's file trailing spaces, line endings, and format.
55

66
name: Lint Format
77

@@ -26,17 +26,33 @@ jobs:
2626
- name: Check for CRLF Files
2727
run: |
2828
FILES=$(git ls-files --eol | grep crlf || true)
29-
if [[ -n "$FILES" ]]; then
29+
if [[ ! -z "$FILES" ]]; then
3030
echo "The following files have incorrect line endings:"
3131
echo "$FILES"
32-
exit 1
32+
false
3333
fi
3434
3535
- name: Check for Trailing Whitespaces
3636
run: |
37-
FILES=$(git grep -Ilr '[[:blank:]]$' -- . || true)
38-
if [[ -n "$FILES" ]]; then
37+
FILES=$(git grep -Ilr '[[:blank:]]$' -- \
38+
':(exclude)*.nix' \
39+
':(exclude)*.sql' \
40+
':(exclude)*.out' \
41+
':(exclude)*.rs' \
42+
':(exclude)docker/manifests/**' || true)
43+
if [[ ! -z "$FILES" ]]; then
3944
echo "The following files have trailing whitespaces:"
4045
echo "$FILES"
4146
exit 1
4247
fi
48+
49+
- name: Print Modified Files
50+
run: |
51+
FILES=$(git ls-files --modified)
52+
if [[ ! -z "$FILES" ]]; then
53+
echo "The following files have incorrect trailing newlines:"
54+
echo "$FILES"
55+
echo "Please fix them using:"
56+
echo -e 'if [[ -f "$1" ]]; then\n echo -n "$1"\n if (diff /dev/null "$1" || true) | tail -1 | grep -q "^\\ No newline"; then\n echo >> "$1"\n echo "...fixed"\n else\n echo ""\n fi\nfi'
57+
false
58+
fi

.github/workflows/lint-markdown.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ on:
1111
paths:
1212
- "**/*.md"
1313
- "**/*.mdx"
14+
- ".github/workflows/lint-markdown.yml"
1415
- ".markdownlint.yaml"
1516
- ".prettierignore"
1617
- ".prettierrc"
17-
- ".github/workflows/lint-markdown.yml"
1818
workflow_dispatch:
1919

2020
concurrency:
@@ -33,11 +33,11 @@ jobs:
3333
- name: Set up NodeJS Environment
3434
uses: actions/setup-node@v6
3535

36-
- name: Install Markdown Linters
36+
- name: Install Prettier and markdownlint
3737
run: npm install -g prettier markdownlint-cli
3838

3939
- name: Run Markdown Lint
40-
run: markdownlint '**/*.md'
40+
run: markdownlint "**/*.md"
4141

4242
- name: Run Prettier
43-
run: prettier --check '{**/*.md,**/*.mdx}' --ignore-path .prettierignore
43+
run: prettier --check "{**/*.md,**/*.mdx}" --ignore-path .prettierignore

0 commit comments

Comments
 (0)