Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/actions/format/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Format Java Code'
description: 'Runs mvn spotless:apply'
inputs:
path:
description: 'Path to the java repository'
required: true
runs:
using: 'composite'
steps:
- name: Set up JDK 20 for formatting
uses: actions/setup-java@v4
with:
java-version: '20'
distribution: 'adopt'

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles(format('{0}/**/pom.xml', inputs.path)) }}
restore-keys: |
${{ runner.os }}-m2-
Comment on lines +10 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This section can be simplified and improved.

  1. JDK Version: The pom.xml for this repository specifies Java 11. It's best practice to align the JDK version in the CI with the project's version to avoid potential inconsistencies.
  2. Maven Caching: The actions/setup-java action has built-in caching for Maven, which is simpler and the recommended approach. This removes the need for a separate actions/cache step. By using cache-dependency-path, we can scope the cache to the specific pom.xml files relevant to the path, just like in the original implementation.
  3. Java Distribution: The adopt distribution is deprecated in actions/setup-java@v4. It's recommended to use temurin instead.

You can combine setting up Java and caching into a single, updated step.

    - name: Set up JDK 11 for formatting
      uses: actions/setup-java@v4
      with:
        java-version: '11'
        distribution: 'temurin'
        cache: 'maven'
        cache-dependency-path: '${{ inputs.path }}/**/pom.xml'

- name: Run Spotless Apply
run: mvn spotless:apply
shell: bash
working-directory: ${{ inputs.path }}
Loading