74 lines
2.0 KiB
YAML
74 lines
2.0 KiB
YAML
apiVersion: tekton.dev/v1
|
|
kind: Task
|
|
metadata:
|
|
name: nx-nodejs-analysis
|
|
spec:
|
|
params:
|
|
- name: home
|
|
type: string
|
|
description: home directory
|
|
default: ""
|
|
|
|
- name: workshop
|
|
type: string
|
|
description: workshop within the repo where the source code is located
|
|
default: ""
|
|
|
|
- name: targetProject
|
|
type: string
|
|
description: Nx workspace project name to lint and test
|
|
|
|
- name: nodejsImageName
|
|
type: string
|
|
default: "node:slim"
|
|
description: Node.js image (e.g., node:18-slim)
|
|
|
|
workspaces:
|
|
- name: shared
|
|
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/shared/$(params.workshop)
|
|
env:
|
|
- name: HOME
|
|
value: /workspace/shared/$(params.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
|
|
|
|
echo "🔍 Running ESLint for project: $(params.targetProject)"
|
|
pnpm nx lint $(params.targetProject)
|
|
|
|
echo "🧪 Running Jest tests for project: $(params.targetProject) with coverage"
|
|
pnpm 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
|