forked from openucx/ucc
-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (90 loc) · 2.89 KB
/
codestyle.yaml
File metadata and controls
95 lines (90 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Codestyle
on: [pull_request]
# Cancel in-progress runs for the same PR
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
GIT_CF: https://raw.githubusercontent.com/llvm/llvm-project/release/21.x/clang/tools/clang-format/git-clang-format
CLANG_FORMAT_VERSION: "21.1.8"
jobs:
check-codestyle:
runs-on: ubuntu-22.04
name: Check code style
defaults:
run:
shell: bash
steps:
- name: Install dependencies
run: |
pipx install clang-format==${CLANG_FORMAT_VERSION}
curl -fsSL $GIT_CF -o git-clang-format
chmod +x ./git-clang-format
sudo mv ./git-clang-format /usr/bin/git-clang-format
- name: Checking out repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Check commit title
run: |
set -eE
range="remotes/origin/$GITHUB_BASE_REF..HEAD"
check_title() {
msg=$1
if [ ${#msg} -gt 50 ]
then
if ! echo $msg | grep -qP '^Merge'
then
echo "Commit title is too long: ${#msg}"
return 1
fi
fi
H1="CODESTYLE|REVIEW|CORE|UTIL|TEST|API|DOCS|TOOLS|BUILD|MC|EC|SCHEDULE|TOPO"
H2="CI|CL/|TL/|MC/|EC/|UCP|SHM|NCCL|SHARP|BASIC|HIER|DOCA_UROM|CUDA|CPU|EE|RCCL|ROCM|SELF|MLX5"
if ! echo $msg | grep -qP '^Merge |^'"(($H1)|($H2))"'+: \w'
then
echo "Wrong header"
return 1
fi
if [ "${msg: -1}" = "." ]
then
echo "Dot at the end of title"
return 1
fi
return 0
}
ok=1
for sha1 in `git log $range --format="%h"`
do
title=`git log -1 --format="%s" $sha1`
if check_title "$title"
then
echo "Good commit title: '$title'"
else
echo "Bad commit title: '$title'"
ok=0
fi
echo "--------------------------------------------------"
done
if [ $ok -ne 1 ]
then
exit 1
fi
- name: Check code format
run: |
set -eEuo pipefail
echo "Commit ${{ github.event.pull_request.base.sha }}"
diff=`git-clang-format --binary=clang-format --style=file --diff ${{ github.event.pull_request.base.sha }}` || true
if [ "$diff" = "no modified files to format" ] || [ "$diff" = "clang-format did not modify any files" ]
then
echo "Format check PASS"
else
echo "Format check FAILED"
echo ""
echo "Please format your code using:"
echo " git-clang-format --binary=clang-format ${{ github.event.pull_request.base.sha }}"
echo ""
echo "Formatting differences:"
echo "$diff"
fi