-
Notifications
You must be signed in to change notification settings - Fork 4
73 lines (65 loc) · 2.4 KB
/
c-cpp-linter.yml
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
71
72
73
name: c-cpp-linter
on:
pull_request:
branches: [main]
paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cc', '**.hh', '**.cxx', '**.hxx']
workflow_call:
jobs:
c-cpp-linter:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/[email protected]
- uses: cpp-linter/[email protected]
id: linter
continue-on-error: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: file
tidy-checks: '-*'
thread-comments: true
step-summary: true
- name: Fail checks
if: steps.linter.outputs.checks-failed > 0
run: |
echo "Some files failed the linting checks!"
echo "No. of checks failed: ${{ steps.linter.outputs.checks-failed }}"
echo "Use the clang-format diffs to find more help"
- name: Setup Python
if: steps.linter.outputs.checks-failed > 0
uses: actions/[email protected]
with:
python-version: '3.12'
- name: Getting PR details
if: steps.linter.outputs.checks-failed > 0
run: |
touch pr.json # creating empty file for paths
gh pr view $PR_NUMBER --json files > pr.json # storing file paths
touch res # creating empty file for final output
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Python script for clang diff
if: steps.linter.outputs.checks-failed > 0
uses: jannekem/run-python-script-action@v1
with:
script: |
import os
import json
import sys
with open('pr.json','r') as json_file:
data = json.load(json_file)
for file in data["files"]:
path = file["path"]
if os.path.exists(path):
os.system('echo "" >> res')
os.system(f'echo "Filename: {path}" >> res')
os.system('echo "" >> res')
os.system(f'clang-format-12 -style=Google {path} >> res')
os.system('echo ---------------------------------------- >> res')
- name: Show diffs and exit
if: steps.linter.outputs.checks-failed > 0
run: |
cat res
exit 1