2025-04-25 20:02:32 +00:00

56 lines
1.7 KiB
YAML

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: specDomain
type: string
default: ""
workspaces:
- name: base
description: Git-cloned source code
results:
- name: specDoamin
description: Extracted domain name (e.g. user)
- name: version
description: Extracted project version (e.g. 0.2.0)
steps:
- name: verify-version
image: mikefarah/yq:4.24.2
workingDir: /workspace/base/$(params.context)/source
env:
- name: HOME
value: /workspace/base/$(params.context)/home
script: |
set -e
echo "🔍 Extracting tag from Git ref..."
FULL_REF="$(params.ref)"
DOMAIN_FROM_REF=$(echo "$FULL_REF" | awk -F'[/-]' '{print $2}')
TAG_FROM_REF=$(basename "$FULL_REF") # → 0.2.0
OPENAPI_FILE="specs/$(params.specDomain)/openapi.yaml"
echo "📄 Reading version from openapi.yaml of ${OPENAPI_FILE}..."
VERSION=$(yq '.info.version' "$OPENAPI_FILE")
TAG_FROM_OPENAPI="${VERSION}"
echo "🔁 Comparing Git tag and workspace version:"
echo " - Git ref tag: $TAG_FROM_REF"
echo " - openapi version: $TAG_FROM_OPENAPI"
if [ "$TAG_FROM_REF" != "$TAG_FROM_OPENAPI" ]; then
echo "❌ Mismatch! Git tag and openapi version are not the same."
exit 1
fi
echo "✅ Tag and version match: $VERSION"
echo -n "$DOMAIN_FROM_REF" > /tekton/results/specDoamin
echo -n "$VERSION" > /tekton/results/version