170 lines
6.6 KiB
YAML
170 lines
6.6 KiB
YAML
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:
|
|
OXLINT_WARNING_THRESHOLD: 0
|
|
OXLINT_ERROR_THRESHOLD: 0
|
|
ESLINT_WARNING_THRESHOLD: 0
|
|
ESLINT_ERROR_THRESHOLD: 0
|
|
BUILD_WARNING_THRESHOLD: 0
|
|
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Set Up pnpm and Node.js
|
|
uses: pnpm/setup@a0881977cd8ea73b1ed212236c99ca10dcc80cf4 # v3.1.1
|
|
with:
|
|
node-version-file: .nvmrc
|
|
cache: true
|
|
install: false
|
|
|
|
- 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: |
|
|
OXLINT_EXIT_CODE=0
|
|
pnpm --silent run lint:oxlint:ci > oxlint-results.json || OXLINT_EXIT_CODE=$?
|
|
echo "OXLINT_EXIT_CODE=${OXLINT_EXIT_CODE}" >> "$GITHUB_ENV"
|
|
|
|
ESLINT_EXIT_CODE=0
|
|
pnpm run lint:eslint --format json --output-file lint-results.json || ESLINT_EXIT_CODE=$?
|
|
echo "ESLINT_EXIT_CODE=${ESLINT_EXIT_CODE}" >> "$GITHUB_ENV"
|
|
|
|
- name: Count Lint Findings
|
|
working-directory: ./frontend
|
|
run: |
|
|
if [ ! -f oxlint-results.json ] || [ ! -f lint-results.json ]; then
|
|
echo "ERROR: one or more lint result files were not generated"
|
|
exit 1
|
|
fi
|
|
|
|
OXLINT_WARNING_COUNT=$(jq '[.diagnostics[] | select(.severity == "warning")] | length' oxlint-results.json)
|
|
OXLINT_ERROR_COUNT=$(jq '[.diagnostics[] | select(.severity == "error")] | length' oxlint-results.json)
|
|
ESLINT_WARNING_COUNT=$(jq 'reduce .[] as $f (0; . + ($f.warningCount // 0))' lint-results.json)
|
|
ESLINT_ERROR_COUNT=$(jq 'reduce .[] as $f (0; . + ($f.errorCount // 0))' lint-results.json)
|
|
|
|
jq -r '.diagnostics[] | "\(.filename):\(.labels[0].span.line // 0): \(.severity) \(.code // "") \(.message)"' oxlint-results.json
|
|
jq -r '.[] | .filePath as $f | .messages[] | "\($f):\(.line // 0): \(if .severity == 2 then "error" else "warning" end) \(.ruleId // "") \(.message)"' lint-results.json
|
|
|
|
echo "Oxlint warnings found: ${OXLINT_WARNING_COUNT}"
|
|
echo "Oxlint errors found: ${OXLINT_ERROR_COUNT}"
|
|
echo "ESLint warnings found: ${ESLINT_WARNING_COUNT}"
|
|
echo "ESLint errors found: ${ESLINT_ERROR_COUNT}"
|
|
echo "OXLINT_WARNING_COUNT=${OXLINT_WARNING_COUNT}" >> "$GITHUB_ENV"
|
|
echo "OXLINT_ERROR_COUNT=${OXLINT_ERROR_COUNT}" >> "$GITHUB_ENV"
|
|
echo "ESLINT_WARNING_COUNT=${ESLINT_WARNING_COUNT}" >> "$GITHUB_ENV"
|
|
echo "ESLINT_ERROR_COUNT=${ESLINT_ERROR_COUNT}" >> "$GITHUB_ENV"
|
|
|
|
- name: Enforce Quality Thresholds
|
|
run: |
|
|
BUILD_STATUS="PASS"
|
|
OXLINT_STATUS="PASS"
|
|
OXLINT_ERROR_STATUS="PASS"
|
|
ESLINT_STATUS="PASS"
|
|
ESLINT_ERROR_STATUS="PASS"
|
|
|
|
if [ "${BUILD_WARNING_COUNT}" -gt "${BUILD_WARNING_THRESHOLD}" ]; then
|
|
BUILD_STATUS="FAIL"
|
|
fi
|
|
|
|
if [ "${OXLINT_WARNING_COUNT}" -gt "${OXLINT_WARNING_THRESHOLD}" ]; then
|
|
OXLINT_STATUS="FAIL"
|
|
fi
|
|
|
|
if [ "${OXLINT_ERROR_COUNT}" -gt "${OXLINT_ERROR_THRESHOLD}" ]; then
|
|
OXLINT_ERROR_STATUS="FAIL"
|
|
fi
|
|
|
|
if [ "${OXLINT_EXIT_CODE}" -ne 0 ]; then
|
|
OXLINT_ERROR_STATUS="FAIL"
|
|
fi
|
|
|
|
if [ "${ESLINT_WARNING_COUNT}" -gt "${ESLINT_WARNING_THRESHOLD}" ]; then
|
|
ESLINT_STATUS="FAIL"
|
|
fi
|
|
|
|
if [ "${ESLINT_ERROR_COUNT}" -gt "${ESLINT_ERROR_THRESHOLD}" ]; then
|
|
ESLINT_ERROR_STATUS="FAIL"
|
|
fi
|
|
|
|
if [ "${ESLINT_EXIT_CODE}" -ne 0 ]; then
|
|
ESLINT_ERROR_STATUS="FAIL"
|
|
fi
|
|
|
|
echo "Build warnings: ${BUILD_WARNING_COUNT} (threshold: ${BUILD_WARNING_THRESHOLD})"
|
|
echo "Oxlint warnings: ${OXLINT_WARNING_COUNT} (threshold: ${OXLINT_WARNING_THRESHOLD})"
|
|
echo "Oxlint errors: ${OXLINT_ERROR_COUNT} (threshold: ${OXLINT_ERROR_THRESHOLD})"
|
|
echo "ESLint warnings: ${ESLINT_WARNING_COUNT} (threshold: ${ESLINT_WARNING_THRESHOLD})"
|
|
echo "ESLint errors: ${ESLINT_ERROR_COUNT} (threshold: ${ESLINT_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 "| Oxlint warnings | ${OXLINT_WARNING_COUNT} | ${OXLINT_WARNING_THRESHOLD} | ${OXLINT_STATUS} |"
|
|
echo "| Oxlint errors | ${OXLINT_ERROR_COUNT} | ${OXLINT_ERROR_THRESHOLD} | ${OXLINT_ERROR_STATUS} |"
|
|
echo "| ESLint warnings | ${ESLINT_WARNING_COUNT} | ${ESLINT_WARNING_THRESHOLD} | ${ESLINT_STATUS} |"
|
|
echo "| ESLint errors | ${ESLINT_ERROR_COUNT} | ${ESLINT_ERROR_THRESHOLD} | ${ESLINT_ERROR_STATUS} |"
|
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
if [ "${BUILD_STATUS}" = "FAIL" ] || [ "${OXLINT_STATUS}" = "FAIL" ] || [ "${OXLINT_ERROR_STATUS}" = "FAIL" ] || [ "${ESLINT_STATUS}" = "FAIL" ] || [ "${ESLINT_ERROR_STATUS}" = "FAIL" ]; then
|
|
echo "ERROR: One or more quality thresholds failed"
|
|
exit 1
|
|
fi
|
|
|
|
echo "OK: All quality thresholds passed"
|