From c16b8fe06bd8d88d6925dae8dad3046971cd7471 Mon Sep 17 00:00:00 2001 From: BAK BYEONG JUN Date: Thu, 10 Apr 2025 15:02:21 +0000 Subject: [PATCH] init --- tasks/pybuild/task.yaml | 60 ++++++++++++++-------------------------- tasks/pylint/task.yaml | 34 ++++++++--------------- tasks/pypi/task.yaml | 10 +++++-- tasks/pytest/task.yaml | 61 +++++++++++++++++------------------------ 4 files changed, 64 insertions(+), 101 deletions(-) diff --git a/tasks/pybuild/task.yaml b/tasks/pybuild/task.yaml index f73dc2e..3b5811d 100644 --- a/tasks/pybuild/task.yaml +++ b/tasks/pybuild/task.yaml @@ -52,8 +52,6 @@ spec: cd "$(params.subdirectory)" fi - pip install --upgrade pip --root-user-action=ignore - PYPI_USER="$(params.pypi-username)" PYPI_PASS="$(params.pypi-password)" @@ -64,66 +62,48 @@ spec: PYPI_PASS=$(cat /workspace/pypi-auth/password) fi + echo "πŸ”§ Installing dependencies..." + pip install --upgrade pip --root-user-action=ignore + 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 virtualenvs.in-project true poetry config repositories."$REPO_NAME" "$REPO_URL" poetry config http-basic."$REPO_NAME" "$PYPI_USER" "$PYPI_PASS" + poetry lock --no-cache --regenerate poetry install --no-root + echo "πŸ“¦ Building package with Poetry..." + poetry build + elif [ -f requirements.txt ] && [ -f setup.py ]; then - echo "[INFO] Pip + setup.py project detected" + echo "[INFO] setup.py project detected" pip install -r requirements.txt --root-user-action=ignore pip install build --root-user-action=ignore + + echo "πŸ“¦ Building package with build module..." + python -m 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 - set -e + echo "πŸ“‚ Verifying built artifacts..." + BUILD_PATH="/workspace/source/$(params.subdirectory)/dist" + echo -n "$BUILD_PATH" > /tekton/results/build-artifact-path - if [ -n "$(params.subdirectory)" ]; then - cd "$(params.subdirectory)" - fi - - if [ -f pyproject.toml ]; then - poetry build - elif [ -f setup.py ]; then - python -m build + if [ -d "$BUILD_PATH" ] && [ -n "$(ls -A $BUILD_PATH)" ]; then + echo "βœ… Build artifacts created in $BUILD_PATH:" + ls -l "$BUILD_PATH" 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" + echo "❌ No build artifacts found in $BUILD_PATH" exit 1 fi diff --git a/tasks/pylint/task.yaml b/tasks/pylint/task.yaml index f13bbb9..72c57de 100644 --- a/tasks/pylint/task.yaml +++ b/tasks/pylint/task.yaml @@ -53,8 +53,6 @@ spec: cd "$(params.subdirectory)" fi - pip install --upgrade pip --root-user-action=ignore - PYPI_USER="$(params.pypi-username)" PYPI_PASS="$(params.pypi-password)" @@ -65,18 +63,22 @@ spec: PYPI_PASS=$(cat /workspace/pypi-auth/password) fi + echo "πŸ”§ Installing dependencies..." + pip install --upgrade pip --root-user-action=ignore + 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" + 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" "$PYPI_USER" "$PYPI_PASS" + poetry lock --no-cache --regenerate poetry install --no-root poetry add pylint --group dev elif [ -f requirements.txt ]; then @@ -88,27 +90,15 @@ spec: pip install pylint --root-user-action=ignore fi - - name: run-lint - 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 - + echo "πŸ§ͺ Running Pylint..." + set +e if [ -f pyproject.toml ]; then poetry run pylint $(params.pylint-args) . else pylint $(params.pylint-args) . fi - onError: continue # 린트 μ‹€νŒ¨ν•΄λ„ νŒŒμ΄ν”„λΌμΈ μ€‘λ‹¨ν•˜μ§€ μ•ŠμŒ + PYLINT_EXIT_CODE=$? + set -e - - name: check-results - image: ubuntu - workingDir: /workspace/source - script: | - #!/usr/bin/env bash - echo "βœ… Pylint execution completed." + echo "βœ… Pylint execution completed with exit code: $PYLINT_EXIT_CODE" + exit 0 # 항상 성곡 처리 (μ›λž˜ onError: continue 효과) diff --git a/tasks/pypi/task.yaml b/tasks/pypi/task.yaml index 226c8cd..0bfbcdd 100644 --- a/tasks/pypi/task.yaml +++ b/tasks/pypi/task.yaml @@ -46,9 +46,6 @@ spec: #!/usr/bin/env bash set -e - pip install --upgrade pip --root-user-action=ignore - pip install poetry twine tomli --root-user-action=ignore - TWINE_USERNAME="$(params.pypi-username)" TWINE_PASSWORD="$(params.pypi-password)" HOSTED_URL="$(params.pypi-hosted-url)" @@ -60,12 +57,19 @@ spec: 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 diff --git a/tasks/pytest/task.yaml b/tasks/pytest/task.yaml index 526f8e5..9a47af1 100644 --- a/tasks/pytest/task.yaml +++ b/tasks/pytest/task.yaml @@ -48,30 +48,29 @@ spec: cd "$(params.subdirectory)" fi + 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 + + + echo "πŸ”§ Installing dependencies..." pip install --upgrade pip --root-user-action=ignore pip install pytest --root-user-action=ignore if [ -f pyproject.toml ]; then - echo "[INFO] Using Poetry to install dependencies" + echo "[INFO] Poetry project detected" pip install poetry tomli --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 - - echo "[INFO] PYPI_PASS: $PYPI_PASS" - 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" "$PYPI_USER" "$PYPI_PASS" @@ -81,37 +80,27 @@ spec: elif [ -f requirements.txt ]; then echo "[INFO] Using pip to install dependencies" pip install -r requirements.txt --root-user-action=ignore + else + echo "[WARN] No dependency file found" fi - - name: run-tests - 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 - + echo "πŸ§ͺ Running tests..." + set +e if [ -f pyproject.toml ]; then poetry run pytest --verbose --junitxml=/workspace/source/pytest-results.xml else pytest --verbose --junitxml=/workspace/source/pytest-results.xml fi - onError: continue - - - name: check-results - image: ubuntu - workingDir: /workspace/source - script: | - #!/usr/bin/env bash + TEST_EXIT_CODE=$? set -e - if [ -f pytest-results.xml ]; then - echo "Test results generated: pytest-results.xml" - cat pytest-results.xml + echo "πŸ“„ Checking test results..." + if [ -f /workspace/source/pytest-results.xml ]; then + echo "Test results:" + cat /workspace/source/pytest-results.xml else - echo "No test results found." + echo "❌ No test results found" exit 1 fi + + exit $TEST_EXIT_CODE \ No newline at end of file