Skip to content

Commit 9e7fa4b

Browse files
Chore: Fix CI lint script to lint all charts (#930)
- lint_chart exited the whole script after the first chart, so only charts/sourcegraph was ever linted - Lint every chart even after a failure, report per-chart results, and exit with the first failing status Amp-Thread-ID: https://ampcode.com/threads/T-01a04192-5b1d-7040-9dc3-76f8d5a10ab0 ### Checklist - [x] Follow the [manual testing process](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/main/TEST.md) - [ ] Update [changelog](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/main/charts/sourcegraph/CHANGELOG.md) - [ ] Update [Kubernetes update doc](https://docs.sourcegraph.com/admin/updates/kubernetes) ### Test plan Before ``` $ cd deploy-sourcegraph-helm $ ./scripts/ci/lint.sh Linting chart sourcegraph ===== Lint Output ===== ==> Linting charts/sourcegraph 1 chart(s) linted, 0 chart(s) failed ``` After ``` $ cd deploy-sourcegraph-helm $ ./scripts/ci/lint.sh Linting chart charts/sourcegraph ===== Lint Output: charts/sourcegraph ===== ==> Linting charts/sourcegraph 1 chart(s) linted, 0 chart(s) failed Linting chart charts/sourcegraph-migrator ===== Lint Output: charts/sourcegraph-migrator ===== ==> Linting charts/sourcegraph-migrator 1 chart(s) linted, 0 chart(s) failed Linting chart charts/sourcegraph-executor/k8s ===== Lint Output: charts/sourcegraph-executor/k8s ===== ==> Linting charts/sourcegraph-executor/k8s 1 chart(s) linted, 0 chart(s) failed Linting chart charts/sourcegraph-executor/dind ===== Lint Output: charts/sourcegraph-executor/dind ===== ==> Linting charts/sourcegraph-executor/dind 1 chart(s) linted, 0 chart(s) failed ``` Co-authored-by: Amp <amp@ampcode.com>
1 parent 1f8179a commit 9e7fa4b

1 file changed

Lines changed: 79 additions & 11 deletions

File tree

‎scripts/ci/lint.sh‎

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,90 @@
22

33
set -euf -o pipefail
44

5+
# Exit status used to signal "lint succeeded but emitted warnings". The Buildkite
6+
# lint step soft-fails on this status, so it must never be used to report a chart
7+
# that actually failed to lint.
8+
WARNING_EXIT_STATUS=255
9+
10+
# Highest-severity outcome seen so far. A hard lint failure always wins over a
11+
# warning, so a warning in an earlier chart can never downgrade a later failure
12+
# into a soft fail.
13+
hard_status=0
14+
warned=0
15+
results=()
16+
517
### Run the helm tests
618
function lint_chart() {
7-
echo "Linting chart $1"
8-
LINT_OUTPUT=$(helm lint charts/$1)
9-
ORG_STATUS=$?
19+
local chart_path="$1"
20+
local lint_output
21+
local lint_status
1022

11-
printf "\n\n===== Lint Output =====\n$LINT_OUTPUT\n"
23+
shift
1224

13-
LINT_OUTPUT_LOWER=$(echo "$LINT_OUTPUT" | awk '{print tolower($0)}')
14-
if grep -q "warning" <<<"$LINT_OUTPUT_LOWER"; then
15-
exit 255
25+
echo "Linting chart ${chart_path}"
26+
if lint_output=$(helm lint "${chart_path}" "$@" 2>&1); then
27+
lint_status=0
1628
else
17-
exit $ORG_STATUS
29+
lint_status=$?
30+
fi
31+
32+
printf "\n\n===== Lint Output: %s =====\n%s\n" "${chart_path}" "${lint_output}"
33+
34+
# A chart that failed to lint is reported as a failure even if it also emitted
35+
# warnings, otherwise the failure would be masked by the soft-failed status.
36+
if [ "${lint_status}" -ne 0 ]; then
37+
printf "Helm lint failed for %s\n" "${chart_path}" >&2
38+
return "${lint_status}"
1839
fi
40+
41+
if grep -qi "warning" <<<"${lint_output}"; then
42+
printf "Helm lint emitted warnings for %s\n" "${chart_path}" >&2
43+
return "${WARNING_EXIT_STATUS}"
44+
fi
45+
46+
return 0
1947
}
2048

21-
lint_chart "sourcegraph"
22-
lint_chart "sourcegraph-migrator"
23-
lint_chart "sourcegraph-executor"
49+
function lint_and_record() {
50+
local chart_path="$1"
51+
local chart_status
52+
53+
if lint_chart "$@"; then
54+
results+=("PASS ${chart_path}")
55+
return 0
56+
else
57+
chart_status=$?
58+
fi
59+
60+
if [ "${chart_status}" -eq "${WARNING_EXIT_STATUS}" ]; then
61+
warned=1
62+
results+=("WARNING ${chart_path}")
63+
else
64+
results+=("FAIL ${chart_path} (helm lint exited ${chart_status})")
65+
if [ "${hard_status}" -eq 0 ]; then
66+
hard_status="${chart_status}"
67+
fi
68+
fi
69+
70+
return 0
71+
}
72+
73+
lint_and_record "charts/sourcegraph"
74+
lint_and_record "charts/sourcegraph-migrator"
75+
lint_and_record "charts/sourcegraph-executor/k8s" --set "executor.queueName=batches"
76+
lint_and_record "charts/sourcegraph-executor/dind" --set "executor.queueName=batches"
77+
78+
printf "\n\n===== Lint Summary =====\n"
79+
printf "%s\n" "${results[@]}"
80+
81+
if [ "${hard_status}" -ne 0 ]; then
82+
printf "\nOne or more charts failed to lint\n" >&2
83+
exit "${hard_status}"
84+
fi
85+
86+
if [ "${warned}" -ne 0 ]; then
87+
printf "\nOne or more charts emitted lint warnings\n" >&2
88+
exit "${WARNING_EXIT_STATUS}"
89+
fi
90+
91+
exit 0

0 commit comments

Comments
 (0)