Skip to content

Commit

Permalink
Show warning if java code needs formatting
Browse files Browse the repository at this point in the history
Add a workflow for java formatting

Pull Request resolved: pytorch#4855
  • Loading branch information
kirklandsign authored Aug 23, 2024
1 parent 891521a commit 02a76ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .ci/docker/common/install_linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
# NB: Install all linter dependencies, the caching of lintrunner init could be
# done after Executorch becomes public
pip_install -r requirements-lintrunner.txt

# Install google-java-format
curl -L --retry 3 https://github.com/google/google-java-format/releases/download/v1.23.0/google-java-format_linux-x86-64 > /opt/google-java-format
chmod +x /opt/google-java-format
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,20 @@ jobs:
lint.json || true
exit $RC
android-java-format:
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
with:
runner: linux.2xlarge
docker-image: executorch-ubuntu-22.04-linter
fetch-depth: 0
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
script: |
FILES_NEEDS_FORMAT=$(/opt/google-java-format -n extension/android/src/main/java/org/pytorch/executorch/*.java \
examples/demo-apps/android/ExecuTorchDemo/app/src/main/java/com/example/executorchdemo/*.java \
examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/*.java)
if [ -n "$FILES_NEEDS_FORMAT" ]; then
echo "Warning: The following files need formatting. Please use google-java-format."
echo "$FILES_NEEDS_FORMAT"
exit 1
fi

0 comments on commit 02a76ea

Please sign in to comment.