1name: Lint 2 3on: 4 pull_request: 5 branches-ignore: 6 - nightly 7 push: 8 branches: 9 - main 10 - release/* 11 workflow_dispatch: 12 13concurrency: 14 group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }} 15 cancel-in-progress: true 16 17jobs: 18 lintrunner: 19 uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.5 20 with: 21 runner: linux.2xlarge 22 docker-image: executorch-ubuntu-22.04-linter 23 fetch-depth: 0 24 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} 25 timeout: 90 26 script: | 27 # The generic Linux job chooses to use base env, not the one setup by the image 28 CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]") 29 conda activate "${CONDA_ENV}" 30 31 CACHE_DIRECTORY="/tmp/.lintbin" 32 # Try to recover the cached binaries 33 if [[ -d "${CACHE_DIRECTORY}" ]]; then 34 # It's ok to fail this as lintrunner init would download these binaries 35 # again if they do not exist 36 cp -r "${CACHE_DIRECTORY}" . || true 37 fi 38 39 # This has already been cached in the docker image 40 lintrunner init 2> /dev/null 41 42 RC=0 43 # Run lintrunner on all files 44 if ! lintrunner --force-color --all-files --tee-json=lint.json 2> /dev/null; then 45 echo "" 46 echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m" 47 echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m" 48 RC=1 49 fi 50 51 # Use jq to massage the JSON lint output into GitHub Actions workflow commands. 52 jq --raw-output \ 53 '"::\(if .severity == "advice" or .severity == "disabled" then "warning" else .severity end) file=\(.path),line=\(.line),col=\(.char),title=\(.code) \(.name)::" + (.description | gsub("\\n"; "%0A"))' \ 54 lint.json || true 55 56 exit $RC 57 58 android-java-format: 59 uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.5 60 with: 61 runner: linux.2xlarge 62 docker-image: executorch-ubuntu-22.04-linter 63 fetch-depth: 0 64 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} 65 script: | 66 FILES_NEEDS_FORMAT=$(/opt/google-java-format -n extension/android/src/main/java/org/pytorch/executorch/*.java \ 67 examples/demo-apps/android/ExecuTorchDemo/app/src/main/java/com/example/executorchdemo/*.java \ 68 examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/*.java \ 69 extension/benchmark/android/benchmark/app/src/main/java/org/pytorch/minibench/*.java) 70 if [ -n "$FILES_NEEDS_FORMAT" ]; then 71 echo "Warning: The following files need formatting. Please use google-java-format." 72 echo "Use a binary from https://github.com/google/google-java-format/releases/" 73 echo "For example:" 74 echo "wget https://github.com/google/google-java-format/releases/download/v1.23.0/google-java-format_linux-x86-64" 75 echo "chmod +x google-java-format_linux-x86-64" 76 echo "./google-java-format_linux-x86-64 -i $FILES_NEEDS_FORMAT" 77 exit 1 78 fi 79