RDKB-66207 : Add clang-format workflow. - #1305
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a two-stage GitHub Actions workflow to run clang-format on changed C/C header lines in pull requests and post the resulting formatting diffs back to the PR as GitHub “suggestion” review comments (non-blocking).
Changes:
- Introduces a
clang-formatPR workflow that runsgit-clang-formatand uploads a diff artifact when formatting changes are detected. - Introduces a
clang-format-suggestionsworkflow that triggers on completion of stage 1, downloads the artifact, converts diffs into PR review suggestions, and posts them via the GitHub API.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| .github/workflows/clang-format.yml | Stage 1 formatter run on PRs; produces and uploads a diff + PR metadata artifact. |
| .github/workflows/clang-format-suggestions.yml | Stage 2 reviewer; converts the diff artifact into “suggestion” comments and posts a PR review. |
Comments suppressed due to low confidence (2)
.github/workflows/clang-format.yml:24
- Stage 1 posts suggestions against the PR head SHA (recorded in
pr-meta.env), butactions/checkoutonpull_requestdefaults to the synthetic merge commit. That mismatch can shift line numbers and cause stage 2 to fail posting suggestions (422) or to target the wrong lines when the base branch has moved. Check out the PR head ref explicitly, and fetch the base branch ref needed for merge-base/diffing.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # need base history to diff changed lines
.github/workflows/clang-format.yml:33
BASE_SHAis set to the base branch tip SHA. For long-lived PRs, that SHA is often not an ancestor of the PR head, sogit-clang-formatcan compute diffs that include unrelated base-branch changes, producing suggestions that don’t correspond to the PR diff (and may trigger 422 in stage 2). Use the merge-base of the PR head and the base branch ref instead.
BASE_SHA="${{ github.event.pull_request.base.sha }}"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
.github/workflows/clang-format.yml:12
- The pull_request path filters use the uncommon patterns
**.c/**.h, which are easy to misread and can behave differently than the standard recursive file globs. Using**/*.cand**/*.his clearer and avoids any globstar edge cases for nested paths.
paths:
- '**.c'
- '**.h'
.github/workflows/clang-format-suggestions.yml:6
- Trailing whitespace at the end of this comment line can cause noisy diffs/linters in some setups; remove the extra space after the period.
# stage 1 as passive data and posts it as review suggestions.
30c8731 to
f1b2319
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (3)
.github/workflows/clang-format.yml:69
- The workflow triggers on
**/*.cppand the step name says it reformats.c/.cpp/.h, butgit-clang-formatis restricted to--extensions c,h, so C++ changes will never produce suggestions. Either include C++ extensions here or remove**/*.cppfrom the trigger list.
git-clang-format --style=file --extensions c,h "$BASE_SHA" -- . "${EXCLUDES[@]}"
.github/workflows/clang-format.yml:51
git merge-basecan fail here even withfetch-depth: 0because the base SHA may not be present in the local clone when checking out only the PR head SHA. Fetching the base SHA explicitly makes the merge-base computation reliable.
BASE_SHA="$(git merge-base "${{ github.event.pull_request.base.sha }}" HEAD)" || {
echo "::error::Could not compute merge base — is fetch-depth: 0 set?"
exit 1
}
.github/workflows/clang-format-suggestions.yml:33
- This comment is missing a closing parenthesis, which makes the sentence hard to read.
# fire 'completed'). Allow failure too (if stage 1 fails, suggestions are still useful!
Dismiss old reviews: - when in progress while new commit (narrow ~2-3 sec window,but vialbe) - when done, and new push done in the meantime .
f1b2319 to
9cfa2f1
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (4)
.github/workflows/clang-format-suggestions.yml:144
- The example command shown when suggestions exceed the cap uses
--extensions c,h, which won’t match the workflow’s.cppscope once enabled. Keep this guidance consistent with the actual formatter invocation.
"> ```\n"
"> pip install clang-format==18.1.8\n"
"> git-clang-format --style=file --extensions c,h <merge-base>\n"
"> ```")
.github/workflows/clang-format.yml:69
- The workflow triggers on
**/*.cpp, butgit-clang-formatis limited to--extensions c,h, so.cppchanges will never be reformatted/suggested. Includecpp(and any other intended extensions) in--extensions, and update the nearby comment so it stays accurate.
# --extensions c,h is why nothing but C sources is ever formatted.
#
# git-clang-format exit codes: 0 = nothing to do, 1 = it reformatted
# something (this is NOT an error), 2+ = genuine failure. The default
# shell is `bash -e`, so a bare call would abort the step on the
.github/workflows/clang-format.yml:26
actions/checkoutis referenced as@v6, but this repo’s other workflows useactions/checkout@v4(e.g..github/workflows/makefile.yml:28,.github/workflows/community_label_by_author.yml:17). Aligning versions reduces maintenance risk and avoids failures ifv6is not available.
- uses: actions/checkout@v6
.github/workflows/clang-format-suggestions.yml:33
- Minor typo in the comment: the parenthesis opened in
Allow failure too (isn’t closed, which makes the comment harder to read.
This issue also appears on line 141 of the same file.
# Exclude cancelled runs at the source (they can leave outdated artifact yet
# fire 'completed'). Allow failure too (if stage 1 fails, suggestions are still useful!
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
.github/workflows/clang-format.yml:40
- This step says it reformats only changed
.c/.hlines, but the workflow also targets.cppfiles (pathsand--extensionsincludecpp). Update the step name to reflect the actual behavior so the workflow remains self-documenting.
- name: Reformat only the changed .c/.h lines
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (3)
.github/workflows/clang-format.yml:98
- This workflow uses
actions/upload-artifact@v6, but the repo’s workflows generally pin coreactions/*dependencies to established major versions (for exampleactions/checkout@v4in.github/workflows/makefile.yml:28). To reduce the chance of breakage from an unsupported/unknown major, pin to the same stable major used elsewhere.
uses: actions/upload-artifact@v6
.github/workflows/clang-format.yml:26
- This workflow uses
actions/checkout@v6, but other workflows in this repo consistently useactions/checkout@v4(e.g.,.github/workflows/community_label_by_author.yml:17,.github/workflows/makefile.yml:28). Using a different (and potentially unsupported) major version here increases the risk of the workflow failing or behaving differently from the rest of the CI setup.
This issue also appears on line 98 of the same file.
- uses: actions/checkout@v6
.github/workflows/clang-format-suggestions.yml:41
- This workflow uses
actions/download-artifact@v7. The repo’s other workflows pin GitHub-maintainedactions/*to stable majors (notablyactions/checkout@v4in.github/workflows/community_label_by_author.yml:17and.github/workflows/makefile.yml:28). Aligning this to the same stable major reduces the risk of CI breakage due to an unsupported/unknown major version.
uses: actions/download-artifact@v7
NOTE: Superseeded by PR #1320
clang-format file is present in the repository, but not used. As a result, code not adhering to coding standards is slipping through the net.
Let's add it to the workflow, observational at first.
It will be run on incoming PRs. Produced output will be copilot-style - in the PR comments will appear with suggested fixes to bring PR in line with coding standards.
Result of it's run will not break the merge requirements.