1
1
name : ' clang-format'
2
2
description : ' Run clang-format on pull request'
3
+ inputs :
4
+ github_token :
5
+ description : ' GitHub Token'
6
+ required : true
7
+
3
8
runs :
4
9
using : " composite"
5
10
steps :
@@ -12,36 +17,57 @@ runs:
12
17
13
18
- name : Get changed files
14
19
id : changed-files
15
- uses : tj-actions/changed-files@v44
20
+ shell : bash
21
+ env :
22
+ GITHUB_TOKEN : ${{ inputs.github_token }}
23
+ run : |
24
+ PR_NUMBER=${{ github.event.pull_request.number }}
25
+ REPO_FULL_NAME=${{ github.repository }}
26
+ echo "Fetching changed files for PR #$PR_NUMBER in $REPO_FULL_NAME"
27
+
28
+ # Use GitHub API to get the list of changed files
29
+ CHANGED_FILES=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
30
+ -H "Accept: application/vnd.github.v3+json" \
31
+ "https://api.github.com/repos/$REPO_FULL_NAME/pulls/$PR_NUMBER/files" \
32
+ | jq -r '.[].filename')
33
+
34
+ echo "Changed files:"
35
+ echo "$CHANGED_FILES"
36
+
37
+ CHANGED_FILES_JOINED=$(echo "$CHANGED_FILES" | tr '\n' ' ')
38
+
39
+ # Set the output for the next steps using environment files
40
+ echo "all_changed_files=$CHANGED_FILES_JOINED" >> $GITHUB_ENV
16
41
17
42
- name : List Files
18
43
shell : bash
19
44
env :
20
- CHANGED_FILES : ${{ steps.changed-files.outputs .all_changed_files }}
45
+ CHANGED_FILES : ${{ env .all_changed_files }}
21
46
run : |
22
- pattern_to_exclude_from_clang=".*clang/test/dpct"
23
- files_to_be_check=""
24
- echo "changed files are $CHANGED_FILES"
25
-
26
- for i in $CHANGED_FILES
27
- do
28
- if [[ "$i" =~ ${pattern_to_exclude_from_clang} ]];then
29
- echo "${i} will be excluded from format checking"
30
- else
31
- files_to_be_check="${files_to_be_check} $i"
32
- fi
33
-
34
- done
35
-
36
- echo " git clang-format ${{ github.event.pull_request.base.sha }} ${files_to_be_check}"
37
- git clang-format ${{ github.event.pull_request.base.sha }} ${files_to_be_check} || echo "Files need to be formated are detected. "
38
- echo "before git diff"
39
- git diff > ./clang-format.patch
40
- # Add patch with formatting fixes to CI job artifacts
47
+ pattern_to_exclude_from_clang=".*clang/test/dpct"
48
+ files_to_be_check=""
49
+ echo "changed files are $CHANGED_FILES"
50
+
51
+ for i in $CHANGED_FILES
52
+ do
53
+ if [[ "$i" =~ ${pattern_to_exclude_from_clang} ]]; then
54
+ echo "${i} will be excluded from format checking"
55
+ else
56
+ files_to_be_check="${files_to_be_check} $i"
57
+ fi
58
+ done
59
+
60
+ echo "git clang-format ${{ github.event.pull_request.base.sha }} ${files_to_be_check}"
61
+ git clang-format ${{ github.event.pull_request.base.sha }} ${files_to_be_check} || echo "Files need to be formatted are detected. "
62
+ echo "before git diff "
63
+ git diff > ./clang-format.patch
64
+
65
+ # Add patch with formatting fixes to CI job artifacts
41
66
- uses : actions/upload-artifact@v4
42
67
with :
43
68
name : clang-format-patch
44
69
path : ./clang-format.patch
70
+
45
71
- name : Check if clang-format patch is empty
46
72
shell : bash
47
73
run : bash -c "if [ -s ./clang-format.patch ]; then cat ./clang-format.patch; exit 1; fi"
0 commit comments