apiVersion: tekton.dev/v1 kind: Task metadata: name: pylint spec: params: - name: subdirectory type: string description: Subdirectory within the repo where the source 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: source description: Workspace containing the cloned Git repository steps: - name: run-pylint image: $(params.pythonImageName) workingDir: /workspace/source/$(params.subdirectory) env: - name: HOME value: /tekton/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 --no-update 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/source/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