From c71d08fc225197fe2c891d00200a1e2149735291 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 3 Jun 2024 21:34:44 +0800 Subject: [PATCH] github: update lint.yml to post details on formatting issue (#3988) 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 --- .github/workflows/lint.yml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 51a62f46..ad441f25 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,6 +8,7 @@ on: permissions: contents: read + pull-requests: write jobs: format_code: @@ -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: +
+ + View the diff from clang-format: + + + \`\`\`diff + ${patch} + \`\`\` + +
+ `; + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + });