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: debug-workspace # image: ubuntu # workingDir: /workspace/source # script: | # #!/usr/bin/env bash # if [ -n "$(params.subdirectory)" ]; then # if [ -d "$(params.subdirectory)" ]; then # echo "Subdirectory $(params.subdirectory) exists:" # ls -la $(params.subdirectory) # else # echo "Subdirectory $(params.subdirectory) not found!" # exit 1 # fi # fi - 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