Skip to content

Commit 575d990

Browse files
authored
Update check_code_format.yml
1 parent d15ac07 commit 575d990

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

.github/workflows/check_code_format.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ jobs:
2626
run: |
2727
echo "Checking formatting in dynadjust"
2828
ERRORS=""
29-
# Determine clang-format style: use .clang-format if available,
30-
# otherwise default to LLVM style.
29+
# Use .clang-format if present, otherwise default to LLVM style.
3130
if [ -f .clang-format ]; then
3231
STYLE=file
3332
else
@@ -38,7 +37,7 @@ jobs:
3837
for f in $files; do
3938
diff=$(clang-format -style=$STYLE "$f" | diff "$f" -)
4039
if [ -n "$diff" ]; then
41-
echo "Formatting issues found in $f"
40+
echo "::warning file=$f::Formatting issues found"
4241
ERRORS="${ERRORS}\n- $f"
4342
ret=1
4443
fi
@@ -61,3 +60,30 @@ jobs:
6160
repo: context.repo.repo,
6261
body: msg
6362
});
63+
64+
- name: Create Annotations for Formatting Issues
65+
if: ${{ github.event_name == 'workflow_dispatch' && steps.fmt.outputs.errors != '' }}
66+
uses: actions/github-script@v6
67+
with:
68+
script: |
69+
const errors = `${{ steps.fmt.outputs.errors }}`.trim().split('\n').filter(e => e);
70+
if (errors.length === 0) return;
71+
github.rest.checks.create({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
name: 'Check code formatting',
75+
head_sha: context.sha,
76+
status: 'completed',
77+
conclusion: 'failure',
78+
output: {
79+
title: 'Formatting Issues',
80+
summary: `Formatting issues detected in the following files:\n${errors.join('\n')}`,
81+
annotations: errors.map(file => ({
82+
path: file.replace(/^- /, ''),
83+
start_line: 1,
84+
end_line: 1,
85+
annotation_level: 'failure',
86+
message: 'Formatting issues found'
87+
}))
88+
}
89+
});

0 commit comments

Comments
 (0)