tekton-hub/tasks/pytest/task.yaml
2025-04-09 07:13:32 +00:00

71 lines
2.3 KiB
YAML

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: pytest
spec:
params:
- name: subdirectory
type: string
description: Subdirectory within the repo where the tests are located
default: ""
- 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
ls -al /workspace/source
if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory)
fi
pip install --upgrade pip
# Poetry가 있는 경우 설치 및 의존성 처리
if [ -f pyproject.toml ]; then
echo "Detected Poetry project (pyproject.toml found)"
pip install poetry
poetry config virtualenvs.in-project true
poetry install --no-root
# Pip fallback (requirements.txt)
elif [ -f requirements.txt ]; then
echo "Detected Pip project (requirements.txt found)"
pip install -r requirements.txt
else
echo "No dependency file found, installing pytest only"
fi
pip install pytest # pytest는 항상 설치
- 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
# Poetry가 사용된 경우 가상환경에서 실행
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