130 lines
3.9 KiB
YAML
130 lines
3.9 KiB
YAML
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"
|
|
|
|
- name: pypi-username
|
|
type: string
|
|
description: PyPI username (fallback)
|
|
default: ""
|
|
|
|
- name: pypi-password
|
|
type: string
|
|
description: PyPI password or token (fallback)
|
|
default: ""
|
|
|
|
workspaces:
|
|
- name: source
|
|
description: Workspace containing the cloned Git repository from git-clone-checkout
|
|
|
|
- name: pypi-auth
|
|
optional: true
|
|
description: |
|
|
A workspace containing authentication credentials for a private PyPI repository.
|
|
Should include:
|
|
- username
|
|
- password
|
|
|
|
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
|
|
set -e
|
|
|
|
if [ -n "$(params.subdirectory)" ]; then
|
|
cd "$(params.subdirectory)"
|
|
fi
|
|
|
|
pip install --upgrade pip --root-user-action=ignore
|
|
|
|
PYPI_USER="$(params.pypi-username)"
|
|
PYPI_PASS="$(params.pypi-password)"
|
|
|
|
if [ -f /workspace/pypi-auth/username ]; then
|
|
PYPI_USER=$(cat /workspace/pypi-auth/username)
|
|
fi
|
|
if [ -f /workspace/pypi-auth/password ]; then
|
|
PYPI_PASS=$(cat /workspace/pypi-auth/password)
|
|
fi
|
|
|
|
if [ -f pyproject.toml ]; then
|
|
echo "[INFO] Poetry project detected"
|
|
pip install poetry tomli --root-user-action=ignore
|
|
poetry config virtualenvs.in-project true
|
|
|
|
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 repositories."$REPO_NAME" "$REPO_URL"
|
|
poetry config http-basic."$REPO_NAME" "$PYPI_USER" "$PYPI_PASS"
|
|
|
|
poetry install --no-root
|
|
|
|
elif [ -f requirements.txt ] && [ -f setup.py ]; then
|
|
echo "[INFO] Pip + setup.py project detected"
|
|
pip install -r requirements.txt --root-user-action=ignore
|
|
pip install build --root-user-action=ignore
|
|
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
|
|
set -e
|
|
|
|
if [ -n "$(params.subdirectory)" ]; then
|
|
cd "$(params.subdirectory)"
|
|
fi
|
|
|
|
if [ -f pyproject.toml ]; then
|
|
poetry build
|
|
elif [ -f setup.py ]; then
|
|
python -m build
|
|
else
|
|
echo "[ERROR] No build tool available"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Built artifacts located in dist/"
|
|
ls -l dist/
|
|
|
|
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
|
|
set -e
|
|
|
|
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 "❌ No build artifacts found in $DIST_PATH"
|
|
exit 1
|
|
fi
|