apiVersion: tekton.dev/v1 kind: Task metadata: name: pyversion 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: pythonImageName type: string description: Python image to use (e.g., python:3.9, python:3.11) default: "python:3.11-slim" workspaces: - name: base description: shared code workspace (includes pyproject.toml) results: - name: version description: Extracted project version with 'v' prefix (e.g. v0.2.0) steps: - name: verify-tag image: $(params.pythonImageName) workingDir: /workspace/base/$(params.context)/source 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 pyproject.toml..." pip install --quiet tomli VERSION=$(python3 -c 'import tomli; print(tomli.load(open("pyproject.toml", "rb"))["tool"]["poetry"]["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: $TAG_FROM_PROJECT" echo -n "$TAG_FROM_PROJECT" > /tekton/results/version