apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: pypi spec: params: - name: build-artifact-path type: string description: Path to the built artifact directory from python-build - name: python-version type: string description: Python version to use (e.g., 3.9, 3.11) default: "3.9" - name: pypi-username type: string description: PyPI username (fallback) default: "" - name: pypi-password type: string description: PyPI password or token (fallback) default: "" - name: pypi-hosted-url type: string description: PyPI repository URL (upload endpoint) default: https://upload.pypi.org/legacy/ - name: pypi-group-url type: string description: PyPI repository URL (install endpoint) default: https://upload.pypi.org/legacy/ workspaces: - name: source description: Workspace containing the built artifacts - name: pypi-auth optional: true description: | Optional workspace containing: - username - password steps: - name: upload-to-pypi image: python:$(params.python-version)-slim workingDir: /workspace/source script: | #!/usr/bin/env bash set -e pip install --upgrade pip pip install poetry twine # 기본값 (params) TWINE_USERNAME="$(params.pypi-username)" TWINE_PASSWORD="$(params.pypi-password)" HOSTED_URL="$(params.pypi-hosted-url)" GROUP_URL="$(params.pypi-group-url)" # pypi-auth workspace에 있으면 override if [ -f /workspace/pypi-auth/username ]; then TWINE_USERNAME=$(cat /workspace/pypi-auth/username) fi if [ -f /workspace/pypi-auth/password ]; then TWINE_PASSWORD=$(cat /workspace/pypi-auth/password) fi echo "[INFO] Twine Upload URL: $HOSTED_URL" # poetry config (install용 group-url 사용) if [ -f pyproject.toml ]; then REPO_NAME=$(echo "$GROUP_URL" | sed -E 's#https?://([^/]+)/repository/([^/]+)/?.*#\1_\2#' | tr -cd '[:alnum:]_') echo "[INFO] Configuring poetry install repo: $REPO_NAME -> $GROUP_URL" poetry config repositories."$REPO_NAME" "$GROUP_URL" poetry config http-basic."$REPO_NAME" "$TWINE_USERNAME" "$TWINE_PASSWORD" fi echo "[INFO] Uploading artifacts with Twine..." twine upload \ --repository-url "$HOSTED_URL" \ --username "$TWINE_USERNAME" \ --password "$TWINE_PASSWORD" \ "$(params.build-artifact-path)"/* echo "[INFO] Successfully uploaded to PyPI"