Skip to content

Commit

Permalink
github: update lint.yml to post details on formatting issue (#3988)
Browse files Browse the repository at this point in the history
before this change, user need to click into the details for more
details on the formatting issue identified by the lint workflow.

after this change, the workflow pastes the details with a comment,
to provide more specific details on the formatting issue if any.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
  • Loading branch information
tchaikov authored Jun 3, 2024
1 parent d9b9002 commit c71d08f
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

permissions:
contents: read
pull-requests: write

jobs:
format_code:
Expand All @@ -21,6 +22,34 @@ jobs:
clangformat: 17.0.5

- name: Run clang-format
id: clang_format
run: |
find include src -name '*.h' -o -name '*.cc' | xargs clang-format -i -style=file -fallback-style=none
git diff --exit-code
git diff | tee fmt.patch
if [ -s fmt.patch ]; then
exit 1
fi
- uses: actions/github-script@v7
if: failure() && steps.clang_format.outcome == 'failure'
with:
script: |
const fs = require('fs');
const patch = fs.readFileSync('fmt.patch', { encoding: 'utf8' });
const comment = `clang-format 17.0.5 found issues in the formatting in your code:
<details>
<summary>
View the diff from clang-format:
</summary>
\`\`\`diff
${patch}
\`\`\`
</details>
`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});

0 comments on commit c71d08f

Please sign in to comment.