tekton-hub/tasks/pytest/task.yaml
2025-04-10 06:00:56 +00:00

70 lines
2.0 KiB
YAML

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: pytest
spec:
params:
- name: subdirectory
type: string
description: Subdirectory within the workspace where the tests are located
default: "" # 기본값을 빈 문자열로 설정, 필요 시 repo로 변경
- name: python-version
type: string
description: Python version to use (e.g., 3.9, 3.11)
default: "3.9"
workspaces:
- name: source
description: Workspace containing the cloned Git repository from git-clone-checkout
steps:
- name: install-dependencies
image: python:$(params.python-version)-slim
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
pip install --upgrade pip
pip install pytest
if [ -f pyproject.toml ]; then
pip install poetry
poetry config virtualenvs.in-project true
poetry lock --no-cache --regenerate
poetry install --no-root
elif [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
- name: run-tests
image: python:$(params.python-version)-slim
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
if [ -f pyproject.toml ]; then
poetry run pytest --verbose --junitxml=/workspace/source/pytest-results.xml
else
pytest --verbose --junitxml=/workspace/source/pytest-results.xml
fi
onError: continue
- name: check-results
image: ubuntu
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
if [ -f pytest-results.xml ]; then
echo "Test results generated: pytest-results.xml"
cat pytest-results.xml
else
echo "No test results found."
exit 1
fi