91 lines
2.7 KiB
YAML
91 lines
2.7 KiB
YAML
apiVersion: tekton.dev/v1
|
|
kind: Task
|
|
metadata:
|
|
name: pylint
|
|
spec:
|
|
params:
|
|
- name: context
|
|
type: string
|
|
description: context directory
|
|
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: base
|
|
description: Workspace containing the cloned Git repository
|
|
|
|
steps:
|
|
- name: run-pylint
|
|
image: $(params.pythonImageName)
|
|
workingDir: /workspace/base/$(params.context)/source
|
|
env:
|
|
- name: HOME
|
|
value: /workspace/base/$(params.context)/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/base/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
|