mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-09-25 19:03:59 +02:00
The `Lint workflows` autofix job has failed on every scheduled run since at
least 2026-08-16, with `shfmt` reporting parse errors ("LitWord cannot be
followed by a word", "${ stmts;} is a mksh feature", ...) in ~70 shell scripts
that parse cleanly on a pristine checkout.
Root cause is the preceding "Fix non-printable Unicode spaces" step. Its regex
was written as `$'[\\u00A0\\u2002...]'`: the doubled backslash makes bash's
ANSI-C quoting emit the literal text ` `, and Perl has no `\u` codepoint
escape — `\u` is the titlecase-next-character operator, so the character class
degrades to the plain characters `0 2 3 5 7 8 9 A B F`. The step therefore
replaced those digits and letters with spaces in every text file in the repo,
which is what left the shell scripts unparseable. `shfmt` then exited 1 and the
job stopped before opening its autofix PR — the only reason the corruption was
never committed.
Switch to Perl's own `\x{...}` escape in a plain single-quoted string, so the
class holds the ten intended code points and nothing else.
Verified locally against the exact step body extracted from the workflow: on a
sample of the repo it now rewrites only the real U+202F occurrences (e.g.
`postgres_15/.../99-run.sh`, `birdnet-pi/DOCS.md`) and leaves all other text
untouched, and `shfmt v3.12.0 -w -i 4 -ci -bn -sr` over the whole repo exits 0
with no parse errors.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
150 lines
4.9 KiB
YAML
150 lines
4.9 KiB
YAML
name: Lint workflows
|
|
|
|
on:
|
|
push:
|
|
branches: [ master ]
|
|
paths-ignore:
|
|
- "**/config.*"
|
|
pull_request:
|
|
branches: [ master ]
|
|
schedule:
|
|
- cron: "0 0 * * 0"
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
lint-changes:
|
|
if: github.event_name == 'push' || github.event_name == 'pull_request'
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v7.0.1
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set diff range
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
echo "DIFF_RANGE=${{ github.event.pull_request.base.sha }}...${{ github.sha }}" >> $GITHUB_ENV
|
|
else
|
|
echo "DIFF_RANGE=${{ github.event.before }}...${{ github.sha }}" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Fix non-printable Unicode spaces in changed text files
|
|
run: |
|
|
set -euo pipefail
|
|
CHANGED_FILES=$(git diff --name-only "$DIFF_RANGE")
|
|
UNICODE_SPACES_REGEX='[\x{00A0}\x{2002}\x{2003}\x{2007}\x{2008}\x{2009}\x{202F}\x{205F}\x{3000}\x{200B}]'
|
|
for file in $CHANGED_FILES; do
|
|
if [ -f "$file" ]; then
|
|
MIME_TYPE=$(file --mime-type -b "$file")
|
|
if [[ "$MIME_TYPE" == text/* ]]; then
|
|
perl -CSD -pe "s/$UNICODE_SPACES_REGEX/ /g" "$file" > "$file.tmp" && mv "$file.tmp" "$file"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
- name: Run Super Linter
|
|
uses: super-linter/super-linter/slim@main
|
|
continue-on-error: true
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
VALIDATE_ALL_CODEBASE: false
|
|
VALIDATE_CHECKOV: false
|
|
VALIDATE_PYTHON_PYLINT: false
|
|
VALIDATE_JSCPD: false
|
|
VALIDATE_NATURAL_LANGUAGE: false
|
|
FILTER_REGEX_EXCLUDE: .github/workflows/.*
|
|
FIX_ENV: false
|
|
FIX_HTML_PRETTIER: false
|
|
FIX_SHELL_SHFMT: true
|
|
FIX_YAML_PRETTIER: false
|
|
FIX_JSON: false
|
|
FIX_MARKDOWN: false
|
|
FIX_PYTHON_BLACK: false
|
|
FIX_PYTHON_ISORT: false
|
|
FIX_PYTHON_RUFF: false
|
|
|
|
- name: Restore executable permissions
|
|
run: |
|
|
find . -type f \( -name "*.sh" -o -name "run" \) -exec chmod +x {} \;
|
|
|
|
- name: Remove Super-Linter output (prevent checkout conflict)
|
|
run: sudo rm -rf super-linter-output/
|
|
|
|
lint-autofix:
|
|
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v7.0.1
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Fix non-printable Unicode spaces in all text files
|
|
run: |
|
|
set -euo pipefail
|
|
UNICODE_SPACES_REGEX='[\x{00A0}\x{2002}\x{2003}\x{2007}\x{2008}\x{2009}\x{202F}\x{205F}\x{3000}\x{200B}]'
|
|
find . -type f ! -path "./.git/*" | while read -r file; do
|
|
MIME_TYPE=$(file --mime-type -b "$file")
|
|
if [[ "$MIME_TYPE" == text/* ]]; then
|
|
perl -CSD -pe "s/$UNICODE_SPACES_REGEX/ /g" "$file" > "$file.tmp" && mv "$file.tmp" "$file"
|
|
fi
|
|
done
|
|
|
|
- name: Run Super Linter
|
|
uses: super-linter/super-linter/slim@main
|
|
continue-on-error: true
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
VALIDATE_ALL_CODEBASE: true
|
|
VALIDATE_CHECKOV: false
|
|
VALIDATE_PYTHON_PYLINT: false
|
|
VALIDATE_JSCPD: false
|
|
VALIDATE_NATURAL_LANGUAGE: false
|
|
FILTER_REGEX_EXCLUDE: .github/workflows/.*
|
|
FIX_ENV: true
|
|
FIX_HTML_PRETTIER: true
|
|
FIX_SHELL_SHFMT: true
|
|
FIX_YAML_PRETTIER: true
|
|
FIX_JSON: false
|
|
FIX_MARKDOWN: true
|
|
FIX_PYTHON_BLACK: true
|
|
FIX_PYTHON_ISORT: false
|
|
FIX_PYTHON_RUFF: true
|
|
|
|
- name: Use 4 spaces in shell scripts
|
|
run: |
|
|
curl -sSLo /usr/local/bin/shfmt https://github.com/mvdan/sh/releases/download/v3.12.0/shfmt_v3.12.0_linux_amd64
|
|
chmod +x /usr/local/bin/shfmt
|
|
find . -type f \( -name "*.sh" -o -name "run" \) -exec shfmt -w -i 4 -ci -bn -sr {} +
|
|
|
|
- name: Restore executable permissions
|
|
run: |
|
|
find . -type f \( -name "*.sh" -o -name "run" \) -exec chmod +x {} \;
|
|
|
|
- name: Remove Super-Linter output (prevent checkout conflict)
|
|
run: sudo rm -rf super-linter-output/
|
|
|
|
- name: Check for linting changes
|
|
id: changed
|
|
run: |
|
|
if ! git diff --quiet; then
|
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Create New Pull Request If Needed
|
|
if: steps.changed.outputs.changed == 'true'
|
|
uses: peter-evans/create-pull-request@v8
|
|
with:
|
|
title: "Github bot: fix linting issues nobuild"
|
|
commit-message: "fix: auto-fix linting issues"
|
|
branch-suffix: timestamp
|