Skip to content

Commit e608950

Browse files
committed
Add reviewdog for inline formatting suggestions
This enhances the coding_style job to provide inline pull request comments for formatting violations using reviewdog. Workflow behavior: - On push: Only runs check-format.sh (strict validation) - On PR: Runs reviewdog (inline suggestions) + check-format.sh (validation) Benefits: - Developers see exact formatting issues inline in PR - Faster iteration on style fixes - Non-blocking suggestions with blocking validation
1 parent d66aefa commit e608950

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

.github/workflows/main.yml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,52 @@ jobs:
8989

9090
coding_style:
9191
runs-on: ubuntu-24.04
92+
permissions:
93+
contents: read
94+
pull-requests: write
9295
steps:
9396
- uses: actions/checkout@v4
94-
- name: coding convention
97+
- name: Install clang-format
9598
run: |
9699
sudo apt-get update
97100
sudo apt-get install -q -y clang-format-18
98-
.ci/check-format.sh
101+
shell: bash
102+
- name: Setup reviewdog
103+
uses: reviewdog/action-setup@v1
104+
if: github.event_name == 'pull_request'
105+
with:
106+
reviewdog_version: latest
107+
- name: Run clang-format with reviewdog
108+
if: github.event_name == 'pull_request'
109+
env:
110+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
run: |
112+
set -euo pipefail
113+
114+
# Get list of source files
115+
SOURCES=$(git ls-files '*.c' '*.cxx' '*.cpp' '*.h' '*.hpp')
116+
117+
# Register cleanup function to restore files on exit
118+
cleanup_files() {
119+
if [ -n "${SOURCES:-}" ]; then
120+
echo "Restoring files to original state..."
121+
git checkout -- ${SOURCES} 2>/dev/null || true
122+
fi
123+
}
124+
trap cleanup_files EXIT INT TERM
125+
126+
# Apply clang-format in-place to generate diff
127+
clang-format-18 -i ${SOURCES}
128+
129+
# Generate diff and pipe to reviewdog
130+
# Note: reviewdog exit code doesn't affect cleanup due to trap
131+
git diff -u --no-color | reviewdog -f=diff \
132+
-name="clang-format" \
133+
-reporter=github-pr-review \
134+
-filter-mode=added \
135+
-fail-on-error=false \
136+
-level=warning || true
137+
shell: bash
138+
- name: Check formatting (fail on violations)
139+
run: .ci/check-format.sh
99140
shell: bash

0 commit comments

Comments
 (0)