Skip to content

Commit 9849007

Browse files
[infra] Manually run google-java-format instead of using an action (#2414)
1 parent c27b84e commit 9849007

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: 'Java Format Check'
2+
description: 'Check Java files formatting using google-java-format (Ubuntu/Linux runners only)'
3+
4+
inputs:
5+
version:
6+
description: 'The version of google-java-format to use. Use without the initial "v".'
7+
required: false
8+
default: '1.28.0'
9+
working-directory:
10+
description: 'The directory to search for Java files (relative to repository root)'
11+
required: true
12+
13+
runs:
14+
using: 'composite'
15+
steps:
16+
- name: Run google-java-format
17+
if: runner.os == 'Linux'
18+
shell: bash
19+
run: |
20+
GJF_VERSION="${{ inputs.version }}"
21+
WORKING_DIR="${{ inputs.working-directory }}"
22+
23+
echo "Downloading google-java-format v${GJF_VERSION}..."
24+
curl -L -s -o google-java-format.jar "https://github.com/google/google-java-format/releases/download/v${GJF_VERSION}/google-java-format-${GJF_VERSION}-all-deps.jar"
25+
26+
echo "Finding all .java files in ${WORKING_DIR}..."
27+
java_files=$(find "${WORKING_DIR}" -type f -name "*.java" -not -path "./.git/*")
28+
29+
if [ -z "$java_files" ]; then
30+
echo "No Java files found in ${WORKING_DIR}"
31+
exit 0
32+
fi
33+
34+
echo "Found $(echo "$java_files" | wc -l) Java files to check"
35+
36+
non_compliant_files=$(echo "$java_files" | xargs java -jar google-java-format.jar -n)
37+
38+
if [ -n "$non_compliant_files" ]; then
39+
echo "❌ The following Java files are not formatted correctly:"
40+
echo "$non_compliant_files"
41+
echo ""
42+
echo "To fix formatting issues, run:"
43+
echo "find \"${WORKING_DIR}\" -name '*.java' -not -path './.git/*' | xargs java -jar google-java-format.jar --replace"
44+
exit 1
45+
else
46+
echo "✅ All Java files are properly formatted."
47+
fi
48+
49+
- name: Unsupported OS
50+
if: runner.os != 'Linux'
51+
shell: bash
52+
run: |
53+
echo "❌ This action only supports Linux runners"
54+
echo "Please use a Linux runner to run this action."
55+
exit 1
56+
57+
branding:
58+
icon: 'check-circle'
59+
color: 'green'

.github/workflows/jnigen.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ jobs:
4646
channel: ${{ matrix.sdk }}
4747
cache: true
4848
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
49-
- uses: axel-op/googlejavaformat-action@c1134ebd196c4cbffb077f9476585b0be8b6afcd
50-
name: 'Check Java formatting with google-java-format'
49+
- uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00
50+
with:
51+
distribution: 'zulu'
52+
java-version: '17'
53+
cache: maven
54+
- uses: ./.github/actions/java-format-check
5155
with:
52-
version: 'v1.24.0'
53-
args: '--set-exit-if-changed'
56+
working-directory: ./pkgs/jnigen
5457
- id: install
5558
name: Install dependencies
5659
run: dart pub get
@@ -164,11 +167,9 @@ jobs:
164167
with:
165168
distribution: 'zulu'
166169
java-version: '17'
167-
- uses: axel-op/googlejavaformat-action@c1134ebd196c4cbffb077f9476585b0be8b6afcd
168-
name: 'Check Java formatting with google-java-format'
170+
- uses: ./.github/actions/java-format-check
169171
with:
170-
version: 'v1.24.0'
171-
args: '--set-exit-if-changed'
172+
working-directory: ./pkgs/jni
172173
- name: install clang tools & CMake
173174
run: |
174175
sudo apt-get update -y

0 commit comments

Comments
 (0)