apiVersion: tekton.dev/v1 kind: Task metadata: name: nx-nodejs-version spec: params: - name: context type: string description: context directory default: "" - 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..." VERSION=$(node -p "require('./package.json').version") TAG_FROM_PROJECT="${VERSION}" echo "🔁 Comparing Git tag and project version:" echo " - Git ref tag: $TAG_FROM_REF" echo " - Project version: $TAG_FROM_PROJECT" if [ "$TAG_FROM_REF" != "$TAG_FROM_PROJECT" ]; then echo "❌ Mismatch! Git tag and project version are not the same." exit 1 fi echo "✅ Tag and version match: $VERSION" echo -n "$VERSION" > /tekton/results/version