tekton-hub/tasks/pypi/task.yaml
2025-04-12 13:16:20 +00:00

85 lines
2.6 KiB
YAML

apiVersion: tekton.dev/v1
kind: Task
metadata:
name: pypi
spec:
params:
- name: build-artifact-path
type: string
description: Path to the built artifact directory from python-build
- name: imageName
type: string
description: Python version to use (e.g., 3.9, 3.11)
default: "python:3.11-slim"
- 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 for upload
default: https://upload.pypi.org/legacy/
workspaces:
- name: source
description: Workspace containing the built artifacts
- name: pypi-auth
optional: true
description: |
A workspace containing:
- username
- password
steps:
- name: upload-to-pypi
image: $(params.imageName)
workingDir: /workspace/source
script: |
#!/usr/bin/env bash
set -e
TWINE_USERNAME="$(params.pypi-username)"
TWINE_PASSWORD="$(params.pypi-password)"
HOSTED_URL="$(params.pypi-hosted-url)"
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
pip install --upgrade pip --root-user-action=ignore
pip install poetry twine --root-user-action=ignore
# poetry 설정이 필요한 경우 pyproject.toml 분석
if [ -f pyproject.toml ]; then
echo "[INFO] Using Poetry to install dependencies"
pip install poetry tomli --root-user-action=ignore
REPO_NAME=$(python3 -c 'import tomli; print(tomli.load(open("pyproject.toml", "rb"))["tool"]["poetry"]["source"][0]["name"])')
REPO_URL=$(python3 -c 'import tomli; print(tomli.load(open("pyproject.toml", "rb"))["tool"]["poetry"]["source"][0]["url"])')
echo "[INFO] Configuring poetry source '$REPO_NAME' → $REPO_URL"
poetry config virtualenvs.in-project true
poetry config repositories."$REPO_NAME" "$REPO_URL"
poetry config http-basic."$REPO_NAME" "$TWINE_USERNAME" "$TWINE_PASSWORD"
fi
echo "[INFO] Uploading artifacts to $HOSTED_URL"
twine upload \
--repository-url "$HOSTED_URL" \
--username "$TWINE_USERNAME" \
--password "$TWINE_PASSWORD" \
"$(params.build-artifact-path)"/*
echo "[INFO] ✅ Upload to PyPI complete"