feat(lint): Additional CI workflow to enforce a threshold of the amount of frontend lint issues (#163)
* feat(lint): add Angular Lint Threshold workflow for CI integration * Update workflow name for clarity in CI integration * fix(lint): update LINT_THRESHOLD to 725 in CI checks * Also run workflow on main branch Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix(lint): simplify lint problem count calculation using jq * feat(lint): enhance quality threshold checks and reporting in CI workflow * refactor(lint): rename lint step for clarity in CI workflow * fix(lint): swap lint warning and error thresholds for correct configuration * fix(lint): update build warning threshold and correct log processing for accurate warning count * refactor(lint): remove unnecessary working-directory specification for quality thresholds step --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
coderabbitai[bot]
parent
af9beafe7a
commit
79aa2e04c9
@@ -0,0 +1,132 @@
|
||||
name: CI - Frontend Quality Thresholds
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- develop
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
lint-threshold:
|
||||
name: Frontend Lint Threshold Check
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
LINT_WARNING_THRESHOLD: 0
|
||||
LINT_ERROR_THRESHOLD: 725
|
||||
BUILD_WARNING_THRESHOLD: 24
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
|
||||
- name: Set Up Node.js
|
||||
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
|
||||
with:
|
||||
node-version: '24'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: booklore-ui/package-lock.json
|
||||
|
||||
- name: Install Frontend Dependencies
|
||||
working-directory: ./booklore-ui
|
||||
run: npm ci
|
||||
|
||||
- name: Typecheck Frontend
|
||||
working-directory: ./booklore-ui
|
||||
run: npx tsc --noEmit -p tsconfig.app.json
|
||||
|
||||
- name: Run Frontend Build
|
||||
working-directory: ./booklore-ui
|
||||
run: |
|
||||
set +e
|
||||
npx ng build --configuration production --progress=false 2>&1 | tee build-output.log
|
||||
BUILD_EXIT_CODE=${PIPESTATUS[0]}
|
||||
set -e
|
||||
|
||||
if [ "${BUILD_EXIT_CODE}" -ne 0 ]; then
|
||||
echo "ERROR: Angular build failed with exit code ${BUILD_EXIT_CODE}"
|
||||
exit ${BUILD_EXIT_CODE}
|
||||
fi
|
||||
|
||||
- name: Count Build Warnings
|
||||
working-directory: ./booklore-ui
|
||||
run: |
|
||||
if [ ! -f build-output.log ]; then
|
||||
echo "ERROR: build-output.log was not generated by ng build"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed -E $'s/\x1B\[[0-9;]*[A-Za-z]//g' build-output.log > build-output-plain.log
|
||||
BUILD_WARNING_COUNT=$(grep -E -c '\[WARNING\]|WARNING in|^Warning:' build-output-plain.log || true)
|
||||
|
||||
echo "Build warnings found: ${BUILD_WARNING_COUNT}"
|
||||
echo "BUILD_WARNING_COUNT=${BUILD_WARNING_COUNT}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Run Frontend Linter
|
||||
working-directory: ./booklore-ui
|
||||
run: |
|
||||
# Lint output is written to JSON for threshold evaluation.
|
||||
npx ng lint --format json --output-file lint-results.json || true
|
||||
|
||||
- name: Count Lint Warnings
|
||||
working-directory: ./booklore-ui
|
||||
run: |
|
||||
if [ ! -f lint-results.json ]; then
|
||||
echo "ERROR: lint-results.json was not generated by ng lint"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LINT_WARNING_COUNT=$(jq 'reduce .[] as $f (0; . + ($f.warningCount // 0))' lint-results.json)
|
||||
LINT_ERROR_COUNT=$(jq 'reduce .[] as $f (0; . + ($f.errorCount // 0))' lint-results.json)
|
||||
|
||||
echo "Lint warnings found: ${LINT_WARNING_COUNT}"
|
||||
echo "Lint errors found: ${LINT_ERROR_COUNT}"
|
||||
echo "LINT_WARNING_COUNT=${LINT_WARNING_COUNT}" >> "$GITHUB_ENV"
|
||||
echo "LINT_ERROR_COUNT=${LINT_ERROR_COUNT}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Enforce Quality Thresholds
|
||||
run: |
|
||||
BUILD_STATUS="PASS"
|
||||
LINT_STATUS="PASS"
|
||||
LINT_ERROR_STATUS="PASS"
|
||||
|
||||
if [ "${BUILD_WARNING_COUNT}" -gt "${BUILD_WARNING_THRESHOLD}" ]; then
|
||||
BUILD_STATUS="FAIL"
|
||||
fi
|
||||
|
||||
if [ "${LINT_WARNING_COUNT}" -gt "${LINT_WARNING_THRESHOLD}" ]; then
|
||||
LINT_STATUS="FAIL"
|
||||
fi
|
||||
|
||||
if [ "${LINT_ERROR_COUNT}" -gt "${LINT_ERROR_THRESHOLD}" ]; then
|
||||
LINT_ERROR_STATUS="FAIL"
|
||||
fi
|
||||
|
||||
echo "Build warnings: ${BUILD_WARNING_COUNT} (threshold: ${BUILD_WARNING_THRESHOLD})"
|
||||
echo "Lint warnings: ${LINT_WARNING_COUNT} (threshold: ${LINT_WARNING_THRESHOLD})"
|
||||
echo "Lint errors: ${LINT_ERROR_COUNT} (threshold: ${LINT_ERROR_THRESHOLD})"
|
||||
|
||||
{
|
||||
echo "## Frontend Quality Gate"
|
||||
echo
|
||||
echo "| Check | Count | Threshold | Status |"
|
||||
echo "| --- | ---: | ---: | --- |"
|
||||
echo "| Build warnings | ${BUILD_WARNING_COUNT} | ${BUILD_WARNING_THRESHOLD} | ${BUILD_STATUS} |"
|
||||
echo "| Lint warnings | ${LINT_WARNING_COUNT} | ${LINT_WARNING_THRESHOLD} | ${LINT_STATUS} |"
|
||||
echo "| Lint errors | ${LINT_ERROR_COUNT} | ${LINT_ERROR_THRESHOLD} | ${LINT_ERROR_STATUS} |"
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
if [ "${BUILD_STATUS}" = "FAIL" ] || [ "${LINT_STATUS}" = "FAIL" ] || [ "${LINT_ERROR_STATUS}" = "FAIL" ]; then
|
||||
echo "ERROR: One or more quality thresholds failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "OK: All quality thresholds passed"
|
||||
Reference in New Issue
Block a user