apiVersion: tekton.dev/v1 kind: Task metadata: name: pyversion 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: imageName type: string description: Python image to use (e.g., python:3.9, python:3.11) default: "python:3.11-slim" workspaces: - name: source description: Source 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.imageName) 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 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