diff --git a/.github/actions/format/action.yml b/.github/actions/format/action.yml new file mode 100644 index 000000000..c07ff57d5 --- /dev/null +++ b/.github/actions/format/action.yml @@ -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 11 for formatting + uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v4.2.1 + with: + java-version: '11' + distribution: 'temurin' + + - name: Cache Maven packages + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.0.2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles(format('{0}/**/pom.xml', inputs.path)) }} + restore-keys: | + ${{ runner.os }}-m2- + + - name: Run Spotless Apply + run: mvn spotless:apply + shell: bash + working-directory: ${{ inputs.path }} diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 5c85cd01b..d2420c874 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,4 +1,6 @@ -name: Java Code Format +# Deprecated + +name: Format and Commit Java Code on: workflow_dispatch: @@ -19,22 +21,10 @@ jobs: with: token: ${{ secrets.ADYEN_AUTOMATION_BOT_ACCESS_TOKEN }} - - name: Set up JDK - uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 - with: - java-version: '20' - distribution: 'adopt' - - - name: Cache Maven packages - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 + - name: Format Java Code + uses: ./.github/actions/format with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-m2- - - - name: Run Spotless Apply - run: mvn spotless:apply + path: . - name: Commit and Push Changes env: