Skip to content

Commit f89c66d

Browse files
authored
ci: Create diff and upload artefacts from clang-tidy fixes yaml (envoyproxy#25753)
Signed-off-by: Ryan Northey <[email protected]>
1 parent 6c18a51 commit f89c66d

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

.azure-pipelines/bazel.yml

+7
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,10 @@ steps:
8181
artifactName: ${{ parameters.ciTarget }}${{ parameters.artifactSuffix }}
8282
timeoutInMinutes: 10
8383
condition: always()
84+
85+
- task: PublishBuildArtifacts@1
86+
inputs:
87+
pathtoPublish: "$(Build.StagingDirectory)/tmp/lint-fixes"
88+
artifactName: "${{ parameters.ciTarget }}.fixes"
89+
timeoutInMinutes: 10
90+
condition: failed()

ci/do_ci.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,18 @@ elif [[ "$CI_TARGET" == "bazel.clang_tidy" ]]; then
455455
# clang-tidy will warn on standard library issues with libc++
456456
ENVOY_STDLIB="libstdc++"
457457
setup_clang_toolchain
458-
BAZEL_BUILD_OPTIONS="${BAZEL_BUILD_OPTIONS[*]}" NUM_CPUS=$NUM_CPUS "${ENVOY_SRCDIR}"/ci/run_clang_tidy.sh "$@"
458+
459+
export CLANG_TIDY_FIX_DIFF="${TEST_TMPDIR}/lint-fixes/clang-tidy-fixed.diff"
460+
export FIX_YAML="${TEST_TMPDIR}/lint-fixes/clang-tidy-fixes.yaml"
461+
export CLANG_TIDY_APPLY_FIXES=1
462+
mkdir -p "${TEST_TMPDIR}/lint-fixes"
463+
BAZEL_BUILD_OPTIONS="${BAZEL_BUILD_OPTIONS[*]}" NUM_CPUS=$NUM_CPUS "${ENVOY_SRCDIR}"/ci/run_clang_tidy.sh "$@" || {
464+
echo >&2
465+
echo "Diff/yaml files with (some) fixes will be uploaded. Please check the artefacts for this PR run in the azure pipeline." >&2
466+
echo >&2
467+
468+
exit 1
469+
}
459470
exit 0
460471
elif [[ "$CI_TARGET" == "bazel.fuzz" ]]; then
461472
setup_clang_toolchain

ci/run_clang_tidy.sh

+39-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}
1111
LLVM_PREFIX=${LLVM_PREFIX:-$(${LLVM_CONFIG} --prefix)}
1212
CLANG_TIDY=${CLANG_TIDY:-$(${LLVM_CONFIG} --bindir)/clang-tidy}
1313
CLANG_APPLY_REPLACEMENTS=${CLANG_APPLY_REPLACEMENTS:-$(${LLVM_CONFIG} --bindir)/clang-apply-replacements}
14-
FIX_YAML=clang-tidy-fixes.yaml
14+
FIX_YAML="${FIX_YAML:-clang-tidy-fixes.yaml}"
15+
CLANG_TIDY_APPLY_FIXES="${CLANG_TIDY_APPLY_FIXES:-}"
16+
CLANG_TIDY_FIX_DIFF="${CLANG_TIDY_FIX_DIFF:-}"
1517

1618
DIFF_TARGET_BRANCH="${DIFF_TARGET_BRANCH:-origin/main}"
1719

@@ -91,7 +93,7 @@ function run_clang_tidy() {
9193
python3 "${LLVM_PREFIX}/share/clang/run-clang-tidy.py" \
9294
-clang-tidy-binary="${CLANG_TIDY}" \
9395
-clang-apply-replacements-binary="${CLANG_APPLY_REPLACEMENTS}" \
94-
-export-fixes=${FIX_YAML} -j "${NUM_CPUS:-0}" -p "${SRCDIR}" -quiet \
96+
-export-fixes="${FIX_YAML}" -j "${NUM_CPUS:-0}" -p "${SRCDIR}" -quiet \
9597
${APPLY_CLANG_TIDY_FIXES:+-fix} "$@"
9698
}
9799

@@ -137,7 +139,40 @@ else
137139
fi
138140

139141
if [[ -s "${FIX_YAML}" ]]; then
140-
echo "clang-tidy check failed, potentially fixed by clang-apply-replacements:"
141-
cat "${FIX_YAML}"
142+
echo >&2
143+
echo "clang-tidy check failed, potentially fixed by clang-apply-replacements:" >&2
144+
echo >&2
145+
146+
# Replace the CI path with `.` so it should work locally for devs
147+
sed -i s#BuildDirectory:.*#BuildDirectory:\ .# "${FIX_YAML}"
148+
cat "${FIX_YAML}" >&2
149+
150+
if [[ -n "${CLANG_TIDY_APPLY_FIXES}" ]]; then
151+
if [[ ! -e "$CLANG_APPLY_REPLACEMENTS" ]]; then
152+
echo "clang-apply-replacements MISSING: ${CLANG_APPLY_REPLACEMENTS}" >&2
153+
else
154+
# Copy the yaml file into repo directory if its in a different location.
155+
if [[ "$(dirname "${FIX_YAML}")" != "$PWD" ]]; then
156+
FIX_YAML_NAME="$(basename "${FIX_YAML}")"
157+
if [[ -e "$FIX_YAML_NAME" ]]; then
158+
# remove existing file
159+
rm "$FIX_YAML_NAME"
160+
fi
161+
cp "${FIX_YAML}" .
162+
fi
163+
164+
${CLANG_APPLY_REPLACEMENTS} .
165+
166+
echo >&2
167+
echo "Changes applied:" >&2
168+
echo >&2
169+
170+
git --no-pager diff >&2
171+
172+
if [[ -n "${CLANG_TIDY_FIX_DIFF}" ]]; then
173+
git diff > "${CLANG_TIDY_FIX_DIFF}"
174+
fi
175+
fi
176+
fi
142177
exit 1
143178
fi

0 commit comments

Comments
 (0)