82 lines
2.2 KiB
YAML
82 lines
2.2 KiB
YAML
apiVersion: tekton.dev/v1
|
|
kind: Task
|
|
metadata:
|
|
name: nx-nodejs-analysis
|
|
spec:
|
|
params:
|
|
- name: context
|
|
type: string
|
|
description: context directory
|
|
default: ""
|
|
|
|
- name: workspaceName
|
|
type: string
|
|
description: Nx workspace name to lint and test
|
|
|
|
- name: targetProjects
|
|
type: array
|
|
description: Nx workspace project names to lint and test
|
|
|
|
- name: nodejsImageName
|
|
type: string
|
|
default: "node:slim"
|
|
description: Node.js image (e.g., node:18-slim)
|
|
|
|
workspaces:
|
|
- name: base
|
|
description: Git-cloned source code with Nx monorepo
|
|
|
|
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: $(params.nodejsImageName)
|
|
workingDir: /workspace/base/$(params.context)/source
|
|
env:
|
|
- name: HOME
|
|
value: /workspace/base/$(params.context)/home
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
export NX_SOCKET_DIR=/tmp/nx-socket
|
|
|
|
echo "🧩 Using pnpm via corepack"
|
|
corepack enable
|
|
corepack prepare pnpm@8.15.4 --activate
|
|
|
|
echo "📦 Installing dependencies with pnpm"
|
|
pnpm install --frozen-lockfile
|
|
|
|
coverage_dirs=()
|
|
html_dirs=()
|
|
|
|
for targetProject in "$@"; do
|
|
echo "🔍 Running ESLint for project: $targetProject"
|
|
pnpm nx lint $targetProject
|
|
|
|
echo "🧪 Running Jest tests for project: $targetProject with coverage"
|
|
pnpm nx test $targetProject --code-coverage
|
|
|
|
COVERAGE_DIR="coverage/$targetProject"
|
|
HTML_DIR="$COVERAGE_DIR/lcov-report"
|
|
|
|
coverage_dirs+=("\"$COVERAGE_DIR\"")
|
|
html_dirs+=("\"$HTML_DIR\"")
|
|
|
|
if [ -d "$HTML_DIR" ]; then
|
|
echo "📄 HTML coverage report generated at $HTML_DIR"
|
|
else
|
|
echo "⚠️ HTML coverage report not found"
|
|
fi
|
|
done
|
|
|
|
echo -n "[${coverage_dirs[*]}]" > /tekton/results/coverage-dir
|
|
echo -n "[${html_dirs[*]}]" > /tekton/results/coverage-html
|
|
|
|
args:
|
|
- "$(params.targetProjects[*])" |