|
1 | 1 |
|
2 | 2 | name: Code_Format_Check |
3 | 3 |
|
4 | | -# Controls when the workflow will run |
5 | 4 | on: |
6 | | - # Triggers the workflow on push or pull request events but only for the "master" branch |
7 | 5 | push: |
8 | 6 | branches: [ "master", "ros2" ] |
9 | 7 | pull_request: |
10 | 8 | branches: [ "master", "ros2" ] |
11 | | - |
12 | | - # Allows you to run this workflow manually from the Actions tab |
13 | 9 | workflow_dispatch: |
14 | 10 |
|
15 | 11 | permissions: |
16 | 12 | contents: read |
17 | 13 |
|
18 | | -# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
19 | 14 | jobs: |
20 | | - # Removed the old artifacts |
21 | | - remove-old-artifacts: |
22 | | - runs-on: ubuntu-22.04 |
23 | | - timeout-minutes: 10 |
24 | | - steps: |
25 | | - - name: Remove old artifacts |
26 | | - uses: c-hive/gha-remove-artifacts@v1 |
27 | | - with: |
28 | | - age: '15 days' |
29 | 15 | code-format-check: |
30 | | - # The type of runner that the job will run on |
31 | 16 | runs-on: ubuntu-22.04 |
32 | | - # Steps represent a sequence of tasks that will be executed as part of the job |
| 17 | + timeout-minutes: 10 |
| 18 | + |
33 | 19 | steps: |
34 | | - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
35 | | - - uses: actions/checkout@v3 |
36 | | - # Install clang-format |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
37 | 23 | - name: Install clang-format |
38 | | - run: sudo apt-get update && sudo apt-get install clang-format -y |
39 | | - # Run clang-format on all C++ files |
40 | | - - name: Run clang-format |
41 | 24 | run: | |
42 | | - find . -type f \( -name '*.h' -o -name '*.hpp' -o -name '*.cpp' \) \ |
43 | | - ! -path "*/build/*" ! -path "*/install/*" ! -path "*/log/*" \ |
44 | | - -exec clang-format -i -style=file {} \; |
45 | | - # Check if any files were modified |
46 | | - - name: Check for formatting changes |
| 25 | + sudo apt-get update |
| 26 | + sudo apt-get install -y clang-format-14 |
| 27 | + sudo ln -s /usr/bin/clang-format-14 /usr/bin/clang-format |
| 28 | +
|
| 29 | + - name: Run clang-format check |
47 | 30 | run: | |
48 | | - git diff --exit-code || (echo "Code formatting issues detected. Please run clang-format locally." && exit 1) |
| 31 | + FILES=$(find . -type f \( -name '*.h' -o -name '*.hpp' -o -name '*.cpp' \) \ |
| 32 | + ! -path "*/build/*" ! -path "*/install/*" ! -path "*/log/*") |
49 | 33 |
|
| 34 | + clang-format --dry-run --Werror -style=file $FILES |
50 | 35 |
|
0 commit comments