Skip to content

CI: the clang-format job can never print its findings (set -e kills it before the report) #89

Description

@balbasty

Found by:claude-jitfields-to-fastfields.

The lint (clang-format, changed lines) job in .github/workflows/ci.yml can never show what it objects to. Every failure renders as a bare exit code 1, which makes an advisory job useless as advice.

Cause

The step runs under set -euo pipefail and captures the diff into a variable:

set -euo pipefail
base=$(git merge-base "origin/${BASE_REF}" HEAD)
out=$(git-clang-format-18 --binary clang-format-18 --diff \ --extensions h,hpp,inl,cpp,cu,cuh "${base}")case"$out"in"no modified files to format"|"clang-format did not modify any files")
echo"clang-format: changed lines are clean" ;;
*)
echo"$out"# <-- unreachableecho"::error::clang-format would reformat the lines above."echo"Run: git clang-format $base"exit 1 ;;
esac

git-clang-format --diffexits 1 whenever it would reformat something — that is its documented contract, not an error. Under set -e, a failing command substitution in an assignment aborts the shell at that line, so the script dies before reaching case. The entire reporting branch — the diff, the ::error:: annotation, and the "Run: git clang-format …" hint — is dead code in exactly the situation it exists for.

The clean path works, which is why this went unnoticed: a passing run reaches case normally.

Fix

Stop treating exit 1 as fatal for that one command, e.g.

out=$(git-clang-format-18 --binary clang-format-18 --diff \ --extensions h,hpp,inl,cpp,cu,cuh "${base}")||true

or capture the status explicitly and branch on it. Worth also asserting in a test PR that the diff genuinely appears in the log, rather than assuming the fix works.

Why it matters more than it looks

The job is deliberately continue-on-error: true — the comment above it explains that .clang-format postdates the tree, which is hand-column-aligned in many places, so only changed lines are checked and the one-shot reformat is left as its own reviewable change. That design only works if a contributor can see the proposed reformat and judge it. Right now they cannot, so the job's output is a red mark with no actionable content, which trains people to ignore it.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions