Files
TX-Ultimate-Easy/.github/workflows/validate_yamllint.yml
2025-03-15 18:23:25 +01:00

53 lines
1.4 KiB
YAML

---
name: Validate YAML (secondary files)
# yamllint disable-line rule:truthy
on:
push:
paths:
- '**/*.yml'
- '**/*.yaml'
pull_request:
paths:
- '**/*.yml'
- '**/*.yaml'
workflow_dispatch:
jobs:
code_scan:
name: Validate YAML
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensures full commit history for diff
- name: Identify changed files
id: changed-files
run: |
BASE=${{ github.event.before }}
HEAD=${{ github.sha }}
FILES=$(git diff --name-only $BASE $HEAD -- '**/*.yml' '**/*.yaml' | tr '\n' ',')
echo "changed_files=$FILES" >> $GITHUB_ENV
if [[ -n "$FILES" ]]; then
echo "any_changed=true" >> $GITHUB_ENV
else
echo "any_changed=false" >> $GITHUB_ENV
fi
- name: Validate YAML
if: env.any_changed == 'true'
run: |
IFS=',' read -ra FILES <<< "${{ env.changed_files }}"
for file in "${FILES[@]}"; do
if [[ "$file" =~ ^.*\.yaml$ ]] || [[ "$file" =~ ^ESPHome/.*\.yaml$ ]]; then
echo "Skipping $file"
continue
fi
echo "::group::Validating $file"
yamllint -c "./.rules/yamllint.yml" "$file"
echo "::endgroup::"
done
...