-
Notifications
You must be signed in to change notification settings - Fork 576
113 lines (108 loc) · 4.78 KB
/
Copy pathlintercheck.yml
File metadata and controls
113 lines (108 loc) · 4.78 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Linter check
on:
pull_request:
push:
branches:
- master
tags:
- r[0-9]+.[0-9]+
jobs:
check_code_changes:
name: Check Code Changes
uses: ./.github/workflows/_check_code_changes.yml
with:
event_name: ${{ github.event_name }}
# For pull_request, use PR's base and head. For push, use event's before and sha.
base_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
head_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
linter_check:
runs-on: ubuntu-24.04
needs: [check_code_changes]
steps:
- name: Checkout repo
if: needs.check_code_changes.outputs.has_code_changes == 'true'
uses: actions/checkout@v3
- name: Setup Python
if: needs.check_code_changes.outputs.has_code_changes == 'true'
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
- run: pip install yapf==0.40.2 # N.B.: keep in sync with `infra/ansible/config/pip.yaml`
- name: Check no TORCH_PIN
if: >
(github.event_name == 'push' && github.event.ref == 'refs/heads/master') &&
needs.check_code_changes.outputs.has_code_changes == 'true'
shell: bash
run: |
TORCH_PIN=./.torch_pin
if [[ -f "${TORCH_PIN}" ]]; then
echo "Please remove ${TORCH_PIN} before landing."
exit 1
else
echo "No ${TORCH_PIN} found, safe to land..."
fi
- name: Check .cc file extension
shell: bash
run: |
# Find *.cc files recursively in the current directory, limiting to files only.
found_files=$(find . -type f -name "*.cc")
# Check if any files were found.
if [ -n "$found_files" ]; then
echo "Found *.cc files:"
echo "$found_files"
echo "Please rename them to *.cpp for consistency."
exit 1
else
echo "PASSED *.cc file extension check"
fi
- name: Run clang-format
if: needs.check_code_changes.outputs.has_code_changes == 'true'
shell: bash
env:
CLANG_FORMAT: clang-format-16
run: |
sudo apt-get update
sudo apt install -y "${CLANG_FORMAT}"
git_status=$(git status --porcelain)
if [[ $git_status ]]; then
echo "Checkout code is not clean"
echo "${git_status}"
exit 1
fi
find . -name '*.cpp' -o -name '*.h' -o -name '*.cc' | xargs "${CLANG_FORMAT}" -i -style=file
git_status=$(git status --porcelain)
if [[ $git_status ]]; then
git diff
echo "${CLANG_FORMAT} recommends the changes above, please manually apply them OR automatically apply the changes "
echo "by running \"${CLANG_FORMAT} -i -style=file /PATH/TO/foo.cpp\" to the following files"
echo "${git_status}"
exit 1
else
echo "PASSED C++ format"
fi
- name: Run yapf
if: needs.check_code_changes.outputs.has_code_changes == 'true'
shell: bash
run: |
git_status=$(git status --porcelain)
if [[ $git_status ]]; then
echo "Checkout code is not clean"
echo "${git_status}"
exit 1
fi
yapf -i -r *.py test/ scripts/ torch_xla/ benchmarks/
git_status=$(git status --porcelain)
if [[ $git_status ]]; then
git diff
echo "yapf recommends the changes above, please manually apply them OR automatically apply the changes "
echo "by running `yapf -i /PATH/TO/foo.py` to the following files"
echo "${git_status}"
exit 1
else
echo "PASSED Python format"
fi
- name: Report no code changes
if: needs.check_code_changes.outputs.has_code_changes == 'false'
run: |
echo "No code changes were detected that require running the full test suite."