apiVersion: tekton.dev/v1 kind: Task metadata: name: nx-nodejs-version spec: params: - name: subdirectory type: string description: Subdirectory within the repo where the source code is located default: "" - name: ref type: string description: Full Git ref string (e.g., refs/tags/v0.2.0) - name: node-version type: string description: Node.js version to use default: "18" workspaces: - name: source description: Git-cloned source code results: - name: version description: Extracted project version (e.g. 0.2.0) steps: - name: verify-tag-version image: node:$(params.node-version) workingDir: /workspace/source script: | #!/usr/bin/env bash set -e if [ -n "$(params.subdirectory)" ]; then cd $(params.subdirectory) fi 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