-
Notifications
You must be signed in to change notification settings - Fork 72
70 lines (67 loc) · 2.63 KB
/
clang-format-lint.yml
File metadata and controls
70 lines (67 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
# https://github.com/marketplace/actions/clang-format-lint
name: ClangFormat
on: [push, pull_request]
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR
# Remove the ones you do not need
contents: write
issues: write
pull-requests: write
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
clang-format:
name: Clang Format
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Clang Format
id: clang
uses: DoozyX/clang-format-lint-action@v0.20
with:
#source: '.'
#exclude: './third_party ./external'
extensions: 'C,c,c++,cc,cl,cpp,cu,cuh,cxx,cxx.in,h,h++,hh,h.in,hpp,hxx,inc,inl,macro'
# clangFormatVersion: 18
style: file
inplace: true
# Set a results status = 0 if no changes, = 1 if formatted
- name: Set result status
id: clang-result
run: |
status=0
if ! git diff --quiet; then
status=1
fi
echo "status=$status" >> "$GITHUB_OUTPUT"
# Create pull request if applicable (for now works only on PR from same repository, not from forks)
- name: Print PR condition
run: |
# Print the condition
echo "${{ github.event_name }} == 'push'"
- name: Create Pull Request with applied fixes
id: cpr
if: github.event_name == 'push'
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
commit-message: "[Clang format] Apply linters automatic fixes"
title: "[Clang format] Apply linters automatic fixes"
body: "Please merge this pull request to apply automatic fixes by Clang format."
labels: bot
branch: patch-${{ github.workflow }}-${{ github.ref_name }}
delete-branch: true
- name: Create PR output
if: steps.clang-result.outputs.status == 1
run: |-
echo "::error::Files need formatting."
if [ ${{ github.event_name }} == 'push' ]; then
echo "::error::Merge pull request ${{ steps.cpr.outputs.pull-request-url }} to apply automatic fixes."
elif [ ${{ github.event_name }} == 'pull_request' ]; then
echo "::error::Check ${{ github.event.pull_request.head.repo.html_url }}/pulls to apply automatic fixes."
echo "::notice::Actions must be allowed in your repository. See ${{ github.event.pull_request.head.repo.html_url }}/settings/actions"
fi
exit 1