| name: 'Java Format Check' |
| description: 'Check Java files formatting using google-java-format (Ubuntu/Linux runners only)' |
| |
| inputs: |
| version: |
| description: 'The version of google-java-format to use. Use without the initial "v".' |
| required: false |
| default: '1.28.0' |
| working-directory: |
| description: 'The directory to search for Java files (relative to repository root)' |
| required: true |
| |
| runs: |
| using: 'composite' |
| steps: |
| - name: Run google-java-format |
| if: runner.os == 'Linux' |
| shell: bash |
| run: | |
| GJF_VERSION="${{ inputs.version }}" |
| WORKING_DIR="${{ inputs.working-directory }}" |
| |
| echo "Downloading google-java-format v${GJF_VERSION}..." |
| 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" |
| |
| echo "Finding all .java files in ${WORKING_DIR}..." |
| java_files=$(find "${WORKING_DIR}" -type f -name "*.java" -not -path "./.git/*") |
| |
| if [ -z "$java_files" ]; then |
| echo "No Java files found in ${WORKING_DIR}" |
| exit 0 |
| fi |
| |
| echo "Found $(echo "$java_files" | wc -l) Java files to check" |
| |
| non_compliant_files=$(echo "$java_files" | xargs java -jar google-java-format.jar -n) |
| |
| if [ -n "$non_compliant_files" ]; then |
| echo "❌ The following Java files are not formatted correctly:" |
| echo "$non_compliant_files" |
| echo "" |
| echo "To fix formatting issues, run:" |
| echo "find \"${WORKING_DIR}\" -name '*.java' -not -path './.git/*' | xargs java -jar google-java-format.jar --replace" |
| exit 1 |
| else |
| echo "✅ All Java files are properly formatted." |
| fi |
| |
| - name: Unsupported OS |
| if: runner.os != 'Linux' |
| shell: bash |
| run: | |
| echo "❌ This action only supports Linux runners" |
| echo "Please use a Linux runner to run this action." |
| exit 1 |
| |
| branding: |
| icon: 'check-circle' |
| color: 'green' |