@@ -75,96 +75,99 @@ jobs:
7575 exit $RC
7676
7777 lintrunner :
78- uses : pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
7978 needs : [get-changed-files]
79+ runs-on : ubuntu-latest
8080 permissions :
81- id-token : write
8281 contents : read
83- with :
84- runner : linux.2xlarge
85- docker-image : ci-image:executorch-ubuntu-22.04-linter
86- submodules : false
87- fetch-depth : 0
88- ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
89- timeout : 90
90- script : |
91- # The generic Linux job chooses to use base env, not the one setup by the image
92- CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
93- conda activate "${CONDA_ENV}"
94-
95- # Not sure why this isn't set up in the docker
96- # image. lintrunner-mypy seems to work becaus setup-linux.sh
97- # does this as part of install_executorch.
98- pip install -r requirements-dev.txt
99-
100- CACHE_DIRECTORY="/tmp/.lintbin"
101- # Try to recover the cached binaries
102- if [[ -d "${CACHE_DIRECTORY}" ]]; then
103- # It's ok to fail this as lintrunner init would download these binaries
104- # again if they do not exist
105- cp -r "${CACHE_DIRECTORY}" . || true
106- fi
107-
108- RC=0
109- CHANGED_FILES="${{ needs.get-changed-files.outputs.changed-files }}"
110- if [ "$CHANGED_FILES" = '*' ]; then
111- LINTRUNNER_FILES="--all-files"
112- else
113- LINTRUNNER_FILES="${CHANGED_FILES}"
114- fi
115- if ! lintrunner --force-color ${LINTRUNNER_FILES} --skip MYPY --tee-json=lint.json 2> /dev/null; then
116- echo ""
117- 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"
118- echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m"
119- RC=1
120- fi
121-
122- # Use jq to massage the JSON lint output into GitHub Actions workflow commands.
123- jq --raw-output \
124- '"::\(if .severity == "advice" or .severity == "disabled" then "warning" else .severity end) file=\(.path),line=\(.line),col=\(.char),title=\(.code) \(.name)::" + (.description | gsub("\\n"; "%0A"))' \
125- lint.json || true
126-
127- exit $RC
82+ steps :
83+ - uses : actions/checkout@v4
84+ with :
85+ fetch-depth : 0
86+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
87+
88+ - uses : actions/setup-python@v5
89+ with :
90+ python-version : ' 3.11'
91+ cache : ' pip'
92+ cache-dependency-path : requirements-lintrunner.txt
93+
94+ - name : Install lintrunner and linters
95+ run : |
96+ pip install lintrunner==0.12.7 lintrunner-adapters==0.13.0
97+ pip install -r requirements-lintrunner.txt
98+ lintrunner init
99+
100+ - name : Run linters
101+ env :
102+ CHANGED_FILES : ${{ needs.get-changed-files.outputs.changed-files }}
103+ run : |
104+ RC=0
105+ if [ "$CHANGED_FILES" = '*' ]; then
106+ LINTRUNNER_FILES="--all-files"
107+ else
108+ LINTRUNNER_FILES="${CHANGED_FILES}"
109+ fi
110+ if ! lintrunner --force-color ${LINTRUNNER_FILES} --skip MYPY --tee-json=lint.json 2> /dev/null; then
111+ echo ""
112+ 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"
113+ echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m"
114+ RC=1
115+ fi
116+
117+ # Use jq to massage the JSON lint output into GitHub Actions workflow commands.
118+ jq --raw-output \
119+ '"::\(if .severity == "advice" or .severity == "disabled" then "warning" else .severity end) file=\(.path),line=\(.line),col=\(.char),title=\(.code) \(.name)::" + (.description | gsub("\\n"; "%0A"))' \
120+ lint.json || true
121+
122+ exit $RC
128123
129124 link-check :
130125 uses : ./.github/workflows/_link_check.yml
131126 with :
132127 ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
133128
134129 android-java-format :
135- uses : pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
130+ runs-on : ubuntu-latest
136131 permissions :
137- id-token : write
138132 contents : read
139- with :
140- runner : linux.2xlarge
141- docker-image : ci-image:executorch-ubuntu-22.04-linter
142- fetch-depth : 0
143- ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
144- timeout : 90
145- script : |
146- FILES_NEEDS_FORMAT=$(find extension/android/executorch_android/src/main/java/org/pytorch/executorch \
147- extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm \
148- extension/android/executorch_android/src/main/java/org/pytorch/executorch/annotations \
149- extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch \
150- extension/benchmark/android/benchmark/app/src/main/java/org/pytorch/minibench \
151- extension/benchmark/android/benchmark/app/src/androidTest/java/org/pytorch/minibench \
152- -type f -name "*.java" 2>/dev/null | \
153- xargs -r /opt/google-java-format -n)
154-
155- if [ -n "$FILES_NEEDS_FORMAT" ]; then
156- echo "Warning: The following files need formatting:"
157- echo "$FILES_NEEDS_FORMAT"
158- echo ""
159- echo "Please use google-java-format from https://github.com/google/google-java-format/releases/"
160- echo ""
161- echo "To fix, run one of these commands:"
162- echo " # Using xargs (recommended):"
163- echo " find <paths> -type f -name '*.java' | xargs google-java-format -i"
164- echo ""
165- echo " # Or format specific files:"
166- echo "$FILES_NEEDS_FORMAT" | while IFS= read -r file; do
167- echo " google-java-format -i \"$file\""
168- done
169- exit 1
170- fi
133+ steps :
134+ - uses : actions/checkout@v4
135+ with :
136+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
137+
138+ - uses : actions/setup-java@v4
139+ with :
140+ distribution : ' temurin'
141+ java-version : ' 17'
142+
143+ - name : Check Java formatting
144+ run : |
145+ GOOGLE_JAVA_FORMAT_VERSION="1.24.0"
146+ 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" \
147+ -o /tmp/google-java-format.jar
148+
149+ FILES_NEEDS_FORMAT=$(find extension/android/executorch_android/src/main/java/org/pytorch/executorch \
150+ extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm \
151+ extension/android/executorch_android/src/main/java/org/pytorch/executorch/annotations \
152+ extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch \
153+ extension/benchmark/android/benchmark/app/src/main/java/org/pytorch/minibench \
154+ extension/benchmark/android/benchmark/app/src/androidTest/java/org/pytorch/minibench \
155+ -type f -name "*.java" 2>/dev/null | \
156+ xargs -r java -jar /tmp/google-java-format.jar -n)
157+
158+ if [ -n "$FILES_NEEDS_FORMAT" ]; then
159+ echo "Warning: The following files need formatting:"
160+ echo "$FILES_NEEDS_FORMAT"
161+ echo ""
162+ echo "Please use google-java-format from https://github.com/google/google-java-format/releases/"
163+ echo ""
164+ echo "To fix, run one of these commands:"
165+ echo " # Using xargs (recommended):"
166+ echo " find <paths> -type f -name '*.java' | xargs google-java-format -i"
167+ echo ""
168+ echo " # Or format specific files:"
169+ echo "$FILES_NEEDS_FORMAT" | while IFS= read -r file; do
170+ echo " google-java-format -i \"$file\""
171+ done
172+ exit 1
173+ fi
0 commit comments