82 lines
2.3 KiB
YAML
82 lines
2.3 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: nodejsImageName
|
|
type: string
|
|
default: "node:slim"
|
|
description: Node.js image (e.g., node:18-slim)
|
|
|
|
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: $(params.nodejsImageName)
|
|
workingDir: /workspace/source
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
if [ -n "$(params.subdirectory)" ]; then
|
|
cd "$(params.subdirectory)"
|
|
fi
|
|
|
|
echo "🧩 Using pnpm via corepack"
|
|
corepack enable
|
|
corepack prepare pnpm@8.15.4 --activate
|
|
|
|
echo "🔐 Checking for private npm credentials"
|
|
if [ -f /workspace/npm-auth/.npmrc ]; then
|
|
echo "✅ Found .npmrc"
|
|
cp /workspace/npm-auth/.npmrc ~/.npmrc
|
|
fi
|
|
|
|
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
|