| 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 | |
| exclude-path: | |
| description: 'A path pattern to exclude from the search (passed to find -not -path)' | |
| required: false | |
| default: '' | |
| 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 }}" | |
| EXCLUDE_PATH="${{ inputs.exclude-path }}" | |
| 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}..." | |
| FIND_CMD="find \"${WORKING_DIR}\" -type f -name \"*.java\" -not -path \"./.git/*\"" | |
| if [ -n "$EXCLUDE_PATH" ]; then | |
| echo " excluding ${EXCLUDE_PATH}" | |
| FIND_CMD="${FIND_CMD} -not -path \"${EXCLUDE_PATH}\"" | |
| fi | |
| java_files=$(eval $FIND_CMD) | |
| 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_CMD | 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' |