Reusable workflow for comprehensive Frontend/Node.js PR analysis in monorepos. Handles change detection, linting, type checking, security scanning, testing, coverage checks, and build verification - all per changed app using a matrix strategy.
- Change Detection: Automatically detects which apps changed in the PR
- Matrix Execution: Runs all checks per changed app in parallel
- ESLint: Configurable linting with custom arguments
- TypeScript: Type checking with
tsc --noEmit - Security Scanning: npm audit for vulnerability detection
- Unit Tests: Runs tests with Jest/Vitest and coverage
- Coverage Check: Threshold enforcement with PR comments
- Build Verification: Ensures code compiles successfully
- Skip Logic: Gracefully skips when no frontend changes detected
- Package Manager Support: npm, yarn, and pnpm
name: Frontend Analysis
on:
pull_request:
branches: [develop, main]
jobs:
analysis:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/frontend-pr-analysis.yml@v1.0.0
secrets: inheritname: Frontend Analysis
on:
pull_request:
branches: [develop, main]
jobs:
analysis:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/frontend-pr-analysis.yml@v1.0.0
with:
filter_paths: '["apps/web", "apps/console", "packages/ui"]'
secrets: inheritname: Frontend Analysis
on:
pull_request:
branches: [develop, main]
jobs:
analysis:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/frontend-pr-analysis.yml@v1.0.0
with:
filter_paths: '["apps/web", "apps/admin", "packages/shared"]'
path_level: 2
app_name_prefix: "console"
node_version: "22"
package_manager: "npm"
eslint_args: "--max-warnings=0"
audit_level: "high"
coverage_threshold: 80
fail_on_coverage_threshold: false
enable_lint: true
enable_typecheck: true
enable_security: true
enable_tests: true
enable_coverage: true
enable_build: true
secrets: inheritjobs:
analysis:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/frontend-pr-analysis.yml@v1.0.0
with:
filter_paths: '["src"]'
enable_typecheck: false
enable_security: false
enable_coverage: false
enable_build: false
secrets: inheritjobs:
analysis:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/frontend-pr-analysis.yml@v1.0.0
with:
package_manager: "yarn"
node_version: "20"
secrets: inheritjobs:
analysis:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/frontend-pr-analysis.yml@v1.0.0
with:
package_manager: "pnpm"
node_version: "22"
secrets: inherit| Input | Description | Required | Default |
|---|---|---|---|
runner_type |
GitHub runner type | No | blacksmith-4vcpu-ubuntu-2404 |
filter_paths |
JSON array of paths to monitor for changes. If empty, treats repo as single-app. | No | '' |
path_level |
Directory depth level to extract app name | No | 2 |
app_name_prefix |
Prefix for app names in matrix output | No | '' |
node_version |
Node.js version to use | No | 22 |
package_manager |
Package manager (npm, yarn, pnpm) | No | npm |
eslint_args |
Additional ESLint arguments | No | '' |
audit_level |
npm audit severity level (low, moderate, high, critical) | No | high |
coverage_threshold |
Minimum coverage percentage (0-100) | No | 80 |
fail_on_coverage_threshold |
Fail if coverage below threshold | No | false |
enable_lint |
Enable ESLint | No | true |
enable_typecheck |
Enable TypeScript type checking | No | true |
enable_security |
Enable security scanning (npm audit) | No | true |
enable_tests |
Enable unit tests | No | true |
enable_coverage |
Enable coverage check with PR comment | No | true |
enable_build |
Enable build verification | No | true |
Uses secrets: inherit pattern. Required secrets:
| Secret | Description | Required When |
|---|---|---|
MANAGE_TOKEN |
GitHub token for PR comments | PR comments (falls back to GITHUB_TOKEN) |
SLACK_WEBHOOK_URL |
Slack webhook for notifications | Optional |
Detects which apps have changes based on filter_paths. Outputs a matrix of changed apps for subsequent jobs.
Runs ESLint per changed app. Configurable arguments via eslint_args.
Runs TypeScript compiler (tsc --noEmit) per changed app to check for type errors.
Runs npm audit per changed app:
- Checks for vulnerabilities in dependencies
- Configurable severity level via
audit_level - Only checks production dependencies (
--omit=dev)
Runs unit tests per changed app with:
- Coverage profiling (json-summary, lcov, text)
- Uploads coverage artifacts
- Works with Jest, Vitest, or any test runner that supports coverage
Calculates coverage and posts PR comment per changed app:
- Downloads coverage artifact from
testsjob - Parses
coverage-summary.jsonfor metrics - Compares against threshold
- Posts formatted coverage report as PR comment
Verifies code compiles/builds successfully per changed app.
Runs when no frontend changes are detected - outputs skip message.
Sends Slack notification with workflow status (if webhook configured).
- Compares changed files between PR base and head
- Extracts directory paths up to
path_leveldepth - Filters paths matching
filter_pathsarray - Builds matrix with
nameandworking_dirfor each changed app
Example:
filter_paths: '["apps/web", "apps/admin"]'
path_level: 2
Changed files:
- apps/web/src/components/Button.tsx
- apps/web/src/hooks/useAuth.ts
- apps/admin/pages/dashboard.tsx
Resulting matrix:
[
{"name": "web", "working_dir": "apps/web"},
{"name": "admin", "working_dir": "apps/admin"}
]
With app_name_prefix: "console":
[
{"name": "console-web", "working_dir": "apps/web"},
{"name": "console-admin", "working_dir": "apps/admin"}
]
Coverage reports are posted as PR comments in this format:
## 📊 Unit Test Coverage Report: `console-web`
| Metric | Value | Status |
|--------|-------|--------|
| **Lines** | `85.5%` | ✅ PASS |
| **Statements** | `84.2%` | |
| **Branches** | `78.3%` | |
| **Functions** | `90.1%` | |
| **Threshold** | `80%` | |
---
*Generated by Frontend PR Analysis workflow*The workflow automatically adapts commands based on package_manager:
| Action | npm | yarn | pnpm |
|---|---|---|---|
| Install | npm ci |
yarn install --frozen-lockfile |
pnpm install --frozen-lockfile |
| Lint | npx eslint . |
yarn eslint . |
pnpm eslint . |
| Test | npm test -- --coverage |
yarn test --coverage |
pnpm test --coverage |
| Build | npm run build |
yarn build |
pnpm build |
| Audit | npm audit --omit=dev |
yarn audit |
pnpm audit |
- Pin to version tag: Use
@v1.0.0instead of@v1.0.0for production stability - Custom ESLint config: Place
.eslintrcoreslint.config.jsin each app directory for app-specific rules - Coverage threshold: Start with
fail_on_coverage_threshold: falseand enable once baseline is established - Test framework: Works with Jest, Vitest, or any test runner that outputs
coverage-summary.json - Performance: Jobs run in parallel per app - more apps = more parallelism
- TypeScript config: Ensure
tsconfig.jsonexists in each app directory for type checking
The workflow requires these permissions:
contents: read- To checkout codepull-requests: write- To post coverage commentssecurity-events: write- For security scanning results
- Go PR Analysis - Equivalent workflow for Go projects
- Changed Paths - Standalone change detection
- Build - Docker image builds
- Slack Notify - Workflow notifications
- PR Security Scan - Additional security scanning with Trivy
Last Updated: 2025-12-23 Version: 1.0.0