Skip to content

Commit 4ea8029

Browse files
authored
Merge pull request #2721 from oneapi-src/replace_tj_actions
[CI][GHA] Update clang-format script to get changed files.
2 parents 8de7546 + 42739ea commit 4ea8029

File tree

2 files changed

+49
-22
lines changed

2 files changed

+49
-22
lines changed

.github/workflows/ci_lin.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ jobs:
2727
fetch-depth: ${{ env.PR_FETCH_DEPTH }}
2828
- name: Run clang-format
2929
uses: ./devops/actions/clang-format-SYCLomatic
30-
30+
with:
31+
github_token: ${{ secrets.GITHUB_TOKEN }}

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

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: 'clang-format'
22
description: 'Run clang-format on pull request'
3+
inputs:
4+
github_token:
5+
description: 'GitHub Token'
6+
required: true
7+
38
runs:
49
using: "composite"
510
steps:
@@ -12,36 +17,57 @@ runs:
1217

1318
- name: Get changed files
1419
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
1641
1742
- name: List Files
1843
shell: bash
1944
env:
20-
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
45+
CHANGED_FILES: ${{ env.all_changed_files }}
2146
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
4166
- uses: actions/upload-artifact@v4
4267
with:
4368
name: clang-format-patch
4469
path: ./clang-format.patch
70+
4571
- name: Check if clang-format patch is empty
4672
shell: bash
4773
run: bash -c "if [ -s ./clang-format.patch ]; then cat ./clang-format.patch; exit 1; fi"

0 commit comments

Comments
 (0)