Skip to content

Simplify the clang format check - #8871

Open
Damyan Pepper (damyanp) wants to merge 5 commits into
microsoft:mainfrom
damyanp:damyanp-simplify-clang-format-checker
Open

Simplify the clang format check#8871
Damyan Pepper (damyanp) wants to merge 5 commits into
microsoft:mainfrom
damyanp:damyanp-simplify-clang-format-checker

Conversation

@damyanp

Copy link
Copy Markdown
Member

This change runs the clang format check in a read-only pull request workflow.

It removes pull request comments and the option that applies formatting changes. The check shows the formatting diff in the job log and fails when formatting changes are required.

Use a read-only pull request workflow. Remove pull request comments and automatic formatting changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6543b38e-a489-4210-9e73-9a51687c3646
Keep the original pull request events and head checkout. Select the same C and C++ file types with a safe NUL-delimited path list.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6543b38e-a489-4210-9e73-9a51687c3646
Select only files changed by the pull request when the base and head branches diverge.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6543b38e-a489-4210-9e73-9a51687c3646
@damyanp
Damyan Pepper (damyanp) marked this pull request as ready for review September 1, 2026 22:31
Copilot AI balanced review requested due to automatic review settings September 1, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The streamlined workflow safely preserves formatting enforcement without requiring write permissions.

Pull request overview

Simplifies the clang-format check into a read-only pull request workflow.

Changes:

  • Reports formatting diffs in job logs and fails when changes are required.
  • Removes PR comments, automatic formatting, Python helpers, and dependencies.
  • Adds minimal permissions, concurrency control, and a timeout.
File summaries
File Description
.github/workflows/clang-format-checker.yml Implements the read-only formatting check.
utils/git/code-format-helper.py Removes the obsolete PR-comment helper.
utils/git/code-format-save-diff.py Removes automatic patch application support.
utils/git/requirements_formatting.txt.in Removes the PyGitHub dependency declaration.
utils/git/requirements_formatting.txt Removes obsolete generated dependencies.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +61 to +64
if [[ "${#cpp_files[@]}" -eq 0 ]]; then
echo "[clang-format] no modified files to format"
exit 0
fi

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Presumably if there isn't anything interesting to format git-clang-format will exit 0 and we don't need to worry about the actual file list at all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's some value in having something to look at in the log to see why it exited with 0 rather than having to guess why it didn't do anything.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, maybe I'm misunderstanding your feedback - it's not about the echo, but about the entire if?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm suggesting we remove all of this:

          git diff --name-only --diff-filter=ACMR -z \
            "$START_REV...$END_REV" \
            -- >"$changed_files_file"
          mapfile -d '' -t changed_files <"$changed_files_file"

          cpp_files=()
          for path in "${changed_files[@]}"; do
            case "$path" in
              *.cpp|*.c|*.h|*.hpp|*.hxx|*.cxx) cpp_files+=("$path") ;;
            esac
          done

          if [[ "${#cpp_files[@]}" -eq 0 ]]; then
            echo "[clang-format] no modified files to format"
            exit 0
          fi

I'm not totally convinced it's important to differentiate between "no relevant files were changed at all" and "everything is already formatted correctly".

If we do want to differentiate, maybe we should just run git-clang-format with --verbose? It prints either "no modified files to format" or "clang-format did not modify any files" in that case. Though, annoyingly, it looks like it prints both the diff and the verbose messages to stdout rather than printing the messages to stderr as I would hope.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It's even simpler now!

@alsepkow

Alex Sepkowski (alsepkow) commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Claude has a concern:

One substantive concern: the workflow uses the merge base only when selecting filenames, but  git-clang-format  still compares the base tip directly with the PR head:

git-clang-format --diff "$START_REV" "$END_REV"

When a PR branch is behind and the target branch modified the same C++ file, this can inspect lines that were not changed by the PR and produce a false formatting failure. It should compute and use the merge base:

merge_base="$(git merge-base "$START_REV" "$END_REV")"

git-clang-format
--diff
--extensions=cpp,c,h,hpp,hxx,cxx
"$merge_base"
"$END_REV"

@alsepkow Alex Sepkowski (alsepkow) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTUS - Joshua Batista (@bob80905)
Assuming you were able to verify with a good/bad C++ file ?

@bob80905 Joshua Batista (bob80905) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think the timeout can be reduced from 30 minutes.

@damyanp

Copy link
Copy Markdown
Member Author

LGTUS - Joshua Batista (Joshua Batista (@bob80905)) Assuming you were able to verify with a good/bad C++ file ?

Use Node.js 24 actions, compare from the merge base, and upload a validated raw formatting patch when the check fails.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6543b38e-a489-4210-9e73-9a51687c3646
Copilot AI review requested due to automatic review settings September 1, 2026 23:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The workflow consistently implements the described read-only check and removes all obsolete supporting components.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Let git-clang-format select changed C and C++ files from the merge base instead of duplicating that logic in the workflow.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6543b38e-a489-4210-9e73-9a51687c3646
Copilot AI review requested due to automatic review settings September 2, 2026 02:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The workflow correctly performs a bounded, read-only formatting check and removes now-unused supporting code.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

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

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

5 participants