Skip to content

Commit 4917749

Browse files
authored
[CI][GHA] Update clang-format script to get changed files.
1 parent 6511333 commit 4917749

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

devops/actions/clang-format-SYCLomatic/action.yml

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,54 @@ runs:
1212

1313
- name: Get changed files
1414
id: changed-files
15-
uses: tj-actions/changed-files@v44
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
run: |
18+
PR_NUMBER=${{ github.event.pull_request.number }}
19+
REPO_FULL_NAME=${{ github.repository }}
20+
echo "Fetching changed files for PR #$PR_NUMBER in $REPO_FULL_NAME"
21+
22+
# Use GitHub API to get the list of changed files
23+
CHANGED_FILES=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
24+
-H "Accept: application/vnd.github.v3+json" \
25+
"https://api.github.com/repos/$REPO_FULL_NAME/pulls/$PR_NUMBER/files" \
26+
| jq -r '.[].filename')
27+
28+
echo "Changed files:"
29+
echo "$CHANGED_FILES"
30+
31+
# Set the output for the next steps
32+
echo "::set-output name=all_changed_files::$CHANGED_FILES"
1633
1734
- name: List Files
1835
shell: bash
1936
env:
2037
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
2138
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
39+
pattern_to_exclude_from_clang=".*clang/test/dpct"
40+
files_to_be_check=""
41+
echo "changed files are $CHANGED_FILES"
42+
43+
for i in $CHANGED_FILES
44+
do
45+
if [[ "$i" =~ ${pattern_to_exclude_from_clang} ]]; then
46+
echo "${i} will be excluded from format checking"
47+
else
48+
files_to_be_check="${files_to_be_check} $i"
49+
fi
50+
done
51+
52+
echo "git clang-format ${{ github.event.pull_request.base.sha }} ${files_to_be_check}"
53+
git clang-format ${{ github.event.pull_request.base.sha }} ${files_to_be_check} || echo "Files need to be formatted are detected."
54+
echo "before git diff"
55+
git diff > ./clang-format.patch
56+
57+
# Add patch with formatting fixes to CI job artifacts
4158
- uses: actions/upload-artifact@v4
4259
with:
4360
name: clang-format-patch
4461
path: ./clang-format.patch
62+
4563
- name: Check if clang-format patch is empty
4664
shell: bash
4765
run: bash -c "if [ -s ./clang-format.patch ]; then cat ./clang-format.patch; exit 1; fi"
48-

0 commit comments

Comments
 (0)