This commit is contained in:
병준 박 2025-04-10 14:02:12 +00:00
parent 9cf2952c24
commit ad02f5622c
4 changed files with 232 additions and 47 deletions

View File

@ -8,41 +8,87 @@ spec:
type: string type: string
description: Subdirectory within the repo where the source code is located description: Subdirectory within the repo where the source code is located
default: "" default: ""
- name: python-version - name: python-version
type: string type: string
description: Python version to use (e.g., 3.9, 3.11) description: Python version to use (e.g., 3.9, 3.11)
default: "3.9" 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-group-url
type: string
description: PyPI repository URL (install endpoint)
default: https://upload.pypi.org/legacy/
workspaces: workspaces:
- name: source - name: source
description: Workspace containing the cloned Git repository from git-clone-checkout 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: results:
- name: build-artifact-path - name: build-artifact-path
description: Path to the built artifact directory (e.g., dist/) description: Path to the built artifact directory (e.g., dist/)
steps: steps:
- name: install-dependencies - name: install-dependencies
image: python:$(params.python-version)-slim image: python:$(params.python-version)-slim
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ -n "$(params.subdirectory)" ]; then if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory) cd "$(params.subdirectory)"
fi fi
pip install --upgrade pip pip install --upgrade pip
# Poetry가 있는 경우 설치 및 의존성 처리
PYPI_USER="$(params.pypi-username)"
PYPI_PASS="$(params.pypi-password)"
PYPI_URL="$(params.pypi-group-url)"
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 if [ -f pyproject.toml ]; then
echo "Detected Poetry project (pyproject.toml found)" echo "[INFO] Poetry project detected"
pip install poetry pip install poetry
poetry config virtualenvs.in-project true poetry config virtualenvs.in-project true
if [ -n "$PYPI_URL" ]; then
REPO_NAME=$(echo "$PYPI_URL" | sed -E 's#https?://([^/]+)/repository/([^/]+)/?.*#\1_\2#' | tr -cd '[:alnum:]_')
echo "[INFO] Configuring poetry source '$REPO_NAME' → $PYPI_URL"
poetry config repositories."$REPO_NAME" "$PYPI_URL"
poetry config http-basic."$REPO_NAME" "$PYPI_USER" "$PYPI_PASS"
fi
poetry install --no-root poetry install --no-root
# Pip fallback (requirements.txt 및 setup.py)
elif [ -f requirements.txt ] && [ -f setup.py ]; then elif [ -f requirements.txt ] && [ -f setup.py ]; then
echo "Detected Pip project (requirements.txt and setup.py found)" echo "[INFO] Pip + setup.py project detected"
pip install -r requirements.txt pip install -r requirements.txt
pip install build pip install build
else else
echo "Error: No valid build configuration found (pyproject.toml or setup.py required)" echo "[ERROR] No valid build configuration found (pyproject.toml or setup.py required)"
exit 1 exit 1
fi fi
@ -51,39 +97,39 @@ spec:
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ -n "$(params.subdirectory)" ]; then if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory) cd "$(params.subdirectory)"
fi fi
# Poetry가 사용된 경우
if [ -f pyproject.toml ]; then if [ -f pyproject.toml ]; then
poetry build poetry build
echo "Built artifacts located in dist/"
ls -l dist/
# Pip 및 setup.py 사용
elif [ -f setup.py ]; then elif [ -f setup.py ]; then
python -m build python -m build
echo "Built artifacts located in dist/"
ls -l dist/
else else
echo "Error: No build tool available" echo "[ERROR] No build tool available"
exit 1 exit 1
fi fi
# 빌드 결과 경로를 결과로 저장 echo "Built artifacts located in dist/"
ls -l dist/
# Save result path
echo -n "/workspace/source/$(params.subdirectory)/dist" > /tekton/results/build-artifact-path echo -n "/workspace/source/$(params.subdirectory)/dist" > /tekton/results/build-artifact-path
- name: verify-build - name: verify-build
image: ubuntu image: ubuntu
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
DIST_PATH=$(cat /tekton/results/build-artifact-path) DIST_PATH=$(cat /tekton/results/build-artifact-path)
if [ -d "$DIST_PATH" ] && [ -n "$(ls -A $DIST_PATH)" ]; then if [ -d "$DIST_PATH" ] && [ -n "$(ls -A $DIST_PATH)" ]; then
echo "Build artifacts successfully created in $DIST_PATH:" echo "Build artifacts successfully created in $DIST_PATH:"
ls -l $DIST_PATH ls -l $DIST_PATH
else else
echo "Error: No build artifacts found in $DIST_PATH" echo " No build artifacts found in $DIST_PATH"
exit 1 exit 1
fi fi

View File

@ -8,44 +8,90 @@ spec:
type: string type: string
description: Subdirectory within the repo where the source code is located description: Subdirectory within the repo where the source code is located
default: "" default: ""
- name: python-version - name: python-version
type: string type: string
description: Python version to use (e.g., 3.9, 3.11) description: Python version to use (e.g., 3.9, 3.11)
default: "3.9" default: "3.9"
- name: pylint-args - name: pylint-args
type: string type: string
description: Additional arguments for pylint (e.g., --fail-under=8) description: Additional arguments for pylint (e.g., --fail-under=8)
default: "" default: ""
- name: pypi-username
type: string
description: PyPI username (fallback)
default: ""
- name: pypi-password
type: string
description: PyPI password or token (fallback)
default: ""
- name: pypi-group-url
type: string
description: PyPI repository URL (install endpoint)
default: https://upload.pypi.org/legacy/
workspaces: workspaces:
- name: source - name: source
description: Workspace containing the cloned Git repository from git-clone-checkout 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
steps: steps:
- name: install-dependencies - name: install-dependencies
image: python:$(params.python-version)-slim image: python:$(params.python-version)-slim
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ -n "$(params.subdirectory)" ]; then if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory) cd "$(params.subdirectory)"
fi fi
pip install --upgrade pip pip install --upgrade pip
# Poetry가 있는 경우 설치 및 의존성 처리 PYPI_USER="$(params.pypi-username)"
PYPI_PASS="$(params.pypi-password)"
PYPI_URL="$(params.pypi-group-url)"
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 if [ -f pyproject.toml ]; then
echo "Detected Poetry project (pyproject.toml found)" echo "[INFO] Poetry project detected"
pip install poetry pip install poetry
poetry config virtualenvs.in-project true poetry config virtualenvs.in-project true
if [ -n "$PYPI_URL" ]; then
REPO_NAME=$(echo "$PYPI_URL" | sed -E 's#https?://([^/]+)/repository/([^/]+)/?.*#\1_\2#' | tr -cd '[:alnum:]_')
echo "[INFO] Configuring poetry source '$REPO_NAME' with URL: $PYPI_URL"
poetry config repositories."$REPO_NAME" "$PYPI_URL"
poetry config http-basic."$REPO_NAME" "$PYPI_USER" "$PYPI_PASS"
fi
poetry install --no-root poetry install --no-root
poetry add pylint --group dev # Pylint를 개발 의존성으로 추가 poetry add pylint --group dev
# Pip fallback (requirements.txt)
elif [ -f requirements.txt ]; then elif [ -f requirements.txt ]; then
echo "Detected Pip project (requirements.txt found)" echo "[INFO] Pip project detected"
pip install -r requirements.txt pip install -r requirements.txt
pip install pylint pip install pylint
else else
echo "No dependency file found, installing pylint only" echo "[INFO] No dependency file found, installing pylint only"
pip install pylint pip install pylint
fi fi
@ -54,24 +100,22 @@ spec:
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ -n "$(params.subdirectory)" ]; then if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory) cd "$(params.subdirectory)"
fi fi
# Poetry가 사용된 경우 가상환경에서 실행
if [ -f pyproject.toml ]; then if [ -f pyproject.toml ]; then
poetry run pylint $(params.pylint-args) . poetry run pylint $(params.pylint-args) .
else else
pylint $(params.pylint-args) . pylint $(params.pylint-args) .
fi fi
onError: continue # 린트 실패 시에도 파이프라인을 중단하지 않음 (선택적) onError: continue # 린트 실패해도 실패로 간주하지 않음
- name: check-results - name: check-results
image: ubuntu image: ubuntu
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
echo "Pylint execution completed." echo "Pylint execution completed."
# Pylint 결과를 별도 파일로 저장하려면 run-lint에서 --output 옵션 추가 필요

View File

@ -7,38 +7,83 @@ spec:
- name: build-artifact-path - name: build-artifact-path
type: string type: string
description: Path to the built artifact directory from python-build description: Path to the built artifact directory from python-build
- name: python-version - name: python-version
type: string type: string
description: Python version to use (e.g., 3.9, 3.11) description: Python version to use (e.g., 3.9, 3.11)
default: "3.9" default: "3.9"
- name: pypi-username - name: pypi-username
type: string type: string
description: PyPI username (e.g., __token__ for token-based auth) description: PyPI username (fallback)
default: ""
- name: pypi-password - name: pypi-password
type: string type: string
description: PyPI password or token description: PyPI password or token (fallback)
- name: pypi-repository-url default: ""
- name: pypi-hosted-url
type: string type: string
description: PyPI repository URL description: PyPI repository URL (upload endpoint)
default: https://upload.pypi.org/legacy/ 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: workspaces:
- name: source - name: source
description: Workspace containing the built artifacts description: Workspace containing the built artifacts
- name: pypi-auth
optional: true
description: |
Optional workspace containing:
- username
- password
steps: steps:
- name: upload-to-pypi - name: upload-to-pypi
image: python:$(params.python-version)-slim image: python:$(params.python-version)-slim
workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
pip install twine pip install --upgrade pip
twine upload \ pip install poetry twine
--repository-url "$(params.pypi-repository-url)" \
--username "$(params.pypi-username)" \ # 기본값 (params)
--password "$(params.pypi-password)" \ TWINE_USERNAME="$(params.pypi-username)"
"$(params.build-artifact-path)"/* TWINE_PASSWORD="$(params.pypi-password)"
if [ $? -eq 0 ]; then HOSTED_URL="$(params.pypi-hosted-url)"
echo "Successfully uploaded to PyPI" GROUP_URL="$(params.pypi-group-url)"
else
echo "Failed to upload to PyPI" # pypi-auth workspace에 있으면 override
exit 1 if [ -f /workspace/pypi-auth/username ]; then
TWINE_USERNAME=$(cat /workspace/pypi-auth/username)
fi 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"

View File

@ -7,34 +7,82 @@ spec:
- name: subdirectory - name: subdirectory
type: string type: string
description: Subdirectory within the workspace where the tests are located description: Subdirectory within the workspace where the tests are located
default: "" # 기본값을 빈 문자열로 설정, 필요 시 repo로 변경 default: ""
- name: python-version - name: python-version
type: string type: string
description: Python version to use (e.g., 3.9, 3.11) description: Python version to use (e.g., 3.9, 3.11)
default: "3.9" 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-group-url
type: string
description: PyPI repository URL (install endpoint)
default: https://upload.pypi.org/legacy/
workspaces: workspaces:
- name: source - name: source
description: Workspace containing the cloned Git repository from git-clone-checkout 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
steps: steps:
- name: install-dependencies - name: install-dependencies
image: python:$(params.python-version)-slim image: python:$(params.python-version)-slim
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ -n "$(params.subdirectory)" ]; then if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory) cd "$(params.subdirectory)"
fi fi
pip install --upgrade pip pip install --upgrade pip
pip install pytest pip install pytest
if [ -f pyproject.toml ]; then if [ -f pyproject.toml ]; then
echo "[INFO] Using Poetry to install dependencies"
pip install poetry pip install poetry
poetry config virtualenvs.in-project true poetry config virtualenvs.in-project true
poetry lock --no-cache --regenerate poetry lock --no-cache --regenerate
PYPI_USER="$(params.pypi-username)"
PYPI_PASS="$(params.pypi-password)"
PYPI_URL="$(params.pypi-group-url)"
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 [ -n "$PYPI_URL" ]; then
REPO_NAME=$(echo "$PYPI_URL" | sed -E 's#https?://([^/]+)/repository/([^/]+)/?.*#\1_\2#' | tr -cd '[:alnum:]_')
echo "[INFO] Configuring poetry source '$REPO_NAME': $PYPI_URL"
poetry config repositories."$REPO_NAME" "$PYPI_URL"
poetry config http-basic."$REPO_NAME" "$PYPI_USER" "$PYPI_PASS"
fi
poetry install --no-root poetry install --no-root
elif [ -f requirements.txt ]; then elif [ -f requirements.txt ]; then
echo "[INFO] Using pip to install dependencies"
pip install -r requirements.txt pip install -r requirements.txt
fi fi
@ -43,9 +91,10 @@ spec:
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ -n "$(params.subdirectory)" ]; then if [ -n "$(params.subdirectory)" ]; then
cd $(params.subdirectory) cd "$(params.subdirectory)"
fi fi
if [ -f pyproject.toml ]; then if [ -f pyproject.toml ]; then
@ -60,6 +109,7 @@ spec:
workingDir: /workspace/source workingDir: /workspace/source
script: | script: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ -f pytest-results.xml ]; then if [ -f pytest-results.xml ]; then
echo "Test results generated: pytest-results.xml" echo "Test results generated: pytest-results.xml"