From ca3aa8fbc0488a74f731e52f9f4cbbfd6f1ced38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 25 Feb 2025 19:20:04 +0100 Subject: [PATCH] #2378: ci: post comment with clang-format output --- .github/workflows/run-clang-format.yml | 47 ++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-clang-format.yml b/.github/workflows/run-clang-format.yml index 36ce16c6a9..d83e46d015 100644 --- a/.github/workflows/run-clang-format.yml +++ b/.github/workflows/run-clang-format.yml @@ -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<> "$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 + }) + }