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: 0 BUILD_WARNING_THRESHOLD: 0 steps: - name: Checkout Repository uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - name: Set Up pnpm uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9 - name: Set Up Node.js uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 with: node-version-file: .nvmrc - name: Install Frontend Dependencies run: pnpm install --frozen-lockfile --ignore-scripts - name: Typecheck Frontend working-directory: ./frontend run: pnpm run typecheck - name: Run Frontend Build working-directory: ./frontend run: | set +e CI=1 NG_CLI_ANALYTICS=false pnpm run build:prod 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: ./frontend 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: ./frontend run: | # Lint output is written to JSON for threshold evaluation. pnpm run lint:eslint --format json --output-file lint-results.json || true - name: Count Lint Warnings working-directory: ./frontend 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"