Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 79 additions & 11 deletions scripts/ci/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,90 @@

set -euf -o pipefail

# Exit status used to signal "lint succeeded but emitted warnings". The Buildkite
# lint step soft-fails on this status, so it must never be used to report a chart
# that actually failed to lint.
WARNING_EXIT_STATUS=255

# Highest-severity outcome seen so far. A hard lint failure always wins over a
# warning, so a warning in an earlier chart can never downgrade a later failure
# into a soft fail.
hard_status=0
warned=0
results=()

### Run the helm tests
function lint_chart() {
echo "Linting chart $1"
LINT_OUTPUT=$(helm lint charts/$1)
ORG_STATUS=$?
local chart_path="$1"
local lint_output
local lint_status

printf "\n\n===== Lint Output =====\n$LINT_OUTPUT\n"
shift

LINT_OUTPUT_LOWER=$(echo "$LINT_OUTPUT" | awk '{print tolower($0)}')
if grep -q "warning" <<<"$LINT_OUTPUT_LOWER"; then
exit 255
echo "Linting chart ${chart_path}"
if lint_output=$(helm lint "${chart_path}" "$@" 2>&1); then
lint_status=0
else
exit $ORG_STATUS
lint_status=$?
fi

printf "\n\n===== Lint Output: %s =====\n%s\n" "${chart_path}" "${lint_output}"

# A chart that failed to lint is reported as a failure even if it also emitted
# warnings, otherwise the failure would be masked by the soft-failed status.
if [ "${lint_status}" -ne 0 ]; then
printf "Helm lint failed for %s\n" "${chart_path}" >&2
return "${lint_status}"
fi

if grep -qi "warning" <<<"${lint_output}"; then
printf "Helm lint emitted warnings for %s\n" "${chart_path}" >&2
return "${WARNING_EXIT_STATUS}"
fi

return 0
}

lint_chart "sourcegraph"
lint_chart "sourcegraph-migrator"
lint_chart "sourcegraph-executor"
function lint_and_record() {
local chart_path="$1"
local chart_status

if lint_chart "$@"; then
results+=("PASS ${chart_path}")
return 0
else
chart_status=$?
fi

if [ "${chart_status}" -eq "${WARNING_EXIT_STATUS}" ]; then
warned=1
results+=("WARNING ${chart_path}")
else
results+=("FAIL ${chart_path} (helm lint exited ${chart_status})")
if [ "${hard_status}" -eq 0 ]; then
hard_status="${chart_status}"
fi
fi

return 0
}

lint_and_record "charts/sourcegraph"
lint_and_record "charts/sourcegraph-migrator"
lint_and_record "charts/sourcegraph-executor/k8s" --set "executor.queueName=batches"
lint_and_record "charts/sourcegraph-executor/dind" --set "executor.queueName=batches"

printf "\n\n===== Lint Summary =====\n"
printf "%s\n" "${results[@]}"

if [ "${hard_status}" -ne 0 ]; then
printf "\nOne or more charts failed to lint\n" >&2
exit "${hard_status}"
fi

if [ "${warned}" -ne 0 ]; then
printf "\nOne or more charts emitted lint warnings\n" >&2
exit "${WARNING_EXIT_STATUS}"
fi

exit 0
Loading