Simplify the clang format check - #8871
Conversation
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
There was a problem hiding this comment.
🟢 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.
| if [[ "${#cpp_files[@]}" -eq 0 ]]; then | ||
| echo "[clang-format] no modified files to format" | ||
| exit 0 | ||
| fi |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
oh, maybe I'm misunderstanding your feedback - it's not about the echo, but about the entire if?
There was a problem hiding this comment.
Without that message we would get nothing: https://github.com/damyanp/DirectXShaderCompiler/actions/runs/33570847315/job/100064255165#step:5:50
There was a problem hiding this comment.
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
fiI'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.
There was a problem hiding this comment.
Thanks! It's even simpler now!
|
Claude has a concern:
|
Alex Sepkowski (alsepkow)
left a comment
There was a problem hiding this comment.
LGTUS - Joshua Batista (@bob80905)
Assuming you were able to verify with a good/bad C++ file ?
Joshua Batista (bob80905)
left a comment
There was a problem hiding this comment.
nit: I think the timeout can be reduced from 30 minutes.
|
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
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
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.