tekton-hub/tasks/pylint/task.yaml
2025-04-15 13:13:16 +00:00

96 lines
2.8 KiB
YAML

apiVersion: tekton.dev/v1
kind: Task
metadata:
name: pylint
spec:
params:
- name: home
type: string
description: home directory
default: ""
- name: workshop
type: string
description: workshop within the repo where the shared code is located
default: ""
- name: pythonImageName
type: string
description: Python version to use (e.g., python:3.11-slim)
default: "python:3.11-slim"
- name: pylint-args
type: string
description: Additional arguments for pylint (e.g., --fail-under=8)
default: ""
- name: fail-on-lint
type: string
default: "false"
description: |
If true, the step will exit with a failure code if pylint reports issues.
Otherwise, it will always exit 0.
results:
- name: pylint-exit-code
description: Exit code returned by pylint (0=clean, non-zero=issues)
workspaces:
- name: shared
description: Workspace containing the cloned Git repository
steps:
- name: run-pylint
image: $(params.pythonImageName)
workingDir: /workspace/shared/$(params.workshop)
env:
- name: HOME
value: /workspace/shared/$(params.home)
script: |
#!/usr/bin/env bash
set -e
echo "🔧 Installing dependencies..."
pip install --upgrade pip --root-user-action=ignore
if [ -f pyproject.toml ]; then
echo "[INFO] Poetry project detected"
pip install poetry --root-user-action=ignore
poetry lock
poetry install --with dev
elif [ -f requirements.txt ]; then
echo "[INFO] Pip project detected"
pip install -r requirements.txt --root-user-action=ignore
else
echo "[INFO] No dependency file found"
fi
echo "✅ Installing pylint..."
pip install pylint --root-user-action=ignore || poetry add --dev pylint || echo "[WARN] Pylint 설치 실패"
echo "🧪 Running Pylint (JSON report)..."
set +e
REPORT_FILE="/workspace/shared/pylint-report.json"
if [ -f pyproject.toml ]; then
poetry run pylint $(params.pylint-args) --output-format=json . > "$REPORT_FILE"
else
pylint $(params.pylint-args) --output-format=json . > "$REPORT_FILE"
fi
PYLINT_EXIT_CODE=$?
set -e
echo "$PYLINT_EXIT_CODE" > /tekton/results/pylint-exit-code
echo "📄 Pylint exit code: $PYLINT_EXIT_CODE"
echo "📦 Report saved to $REPORT_FILE"
head -n 10 "$REPORT_FILE" || echo "[WARN] Empty report"
if [ "$(params.fail-on-lint)" = "true" ] && [ "$PYLINT_EXIT_CODE" -ne 0 ]; then
echo "❌ Pylint failed and fail-on-lint=true"
exit $PYLINT_EXIT_CODE
fi
echo "✅ Task succeeded regardless of lint result"
exit 0