tekton-hub/tasks/pytest/task.yaml
2025-04-16 02:36:41 +00:00

76 lines
2.1 KiB
YAML

apiVersion: tekton.dev/v1
kind: Task
metadata:
name: pytest
spec:
params:
- name: home
type: string
description: home directory
default: ""
- name: workshop
type: string
description: workshop within the workspace where the tests are located
default: ""
- name: pythonImageName
type: string
description: Python version to use (e.g., 3.9, 3.11)
default: "python:3.11-slim"
workspaces:
- name: shared
description: Workspace containing the cloned Git repository from git-clone-checkout
steps:
- name: install-dependencies
image: $(params.pythonImageName)
workingDir: /workspace/shared/$(params.workshop)
env:
- name: HOME
value: /workspace/shared/$(params.home)
script: |
#!/usr/bin/env bash
set -e
echo "🔧 Installing dependencies..."
pip install --upgrade pip --root-user-action=ignore
pip install pytest --root-user-action=ignore
if [ -f pyproject.toml ]; then
echo "[INFO] Poetry project detected"
pip install poetry --root-user-action=ignore
echo "[INFO] Using pre-configured poetry settings from $HOME/.config/pypoetry/"
poetry lock --no-cache
poetry install
elif [ -f requirements.txt ]; then
echo "[INFO] Using pip to install dependencies"
pip install -r requirements.txt --root-user-action=ignore
else
echo "[WARN] No dependency file found"
fi
echo "🧪 Running tests..."
set +e
if [ -f pyproject.toml ]; then
poetry run pytest --verbose --junitxml=/workspace/shared/pytest-results.xml
else
pytest --verbose --junitxml=/workspace/shared/pytest-results.xml
fi
TEST_EXIT_CODE=$?
set -e
echo "📄 Checking test results..."
if [ -f /workspace/shared/pytest-results.xml ]; then
echo "Test results:"
cat /workspace/shared/pytest-results.xml
else
echo "❌ No test results found"
exit 1
fi
exit $TEST_EXIT_CODE