-
Notifications
You must be signed in to change notification settings - Fork 1k
173 lines (150 loc) · 7.03 KB
/
lint.yml
File metadata and controls
173 lines (150 loc) · 7.03 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Lint
on:
pull_request:
branches-ignore:
- nightly
push:
branches:
- main
- release/*
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
cancel-in-progress: true
jobs:
get-changed-files:
if: github.repository_owner == 'pytorch'
name: Get changed files
uses: ./.github/workflows/_get-changed-files.yml
lintrunner-mypy:
needs: [get-changed-files]
runs-on: ubuntu-latest
permissions:
contents: read
if: |
needs.get-changed-files.outputs.changed-files == '*' ||
contains(needs.get-changed-files.outputs.changed-files, '.py') ||
contains(needs.get-changed-files.outputs.changed-files, '.pyi')
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Checkout torchao submodule
run: git submodule update --init third-party/ao
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: requirements-lintrunner.txt
- name: Install dependencies
run: |
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install lintrunner==0.12.7 lintrunner-adapters==0.13.0
pip install -r requirements-lintrunner.txt
USE_CPP=0 pip install --no-build-isolation third-party/ao
pip install pytest numpy parameterized huggingface_hub transformers timm expecttest types-requests
pip install torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
- name: Generate mypy stubs for C++ bindings
run: |
cp extension/pybindings/pybindings.pyi extension/pybindings/_portable_lib.pyi
- name: Run mypy
run: |
lintrunner init
RC=0
if ! lintrunner --force-color --all-files --take MYPY --tee-json=lint.json 2> /dev/null; then
echo ""
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner --take MYPY\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m"
echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m"
RC=1
fi
# Use jq to massage the JSON lint output into GitHub Actions workflow commands.
jq --raw-output \
'"::\(if .severity == "advice" or .severity == "disabled" then "warning" else .severity end) file=\(.path),line=\(.line),col=\(.char),title=\(.code) \(.name)::" + (.description | gsub("\\n"; "%0A"))' \
lint.json || true
exit $RC
lintrunner:
needs: [get-changed-files]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: requirements-lintrunner.txt
- name: Install lintrunner and linters
run: |
pip install lintrunner==0.12.7 lintrunner-adapters==0.13.0
pip install -r requirements-lintrunner.txt
lintrunner init
- name: Run linters
env:
CHANGED_FILES: ${{ needs.get-changed-files.outputs.changed-files }}
run: |
RC=0
if [ "$CHANGED_FILES" = '*' ]; then
LINTRUNNER_FILES="--all-files"
else
LINTRUNNER_FILES="${CHANGED_FILES}"
fi
if ! lintrunner --force-color ${LINTRUNNER_FILES} --skip MYPY --tee-json=lint.json 2> /dev/null; then
echo ""
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner --skip MYPY\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m"
echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m"
RC=1
fi
# Use jq to massage the JSON lint output into GitHub Actions workflow commands.
jq --raw-output \
'"::\(if .severity == "advice" or .severity == "disabled" then "warning" else .severity end) file=\(.path),line=\(.line),col=\(.char),title=\(.code) \(.name)::" + (.description | gsub("\\n"; "%0A"))' \
lint.json || true
exit $RC
link-check:
uses: ./.github/workflows/_link_check.yml
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
android-java-format:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Check Java formatting
run: |
GOOGLE_JAVA_FORMAT_VERSION="1.24.0"
curl -sSfL "https://github.com/google/google-java-format/releases/download/v${GOOGLE_JAVA_FORMAT_VERSION}/google-java-format-${GOOGLE_JAVA_FORMAT_VERSION}-all-deps.jar" \
-o /tmp/google-java-format.jar
FILES_NEEDS_FORMAT=$(find extension/android/executorch_android/src/main/java/org/pytorch/executorch \
extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm \
extension/android/executorch_android/src/main/java/org/pytorch/executorch/annotations \
extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch \
extension/benchmark/android/benchmark/app/src/main/java/org/pytorch/minibench \
extension/benchmark/android/benchmark/app/src/androidTest/java/org/pytorch/minibench \
-type f -name "*.java" 2>/dev/null | \
xargs -r java -jar /tmp/google-java-format.jar -n)
if [ -n "$FILES_NEEDS_FORMAT" ]; then
echo "Warning: The following files need formatting:"
echo "$FILES_NEEDS_FORMAT"
echo ""
echo "Please use google-java-format from https://github.com/google/google-java-format/releases/"
echo ""
echo "To fix, run one of these commands:"
echo " # Using xargs (recommended):"
echo " find <paths> -type f -name '*.java' | xargs google-java-format -i"
echo ""
echo " # Or format specific files:"
echo "$FILES_NEEDS_FORMAT" | while IFS= read -r file; do
echo " google-java-format -i \"$file\""
done
exit 1
fi