Skip to content

Commit

Permalink
#2378: ci: post comment with clang-format output
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Feb 26, 2025
1 parent 5440153 commit ca3aa8f
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions .github/workflows/run-clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,48 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Run clang-format
shell: bash
run: git clang-format-16 --diff ${{ github.base_ref }}
run: |
{
echo 'CLANG_FORMAT_DIFF<<EOF'
git clang-format-16 --diff origin/${{ github.base_ref }} || true
echo EOF
} >> "$GITHUB_ENV"
- uses: actions/github-script@v7
with:
script: |
let commentId = -1
for await (const { data: comments } of github.paginate.iterator(
github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
}
)) {
const foundComment = comments.find((comment) =>
comment.body.startsWith(
'`clang-format` output for this changeset:'
)
)
if (foundComment) {
commentId = foundComment.id
break
}
}
const { CLANG_FORMAT_DIFF } = process.env
const commentBody = '`clang-format` output for this changeset:\n```diff\n' + CLANG_FORMAT_DIFF + '\n```'
if (commentId === -1) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
})
} else {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: commentBody
})
}

0 comments on commit ca3aa8f

Please sign in to comment.