chore: add pre-commit hooks and CI coverage reporting

- Add pre-commit hook for JS/TS and CSS lint checks
- Add setup script to install hooks
- Add coverage reporting to CI workflow
- Add coverage threshold warning (60%)
- Update CONTRIBUTING.md with hooks setup instructions
This commit is contained in:
admin 2025-12-18 11:01:00 -06:00
parent 09a7180966
commit 66264b7301
4 changed files with 90 additions and 4 deletions

View file

@ -90,10 +90,10 @@ jobs:
chmod +x _tests/bin/Radarr
find _tests -name "Radarr.Test.Dummy" -exec chmod a+x {} \;
- name: Test
- name: Test with coverage
shell: bash
continue-on-error: true
run: ./test.sh Linux Unit Test
run: ./test.sh Linux Unit Coverage
- name: Report test results
uses: dorny/test-reporter@v2
@ -106,6 +106,36 @@ jobs:
fail-on-error: false
fail-on-empty: false
- name: Generate coverage report
uses: danielpalme/ReportGenerator-GitHub-Action@5
if: always()
with:
reports: "**/coverage.cobertura.xml"
targetdir: CoverageReport
reporttypes: "HtmlInline;Cobertura;TextSummary"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: always()
continue-on-error: true
with:
files: "**/coverage.cobertura.xml"
fail_ci_if_error: false
- name: Check coverage threshold
if: always()
shell: bash
run: |
if [ -f CoverageReport/Summary.txt ]; then
COVERAGE=$(grep -oP 'Line coverage: \K[\d.]+' CoverageReport/Summary.txt || echo "0")
echo "Line coverage: ${COVERAGE}%"
if (( $(echo "$COVERAGE < 60" | bc -l) )); then
echo "::warning::Coverage is below 60% threshold (${COVERAGE}%)"
fi
else
echo "::warning::Coverage report not found"
fi
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /usr/local/share/boost

View file

@ -31,9 +31,10 @@ Aletheia is written in C# (backend) and JS (frontend). The backend is built on .
1. Clone the repository: `git clone https://github.com/cheir-mneme/aletheia.git`
1. Install dependencies and build as described below
1. (Optional) Install pre-commit hooks: `./scripts/setup-hooks.sh`
> Be sure to run lint `yarn lint --fix` on your code for any front end changes before committing.
For css changes `yarn stylelint-windows --fix` {.is-info}
> The pre-commit hooks will automatically run lint checks before each commit.
> You can also run lint manually: `yarn lint --fix` for JS/TS, `yarn stylelint-linux --fix` for CSS.
### Building the frontend

37
scripts/pre-commit Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
# Pre-commit hook for Aletheia
set -e
echo "Running pre-commit checks..."
# Check if there are any staged frontend files
STAGED_JS=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|jsx|ts|tsx)$' | grep '^frontend/' || true)
if [ -n "$STAGED_JS" ]; then
echo "Checking JavaScript/TypeScript lint..."
yarn lint --quiet 2>/dev/null || {
echo "ESLint errors found. Run 'yarn lint-fix' to auto-fix."
exit 1
}
fi
# Check if there are any staged CSS files
STAGED_CSS=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.css$' | grep '^frontend/' || true)
if [ -n "$STAGED_CSS" ]; then
echo "Checking CSS lint..."
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
yarn stylelint-windows --quiet 2>/dev/null || {
echo "Stylelint errors found."
exit 1
}
else
yarn stylelint-linux --quiet 2>/dev/null || {
echo "Stylelint errors found."
exit 1
}
fi
fi
echo "Pre-commit checks passed."

18
scripts/setup-hooks.sh Executable file
View file

@ -0,0 +1,18 @@
#!/bin/bash
# Install git hooks for Aletheia development
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HOOKS_DIR="$SCRIPT_DIR/../.git/hooks"
echo "Installing git hooks..."
if [ -f "$HOOKS_DIR/pre-commit" ]; then
echo "Backing up existing pre-commit hook..."
mv "$HOOKS_DIR/pre-commit" "$HOOKS_DIR/pre-commit.backup"
fi
cp "$SCRIPT_DIR/pre-commit" "$HOOKS_DIR/pre-commit"
chmod +x "$HOOKS_DIR/pre-commit"
echo "Git hooks installed successfully."
echo "Run 'yarn install' to ensure lint dependencies are available."