Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2378: update .clang-format to match style guidelines #2379

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ ColumnLimit: 80
UseTab: Never

AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
@@ -89,4 +89,4 @@ SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++14
Standard: c++17
59 changes: 59 additions & 0 deletions .github/workflows/run-clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: PR checks (clang-format)

on: pull_request

jobs:
check:
name: Run clang-format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Run clang-format
run: |
{
echo 'CLANG_FORMAT_DIFF<<EOF'
git clang-format-16 --diff origin/${{ github.base_ref }} || true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git clang-format-16 --diff origin/${{ github.base_ref }} || true is the core of the action, the rest is pretty much boilerplate and comment-posting code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

echo EOF
} >> "$GITHUB_ENV"
- uses: actions/github-script@v7
with:
script: |
Copy link
Contributor Author

@cz4rs cz4rs Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script part boils down to:

  • find the comment id if the comment already exists
  • create or update the comment with clang-format output

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much the same what DARMA-tasking/comment-on-pr action does, but the script seems short enough to be put directly here.

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
})
}