apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: pybuild spec: params: - name: subdirectory type: string description: Subdirectory within the repo where the source code is 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 results: - name: build-artifact-path description: Path to the built artifact directory (e.g., dist/) 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 # 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 및 setup.py) elif [ -f requirements.txt ] && [ -f setup.py ]; then echo "Detected Pip project (requirements.txt and setup.py found)" pip install -r requirements.txt pip install build else echo "Error: No valid build configuration found (pyproject.toml or setup.py required)" exit 1 fi - name: build-package 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 build echo "Built artifacts located in dist/" ls -l dist/ # Pip 및 setup.py 사용 elif [ -f setup.py ]; then python -m build echo "Built artifacts located in dist/" ls -l dist/ else echo "Error: No build tool available" exit 1 fi # 빌드 결과 경로를 결과로 저장 echo -n "/workspace/source/$(params.subdirectory)/dist" > /tekton/results/build-artifact-path - name: verify-build image: ubuntu workingDir: /workspace/source script: | #!/usr/bin/env bash DIST_PATH=$(cat /tekton/results/build-artifact-path) if [ -d "$DIST_PATH" ] && [ -n "$(ls -A $DIST_PATH)" ]; then echo "Build artifacts successfully created in $DIST_PATH:" ls -l $DIST_PATH else echo "Error: No build artifacts found in $DIST_PATH" exit 1 fi