init
This commit is contained in:
parent
398b514490
commit
1fd5e1be1d
@ -16,18 +16,18 @@ spec:
|
|||||||
type: string
|
type: string
|
||||||
description: Nx workspace name to lint and test
|
description: Nx workspace name to lint and test
|
||||||
- name: targetProjects
|
- name: targetProjects
|
||||||
type: array
|
type: string
|
||||||
description: Nx workspace project names to lint and test
|
description: Comma-separated list of Nx workspace project names to lint and test (e.g., "api-client-request,openapi-project")
|
||||||
workspaces:
|
workspaces:
|
||||||
- name: base
|
- name: base
|
||||||
description: Git-cloned source code with Nx monorepo
|
description: Git-cloned source code with Nx monorepo
|
||||||
results:
|
results:
|
||||||
- name: coverage-dir
|
- name: coverage-dir
|
||||||
description: Path to generated coverage directory
|
description: Comma-separated paths to generated coverage directories
|
||||||
- name: coverage-html
|
- name: coverage-html
|
||||||
description: Path to generated HTML coverage report directory
|
description: Comma-separated paths to generated HTML coverage report directories
|
||||||
steps:
|
steps:
|
||||||
- name: lint-test-coverage
|
- name: install-dependencies
|
||||||
image: rust:1.75-slim
|
image: rust:1.75-slim
|
||||||
workingDir: /workspace/base/$(params.context)/$(params.source)/$(params.workspaceName)
|
workingDir: /workspace/base/$(params.context)/$(params.source)/$(params.workspaceName)
|
||||||
env:
|
env:
|
||||||
@ -37,8 +37,8 @@ spec:
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Install dependencies
|
# Install system dependencies
|
||||||
apt-get update && apt-get install -y curl libssl-dev pkg-config build-essential
|
apt-get update && apt-get install -y curl libssl-dev pkg-config build-essential jq
|
||||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||||
apt-get install -y nodejs
|
apt-get install -y nodejs
|
||||||
|
|
||||||
@ -59,48 +59,62 @@ spec:
|
|||||||
node --version
|
node --version
|
||||||
npm --version
|
npm --version
|
||||||
pnpm --version
|
pnpm --version
|
||||||
|
- name: lint-test-coverage
|
||||||
|
image: rust:1.75-slim
|
||||||
|
workingDir: /workspace/base/$(params.context)/$(params.source)/$(params.workspaceName)
|
||||||
|
env:
|
||||||
|
- name: HOME
|
||||||
|
value: /workspace/base/$(params.context)/home
|
||||||
|
script: |
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
export NX_SOCKET_DIR=/tmp/nx-socket
|
export NX_SOCKET_DIR=/tmp/nx-socket
|
||||||
|
|
||||||
# Initialize result arrays
|
# Convert comma-separated targetProjects to space-separated for Bash
|
||||||
coverage_dirs=()
|
PROJECTS=$(echo "$(params.targetProjects)" | tr ',' ' ')
|
||||||
html_dirs=()
|
|
||||||
|
|
||||||
# Run lint, test, and coverage in parallel using nx run-many
|
# Run lint and test in parallel using nx run-many
|
||||||
echo "🔍 Running lint, test, and coverage for projects: $(params.targetProjects[*])"
|
echo "🔍 Running lint for projects: $PROJECTS"
|
||||||
|
pnpm nx run-many --target=lint --projects="$(params.targetProjects)" --parallel=4
|
||||||
|
|
||||||
# Lint (cargo clippy via nx)
|
echo "🧪 Running tests for projects: $PROJECTS"
|
||||||
pnpm nx run-many --target=lint --projects=$(params.targetProjects[*]) --parallel=4
|
pnpm nx run-many --target=test --projects="$(params.targetProjects)" --parallel=4
|
||||||
|
|
||||||
# Test (cargo test via nx)
|
# Initialize result variables
|
||||||
pnpm nx run-many --target=test --projects=$(params.targetProjects[*]) --parallel=4
|
COVERAGE_DIRS=""
|
||||||
|
HTML_DIRS=""
|
||||||
|
|
||||||
# Coverage (cargo-tarpaulin)
|
# Run coverage for each project
|
||||||
for targetProject in "${@:1}"; do
|
for project in $PROJECTS; do
|
||||||
echo "🧪 Generating coverage for project: $targetProject"
|
echo "📊 Generating coverage for project: $project"
|
||||||
PROJECT_PATH=$(pnpm nx show project $targetProject --json | jq -r '.root')
|
PROJECT_PATH=$(pnpm nx show project "$project" --json | jq -r '.root')
|
||||||
cd "$PROJECT_PATH"
|
cd "$PROJECT_PATH"
|
||||||
|
|
||||||
# Run tarpaulin for coverage
|
# Run tarpaulin for coverage
|
||||||
cargo tarpaulin --out Html --output-dir coverage --timeout 120
|
cargo tarpaulin --out Html --output-dir coverage --timeout 120
|
||||||
|
|
||||||
COVERAGE_DIR="coverage"
|
COVERAGE_DIR="coverage"
|
||||||
HTML_DIR="$COVERAGE_DIR/html"
|
HTML_DIR="$COVERAGE_DIR/html"
|
||||||
|
|
||||||
coverage_dirs+=("\"$PROJECT_PATH/$COVERAGE_DIR\"")
|
# Append to results (comma-separated)
|
||||||
html_dirs+=("\"$PROJECT_PATH/$HTML_DIR\"")
|
if [ -z "$COVERAGE_DIRS" ]; then
|
||||||
|
COVERAGE_DIRS="$PROJECT_PATH/$COVERAGE_DIR"
|
||||||
|
HTML_DIRS="$PROJECT_PATH/$HTML_DIR"
|
||||||
|
else
|
||||||
|
COVERAGE_DIRS="$COVERAGE_DIRS,$PROJECT_PATH/$COVERAGE_DIR"
|
||||||
|
HTML_DIRS="$HTML_DIRS,$PROJECT_PATH/$HTML_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -d "$HTML_DIR" ]; then
|
if [ -d "$HTML_DIR" ]; then
|
||||||
echo "📄 HTML coverage report generated at $HTML_DIR"
|
echo "📄 HTML coverage report generated at $HTML_DIR"
|
||||||
else
|
else
|
||||||
echo "⚠️ HTML coverage report not found for $targetProject"
|
echo "⚠️ HTML coverage report not found for $project"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd /workspace/base/$(params.context)/$(params.source)/$(params.workspaceName)
|
cd /workspace/base/$(params.context)/$(params.source)/$(params.workspaceName)
|
||||||
done
|
done
|
||||||
|
|
||||||
# Write results to Tekton results
|
# Write results to Tekton results
|
||||||
echo "[${coverage_dirs[*]}]" > /tekton/results/coverage-dir
|
echo "$COVERAGE_DIRS" > /tekton/results/coverage-dir
|
||||||
echo "[${html_dirs[*]}]" > /tekton/results/coverage-html
|
echo "$HTML_DIRS" > /tekton/results/coverage-html
|
||||||
args:
|
|
||||||
- "$(params.targetProjects[*])"
|
|
Loading…
x
Reference in New Issue
Block a user