72 lines
2.0 KiB
YAML
72 lines
2.0 KiB
YAML
---
|
|
apiVersion: tekton.dev/v1
|
|
kind: Task
|
|
metadata:
|
|
name: nx-nodejs-analysis
|
|
spec:
|
|
params:
|
|
- name: subdirectory
|
|
type: string
|
|
description: Subdirectory within the repo where the source code is located
|
|
default: ""
|
|
|
|
- name: targetProject
|
|
type: string
|
|
description: Nx workspace project name to lint and test
|
|
|
|
- name: node-version
|
|
type: string
|
|
default: "18"
|
|
description: Node.js version (e.g., 18, 20)
|
|
|
|
workspaces:
|
|
- name: source
|
|
description: Git-cloned source code with Nx monorepo
|
|
- name: npm-auth
|
|
optional: true
|
|
description: |
|
|
A workspace containing authentication credentials for a private npm repository.
|
|
Should include:
|
|
- username
|
|
- password
|
|
|
|
results:
|
|
- name: coverage-dir
|
|
description: Path to generated coverage directory
|
|
- name: coverage-html
|
|
description: Path to generated HTML coverage report directory
|
|
|
|
steps:
|
|
- name: lint-and-test
|
|
image: node:$(params.node-version)
|
|
workingDir: /workspace/source
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
if [ -n "$(params.subdirectory)" ]; then
|
|
cd "$(params.subdirectory)"
|
|
fi
|
|
|
|
echo "📦 Installing dependencies"
|
|
npm ci
|
|
|
|
echo "🔍 Running ESLint for project: $(params.targetProject)"
|
|
npx nx lint $(params.targetProject)
|
|
|
|
echo "🧪 Running Jest tests for project: $(params.targetProject) with coverage"
|
|
npx nx test $(params.targetProject) --code-coverage
|
|
|
|
COVERAGE_DIR="coverage/$(params.targetProject)"
|
|
HTML_DIR="$COVERAGE_DIR/lcov-report"
|
|
|
|
echo "📁 Saving coverage path: $COVERAGE_DIR"
|
|
echo -n "$COVERAGE_DIR" > /tekton/results/coverage-dir
|
|
echo -n "$HTML_DIR" > /tekton/results/coverage-html
|
|
|
|
if [ -d "$HTML_DIR" ]; then
|
|
echo "📄 HTML coverage report generated at $HTML_DIR"
|
|
else
|
|
echo "⚠️ HTML coverage report not found"
|
|
fi
|