|
1 | 1 | name: Linter check
|
2 | 2 | on:
|
3 |
| - pull_request: |
4 |
| - push: |
5 |
| - branches: |
6 |
| - - master |
7 |
| - tags: |
8 |
| - - r[0-9]+.[0-9]+ |
| 3 | + pull_request: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + tags: |
| 8 | + - r[0-9]+.[0-9]+ |
9 | 9 |
|
10 | 10 | jobs:
|
11 |
| - check_code_changes: |
12 |
| - name: Check Code Changes |
13 |
| - uses: ./.github/workflows/_check_code_changes.yml |
14 |
| - with: |
15 |
| - event_name: ${{ github.event_name }} |
16 |
| - # For pull_request, use PR's base and head. For push, use event's before and sha. |
17 |
| - base_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} |
18 |
| - head_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} |
19 |
| - linter_check: |
20 |
| - runs-on: ubuntu-24.04 |
21 |
| - needs: [check_code_changes] |
22 |
| - steps: |
23 |
| - - name: Checkout repo |
24 |
| - if: needs.check_code_changes.outputs.has_code_changes == 'true' |
25 |
| - uses: actions/checkout@v3 |
26 |
| - - name: Setup Python |
27 |
| - if: needs.check_code_changes.outputs.has_code_changes == 'true' |
28 |
| - uses: actions/setup-python@v4 |
| 11 | + check_code_changes: |
| 12 | + name: Check Code Changes |
| 13 | + uses: ./.github/workflows/_check_code_changes.yml |
29 | 14 | with:
|
30 |
| - python-version: '3.10' |
31 |
| - cache: 'pip' |
32 |
| - - run: pip install yapf==0.40.2 # N.B.: keep in sync with `torchax/dev-requirements.txt`, `infra/ansible/config/pip.yaml` |
| 15 | + event_name: ${{ github.event_name }} |
| 16 | + # For pull_request, use PR's base and head. For push, use event's before and sha. |
| 17 | + base_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} |
| 18 | + head_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} |
| 19 | + linter_check: |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + needs: [check_code_changes] |
| 22 | + steps: |
| 23 | + - name: Checkout repo |
| 24 | + if: needs.check_code_changes.outputs.has_code_changes == 'true' |
| 25 | + uses: actions/checkout@v3 |
| 26 | + - name: Setup Python |
| 27 | + if: needs.check_code_changes.outputs.has_code_changes == 'true' |
| 28 | + uses: actions/setup-python@v4 |
| 29 | + with: |
| 30 | + python-version: "3.10" |
| 31 | + cache: "pip" |
| 32 | + - run: pip install yapf==0.40.2 # N.B.: keep in sync with `infra/ansible/config/pip.yaml` |
33 | 33 |
|
34 |
| - - name: Check no TORCH_PIN |
35 |
| - if: > |
36 |
| - (github.event_name == 'push' && github.event.ref == 'refs/heads/master') && |
37 |
| - needs.check_code_changes.outputs.has_code_changes == 'true' |
38 |
| - shell: bash |
39 |
| - run: | |
40 |
| - TORCH_PIN=./.torch_pin |
41 |
| - if [[ -f "${TORCH_PIN}" ]]; then |
42 |
| - echo "Please remove ${TORCH_PIN} before landing." |
43 |
| - exit 1 |
44 |
| - else |
45 |
| - echo "No ${TORCH_PIN} found, safe to land..." |
46 |
| - fi |
47 |
| - - name: Check .cc file extension |
48 |
| - shell: bash |
49 |
| - run: | |
50 |
| - # Find *.cc files recursively in the current directory, limiting to files only. |
51 |
| - found_files=$(find . -type f -name "*.cc") |
| 34 | + - name: Check no TORCH_PIN |
| 35 | + if: > |
| 36 | + (github.event_name == 'push' && github.event.ref == 'refs/heads/master') && |
| 37 | + needs.check_code_changes.outputs.has_code_changes == 'true' |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + TORCH_PIN=./.torch_pin |
| 41 | + if [[ -f "${TORCH_PIN}" ]]; then |
| 42 | + echo "Please remove ${TORCH_PIN} before landing." |
| 43 | + exit 1 |
| 44 | + else |
| 45 | + echo "No ${TORCH_PIN} found, safe to land..." |
| 46 | + fi |
| 47 | + - name: Check .cc file extension |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + # Find *.cc files recursively in the current directory, limiting to files only. |
| 51 | + found_files=$(find . -type f -name "*.cc") |
52 | 52 |
|
53 |
| - # Check if any files were found. |
54 |
| - if [ -n "$found_files" ]; then |
55 |
| - echo "Found *.cc files:" |
56 |
| - echo "$found_files" |
57 |
| - echo "Please rename them to *.cpp for consistency." |
58 |
| - exit 1 |
59 |
| - else |
60 |
| - echo "PASSED *.cc file extension check" |
61 |
| - fi |
62 |
| - - name: Run clang-format |
63 |
| - if: needs.check_code_changes.outputs.has_code_changes == 'true' |
64 |
| - shell: bash |
65 |
| - env: |
66 |
| - CLANG_FORMAT: clang-format-16 |
67 |
| - run: | |
68 |
| - sudo apt-get update |
69 |
| - sudo apt install -y "${CLANG_FORMAT}" |
70 |
| - git_status=$(git status --porcelain) |
71 |
| - if [[ $git_status ]]; then |
72 |
| - echo "Checkout code is not clean" |
73 |
| - echo "${git_status}" |
74 |
| - exit 1 |
75 |
| - fi |
| 53 | + # Check if any files were found. |
| 54 | + if [ -n "$found_files" ]; then |
| 55 | + echo "Found *.cc files:" |
| 56 | + echo "$found_files" |
| 57 | + echo "Please rename them to *.cpp for consistency." |
| 58 | + exit 1 |
| 59 | + else |
| 60 | + echo "PASSED *.cc file extension check" |
| 61 | + fi |
| 62 | + - name: Run clang-format |
| 63 | + if: needs.check_code_changes.outputs.has_code_changes == 'true' |
| 64 | + shell: bash |
| 65 | + env: |
| 66 | + CLANG_FORMAT: clang-format-16 |
| 67 | + run: | |
| 68 | + sudo apt-get update |
| 69 | + sudo apt install -y "${CLANG_FORMAT}" |
| 70 | + git_status=$(git status --porcelain) |
| 71 | + if [[ $git_status ]]; then |
| 72 | + echo "Checkout code is not clean" |
| 73 | + echo "${git_status}" |
| 74 | + exit 1 |
| 75 | + fi |
76 | 76 |
|
77 |
| - find . -name '*.cpp' -o -name '*.h' -o -name '*.cc' | xargs "${CLANG_FORMAT}" -i -style=file |
78 |
| - git_status=$(git status --porcelain) |
79 |
| - if [[ $git_status ]]; then |
80 |
| - git diff |
81 |
| - echo "${CLANG_FORMAT} recommends the changes above, please manually apply them OR automatically apply the changes " |
82 |
| - echo "by running \"${CLANG_FORMAT} -i -style=file /PATH/TO/foo.cpp\" to the following files" |
83 |
| - echo "${git_status}" |
84 |
| - exit 1 |
85 |
| - else |
86 |
| - echo "PASSED C++ format" |
87 |
| - fi |
88 |
| - - name: Run yapf |
89 |
| - if: needs.check_code_changes.outputs.has_code_changes == 'true' |
90 |
| - shell: bash |
91 |
| - run: | |
92 |
| - git_status=$(git status --porcelain) |
93 |
| - if [[ $git_status ]]; then |
94 |
| - echo "Checkout code is not clean" |
95 |
| - echo "${git_status}" |
96 |
| - exit 1 |
97 |
| - fi |
| 77 | + find . -name '*.cpp' -o -name '*.h' -o -name '*.cc' | xargs "${CLANG_FORMAT}" -i -style=file |
| 78 | + git_status=$(git status --porcelain) |
| 79 | + if [[ $git_status ]]; then |
| 80 | + git diff |
| 81 | + echo "${CLANG_FORMAT} recommends the changes above, please manually apply them OR automatically apply the changes " |
| 82 | + echo "by running \"${CLANG_FORMAT} -i -style=file /PATH/TO/foo.cpp\" to the following files" |
| 83 | + echo "${git_status}" |
| 84 | + exit 1 |
| 85 | + else |
| 86 | + echo "PASSED C++ format" |
| 87 | + fi |
| 88 | + - name: Run yapf |
| 89 | + if: needs.check_code_changes.outputs.has_code_changes == 'true' |
| 90 | + shell: bash |
| 91 | + run: | |
| 92 | + git_status=$(git status --porcelain) |
| 93 | + if [[ $git_status ]]; then |
| 94 | + echo "Checkout code is not clean" |
| 95 | + echo "${git_status}" |
| 96 | + exit 1 |
| 97 | + fi |
98 | 98 |
|
99 |
| - yapf -i -r *.py test/ scripts/ torch_xla/ benchmarks/ torchax/ |
100 |
| - git_status=$(git status --porcelain) |
101 |
| - if [[ $git_status ]]; then |
102 |
| - git diff |
103 |
| - echo "yapf recommends the changes above, please manually apply them OR automatically apply the changes " |
104 |
| - echo "by running `yapf -i /PATH/TO/foo.py` to the following files" |
105 |
| - echo "${git_status}" |
106 |
| - exit 1 |
107 |
| - else |
108 |
| - echo "PASSED Python format" |
109 |
| - fi |
110 |
| - - name: Report no code changes |
111 |
| - if: needs.check_code_changes.outputs.has_code_changes == 'false' |
112 |
| - run: | |
113 |
| - echo "No code changes were detected that require running the full test suite." |
| 99 | + yapf -i -r *.py test/ scripts/ torch_xla/ benchmarks/ |
| 100 | + git_status=$(git status --porcelain) |
| 101 | + if [[ $git_status ]]; then |
| 102 | + git diff |
| 103 | + echo "yapf recommends the changes above, please manually apply them OR automatically apply the changes " |
| 104 | + echo "by running `yapf -i /PATH/TO/foo.py` to the following files" |
| 105 | + echo "${git_status}" |
| 106 | + exit 1 |
| 107 | + else |
| 108 | + echo "PASSED Python format" |
| 109 | + fi |
| 110 | + - name: Report no code changes |
| 111 | + if: needs.check_code_changes.outputs.has_code_changes == 'false' |
| 112 | + run: | |
| 113 | + echo "No code changes were detected that require running the full test suite." |
0 commit comments