Add syntax checking for every 2 commits
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
name: Syntax Check (Every 2 Commits)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "**"
|
||||
|
||||
jobs:
|
||||
syntax-check:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.commits && github.event.commits.length >= 2 }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install linting tools
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y shellcheck
|
||||
pip install --break-system-packages yamllint
|
||||
|
||||
- name: Lint shell scripts with ShellCheck
|
||||
run: |
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " Running ShellCheck on all .sh files"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
|
||||
SH_FILES=$(find . -name '*.sh' -not -path './.git/*')
|
||||
if [ -z "$SH_FILES" ]; then
|
||||
echo "No shell scripts found."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
FAILED=0
|
||||
for f in $SH_FILES; do
|
||||
echo ""
|
||||
echo "── Checking: $f"
|
||||
if shellcheck -x -s bash "$f"; then
|
||||
echo " ✅ $f passed"
|
||||
else
|
||||
echo " ❌ $f failed"
|
||||
FAILED=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$FAILED" -ne 0 ]; then
|
||||
echo ""
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " ❌ One or more shell scripts have syntax issues"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " ✅ All shell scripts passed ShellCheck"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
|
||||
- name: Lint YAML files with yamllint
|
||||
run: |
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " Running yamllint on all YAML files"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
|
||||
YAML_FILES=$(find . -name '*.yml' -o -name '*.yaml' | grep -v '.git/')
|
||||
if [ -z "$YAML_FILES" ]; then
|
||||
echo "No YAML files found."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
FAILED=0
|
||||
for f in $YAML_FILES; do
|
||||
echo ""
|
||||
echo "── Checking: $f"
|
||||
if yamllint -d relaxed "$f"; then
|
||||
echo " ✅ $f passed"
|
||||
else
|
||||
echo " ❌ $f failed"
|
||||
FAILED=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$FAILED" -ne 0 ]; then
|
||||
echo ""
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " ❌ One or more YAML files have syntax issues"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " ✅ All YAML files passed yamllint"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
|
||||
- name: Validate packages.x86_64 syntax
|
||||
run: |
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " Validating packages.x86_64 format"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
|
||||
if [ ! -f packages.x86_64 ]; then
|
||||
echo "packages.x86_64 not found, skipping."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
FAILED=0
|
||||
LINENUM=0
|
||||
while IFS= read -r line; do
|
||||
LINENUM=$((LINENUM + 1))
|
||||
# Skip empty lines and comments
|
||||
[[ -z "$line" || "$line" =~ ^# ]] && continue
|
||||
|
||||
# Check for invalid characters (package names should be alphanumeric, hyphens, dots, underscores, @)
|
||||
if [[ ! "$line" =~ ^[a-zA-Z0-9._@+\-]+$ ]]; then
|
||||
echo "❌ Line $LINENUM: invalid package name format: '$line'"
|
||||
FAILED=1
|
||||
fi
|
||||
|
||||
# Check for trailing whitespace
|
||||
if [[ "$line" =~ [[:space:]]$ ]]; then
|
||||
echo "⚠️ Line $LINENUM: trailing whitespace: '$line'"
|
||||
FAILED=1
|
||||
fi
|
||||
done < packages.x86_64
|
||||
|
||||
if [ "$FAILED" -ne 0 ]; then
|
||||
echo ""
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " ❌ packages.x86_64 has syntax issues"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo " ✅ packages.x86_64 syntax is valid"
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
Reference in New Issue
Block a user