@@ -7,41 +7,55 @@ on: # yamllint disable-line rule:truthy
7
7
jobs :
8
8
clang-format :
9
9
runs-on : ubuntu-latest
10
+ container :
11
+ image : dtors/base-cpp:latest
10
12
11
13
steps :
12
14
- name : Checkout code
13
- uses : actions/checkout@v3
14
- - name : Get changed files
15
- uses : jitterbit/get-changed-files@v1
16
- id : changed_files
17
- with :
18
- format : space-delimited
19
- token : ${{ secrets.GITHUB_TOKEN }}
20
- - name : Set up clang-format
21
- run : sudo apt-get install clang-format
22
- - name : Run clang-format
23
- run : |-
24
- IFS=' ' read -r -a files <<< "${{ steps.changed_files.outputs.all }}"
25
- cpp_files=()
26
- for file in "${files[@]}"; do
27
- if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
28
- cpp_files+=("$file")
29
- fi
30
- done
31
-
32
- if [ ${#cpp_files[@]} -gt 0 ]; then
33
- echo -e "Running clang-format"
34
- clang-format --dry-run --Werror "${cpp_files[@]}"
35
- else
36
- echo -e "Skipping clang-format since no source files were changed."
37
- fi
15
+ uses : actions/checkout@v4
16
+
17
+ - name : Configure Git Safe Directory
18
+ run : |
19
+ git config --global --add safe.directory $(pwd)
20
+
21
+ - name : Find affected files
22
+ run : |
23
+ git fetch origin ${{ github.base_ref }} --depth=1
24
+ git diff --name-only origin/${{ github.base_ref }} > affected_files.txt
25
+ echo "Affected files:"
26
+ cat affected_files.txt
27
+
28
+ - name : Find affected cpp files
29
+ run : |
30
+ > affected_cpp_files.txt
31
+
32
+ while read file; do
33
+ if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
34
+ echo "$file" >> affected_cpp_files.txt
35
+ fi
36
+ done < affected_files.txt
37
+
38
+ sort -u affected_cpp_files.txt -o affected_cpp_files.txt
39
+ echo "Affected cpp files:"
40
+ cat affected_cpp_files.txt
41
+ echo "cpp_files=$(cat affected_cpp_files.txt | tr '\n' ' ')" >> $GITHUB_ENV
42
+ shell : bash
43
+
44
+ - name : Run Clang-Format
45
+ if : env.cpp_files != ''
46
+ run : |
47
+ echo "Running: clang-format --dry-run --Werror ${cpp_files}"
48
+ clang-format --dry-run --Werror ${cpp_files}
49
+
50
+ - name : Skip Clang-Format
51
+ if : env.cpp_files == ''
52
+ run : echo "No affected cpp files found. Skipping Clang-Format."
53
+
38
54
- name : Show failure message
39
55
if : failure()
40
56
run : |-
41
57
echo -e "To automatically apply suggested fixes, run the following command:
42
58
======================================================================================
43
- 1. Install clang-format:
44
- sudo apt-get install clang-format
45
- 2. Run clang-format:
59
+ 1. Run clang-format:
46
60
find . -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.hpp\" -o -name \"*.cc\" -o -name \"*.cxx\" -o -name \"*.hxx\" | xargs clang-format -i
47
61
======================================================================================"
0 commit comments