-
Notifications
You must be signed in to change notification settings - Fork 15
77 lines (62 loc) · 2.52 KB
/
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
74
75
76
name: Run all linters
on:
pull_request:
branches: [ master, develop ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
linter:
runs-on: ubuntu-latest
env:
LocalCommit: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
token: ${{ secrets.LINTER_PAT }}
if: env.LocalCommit == 'true'
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
if: env.LocalCommit != 'true'
- run: git fetch origin $GITHUB_BASE_REF
- name: Set Branch name
id: branch-name
run:
echo "branchName=$GITHUB_BASE_REF" >> $GITHUB_OUTPUT
- name: Format CMake files
id: cmake-format
uses: PuneetMatharu/[email protected]
with:
args: --config-files .cmake-format.py --in-place
- name: Define base git diff args
id: git-diff-args
run: |
echo "args=origin/${{steps.branch-name.outputs.branchName}}..HEAD" >> $GITHUB_OUTPUT
- name: Apply clang-format on changed files
run: |
changedFileList=`git diff ${{steps.git-diff-args.outputs.args}} --name-only --diff-filter=d -- '***.hpp' '***.cpp' '***.h' '***.c'`
for file in $changedFileList; do echo "Checking file " $file; clang-format --style=file -i $file; done
- name: Check if we have local changes
id: check-changes
shell: bash
run: |
if [[ -z $(git status --porcelain --untracked-files=no) ]]; then echo "ChangesFound=False" >> $GITHUB_OUTPUT; else echo "ChangesFound=True" >> $GITHUB_OUTPUT; fi
- name: setup git config
run: |
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: Commit changes
if: steps.check-changes.outputs.ChangesFound == 'True' && env.LocalCommit == 'true'
run: |
git commit -am "Automatically applied linter"
git push
- name: Notify that changes are required
if: ${{ steps.check-changes.outputs.ChangesFound == 'True' && env.LocalCommit != 'true' }}
run: |
echo "Linter changes are required" >> $GITHUB_STEP_SUMMARY
exit 1