Skip to content

Commit 5a85bd9

Browse files
authored
C++ formatting suggestions on PRs (#3829)
1 parent 3ff6b59 commit 5a85bd9

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

.github/workflows/format-check.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ on:
55
workflow_dispatch:
66

77
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
- labeled
13+
- unlabeled
814
branches:
915
- develop
1016
- master
1117

1218
jobs:
1319
cpp-linter:
1420
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
pull-requests: write
1524
steps:
1625
- uses: actions/checkout@v4
1726
- uses: cpp-linter/cpp-linter-action@v2
@@ -23,10 +32,29 @@ jobs:
2332
files-changed-only: true
2433
tidy-checks: '-*'
2534
version: '15' # clang-format version
35+
format-review: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'cpp-format-suggest') }}
36+
passive-reviews: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'cpp-format-suggest') }}
2637
file-annotations: true
2738
step-summary: true
2839
extensions: 'cpp,h'
2940

41+
- name: Comment with suggestion instructions
42+
if: steps.linter.outputs.checks-failed > 0 && !contains(github.event.pull_request.labels.*.name, 'cpp-format-suggest')
43+
uses: actions/github-script@v7
44+
with:
45+
script: |
46+
const {owner, repo} = context.repo;
47+
const issue_number = context.payload.pull_request.number;
48+
await github.rest.issues.createComment({
49+
owner,
50+
repo,
51+
issue_number,
52+
body: "C++ formatting checks failed. Add the `cpp-format-suggest` label to this PR for inline formatting suggestions on the next run."
53+
});
54+
3055
- name: Failure Check
3156
if: steps.linter.outputs.checks-failed > 0
32-
run: echo "Some files failed the formatting check! See job summary and file annotations for more info" && exit 1
57+
run: |
58+
echo "Some files failed the formatting check."
59+
echo "See job summary and file annotations for details."
60+
exit 1

0 commit comments

Comments
 (0)