apiVersion: tekton.dev/v1 kind: Task metadata: name: nx-nodejs-version spec: params: - name: context type: string description: context directory default: "" - name: workspaceName type: string description: Nx workspace project name to lint and test - name: ref type: string description: Full Git ref string (e.g., refs/tags/v0.2.0) - name: nodejsImageName type: string default: "node:slim" description: Node.js image (e.g., node:23-slim) workspaces: - name: base description: Git-cloned source code results: - name: version description: Extracted project version (e.g. 0.2.0) steps: - name: verify-tag-version 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 echo "🔍 Extracting tag from Git ref..." FULL_REF="$(params.ref)" TAG_FROM_REF=$(basename "$FULL_REF") # → v0.2.0 echo "📄 Reading version from package.json of $(params.workspaceName)..." VERSION=$(node -p "require('./$(params.workspaceName)/package.json').version") TAG_FROM_WORKSPACE="${VERSION}" echo "🔁 Comparing Git tag and workspace version:" echo " - Git ref tag: $TAG_FROM_REF" echo " - Workspace version: $TAG_FROM_WORKSPACE" if [ "$TAG_FROM_REF" != "$TAG_FROM_WORKSPACE" ]; then echo "❌ Mismatch! Git tag and workspace version are not the same." exit 1 fi echo "✅ Tag and version match: $VERSION" echo -n "$VERSION" > /tekton/results/version