This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new c359bf72ea6 HDDS-17790. Create setup-java-with-cache action (#12023)
c359bf72ea6 is described below
commit c359bf72ea6aa98147fd1935952c805242f1d18c
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Thu Nov 12 16:58:56 2026 +0100
HDDS-17790. Create setup-java-with-cache action (#12023)
---
.github/actions/setup-java-with-cache/action.yml | 119 +++++++++++++++++++++++
.github/workflows/asf-allowlist-check.yaml | 4 +-
.github/workflows/check.yml | 26 +----
.github/workflows/ci.yml | 14 +--
.github/workflows/intermittent-test-check.yml | 32 ++----
.github/workflows/populate-cache.yml | 22 ++---
.github/workflows/post-commit.yml | 1 +
.github/workflows/repeat-acceptance.yml | 13 +--
.github/workflows/zizmor.yml | 2 +
dev-support/ci/selective_ci_checks.sh | 1 +
10 files changed, 144 insertions(+), 90 deletions(-)
diff --git a/.github/actions/setup-java-with-cache/action.yml
b/.github/actions/setup-java-with-cache/action.yml
new file mode 100644
index 00000000000..f717c963b0c
--- /dev/null
+++ b/.github/actions/setup-java-with-cache/action.yml
@@ -0,0 +1,119 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: Setup Java with Maven Cache
+description: Setup Java and restore Maven cache of Ozone's dependencies
+
+inputs:
+ java-version:
+ description: >
+ Java version to set up.
+ required: true
+
+ only-exact-hit:
+ description: >
+ Restore cache only with exact key (if true), or allow fallback to any
cache.
+ default: 'false'
+
+outputs:
+ cache-hit:
+ description: >
+ Whether cache with exact key was restored (true) or not (false).
+ value: ${{ steps.exact-hit.outputs.value }}
+
+ cache-key:
+ description: >
+ The cache key calculated from POM and other files. This may not be the
key
+ of the cache that was restored if fallback is allowed.
+ value: ${{ steps.cache-key.outputs.value }}
+
+ restored:
+ description: >
+ Whether any cache was restored (true) or not (false).
+ value: ${{ steps.any-hit.outputs.value }}
+
+runs:
+ using: composite
+ steps:
+ - name: Setup Java ${{ inputs.java-version }}
+ id: setup-java
+ uses: actions/setup-java@v6
+ with:
+ distribution: 'temurin'
+ java-version: ${{ inputs.java-version }}
+
+ - name: Calculate cache key
+ id: cache-key
+ shell: bash
+ run: |
+ echo "value=maven-repo-${{ hashFiles('**/pom.xml',
'.mvn/extensions.xml') }}" >> "$GITHUB_OUTPUT"
+
+ - name: Remove any leftover Maven repo
+ id: cleanup
+ shell: bash
+ run: |
+ rm -frv ~/.m2/repository
+
+ - name: Restore cache with exact key
+ id: exact-cache
+ uses: actions/cache/restore@v6
+ with:
+ path: |
+ ~/.m2/repository/*/*/*
+ !~/.m2/repository/org/apache/ozone
+ key: ${{ steps.cache-key.outputs.value }}
+
+ - name: Exact hit?
+ id: exact-hit
+ shell: bash
+ run: |
+ if [[ "$HIT" == "true" ]] || [[ -d ~/.m2/repository ]]; then
+ value="true"
+ else
+ value="false"
+ fi
+ echo "hit: $value"
+ echo "value=$value" >> "$GITHUB_OUTPUT"
+ env:
+ HIT: ${{ steps.exact-cache.outputs.cache-hit }}
+
+ - name: Fallback to generic cache
+ id: generic-cache
+ if: >
+ steps.exact-hit.outputs.value != 'true'
+ && inputs.only-exact-hit != 'true'
+ uses: actions/cache/restore@v6
+ with:
+ path: |
+ ~/.m2/repository/*/*/*
+ !~/.m2/repository/org/apache/ozone
+ key: maven-repo-
+
+ - name: Any hit?
+ id: any-hit
+ if: >
+ steps.exact-hit.outputs.value != 'true'
+ && inputs.only-exact-hit != 'true'
+ shell: bash
+ run: |
+ if [[ "$HIT" == "true" ]] || [[ -d ~/.m2/repository ]]; then
+ value="true"
+ else
+ value="false"
+ fi
+ echo "hit: $value"
+ echo "value=$value" >> "$GITHUB_OUTPUT"
+ env:
+ HIT: ${{ steps.exact-hit.outputs.value }}
diff --git a/.github/workflows/asf-allowlist-check.yaml
b/.github/workflows/asf-allowlist-check.yaml
index 75804f39340..4c39c9504b5 100644
--- a/.github/workflows/asf-allowlist-check.yaml
+++ b/.github/workflows/asf-allowlist-check.yaml
@@ -19,6 +19,7 @@ on:
workflow_dispatch:
pull_request:
paths:
+ - ".github/actions/**"
- ".github/workflows/**"
push:
branches-ignore:
@@ -26,6 +27,7 @@ on:
tags:
- '**'
paths:
+ - ".github/actions/**"
- ".github/workflows/**"
permissions:
@@ -46,4 +48,4 @@ jobs:
- name: Check actions
uses: apache/infrastructure-actions/allowlist-check@allowlist-check/v1
with:
- scan-glob: ".github/workflows/*.y*ml"
+ scan-glob: ".github/**/*.y*ml"
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index e9463a38c10..f6cc4785fbb 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -51,12 +51,6 @@ on:
default: ''
required: false
- needs-maven-cache:
- type: boolean
- description: "Whether to restore Maven cache before run (default: yes)"
- default: true
- required: false
-
needs-npm-cache:
type: boolean
description: "Whether to restore NPM cache before run (default: no)"
@@ -195,16 +189,11 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-
- - name: Cache for Maven dependencies
- if: ${{ inputs.needs-maven-cache }}
- uses: actions/cache/restore@v6
+ - name: Setup Java ${{ inputs.java-version }} with cache
+ if: ${{ inputs.java-version }}
+ uses: $/.github/actions/setup-java-with-cache
with:
- path: |
- ~/.m2/repository/*/*/*
- !~/.m2/repository/org/apache/ozone
- key: maven-repo-${{ hashFiles('**/pom.xml') }}
- restore-keys: |
- maven-repo-
+ java-version: ${{ inputs.java-version }}
- name: Download Ozone repo
id: download-ozone-repo
@@ -236,13 +225,6 @@ jobs:
tar xzvf ozone*.tar.gz -C hadoop-ozone/dist/target
rm ozone*.tar.gz
- - name: Setup java ${{ inputs.java-version }}
- if: ${{ inputs.java-version }}
- uses: actions/setup-java@v6
- with:
- distribution: 'temurin'
- java-version: ${{ inputs.java-version }}
-
- name: Get versions
id: versions
# TODO remove hard-code in HDDS-17509
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b59ee650c4e..d7047be7a66 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -208,7 +208,6 @@ jobs:
with:
checkout-fetch-depth: ${{ matrix.check != 'bats' && 1 || 0 }}
java-version: ${{ !contains('author,bats', matrix.check) &&
needs.build-info.outputs.java-version || '' }}
- needs-maven-cache: ${{ !contains('author,bats', matrix.check) }}
ratis-args: ${{ inputs.ratis_args }}
runner: ${{ contains('author,bats', matrix.check) && 'ubuntu-slim' ||
'ubuntu-26.04' }}
script: ${{ matrix.check }}
@@ -248,7 +247,6 @@ jobs:
secrets:
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
with:
- needs-maven-cache: false
needs-ozone-binary-tarball: true
runner: ubuntu-slim
script: dependency
@@ -490,15 +488,6 @@ jobs:
fetch-depth: 0
persist-credentials: false
ref: ${{ needs.build-info.outputs.sha }}
- - name: Cache for maven dependencies
- uses: actions/cache/restore@v6
- with:
- path: |
- ~/.m2/repository/*/*/*
- !~/.m2/repository/org/apache/ozone
- key: maven-repo-${{ hashFiles('**/pom.xml') }}
- restore-keys: |
- maven-repo-
- name: Download artifacts
uses: actions/download-artifact@v8
with:
@@ -508,9 +497,8 @@ jobs:
mkdir -p hadoop-ozone/dist/target
tar xzvf target/artifacts/ozone-bin/ozone*.tar.gz -C
hadoop-ozone/dist/target
- name: Setup java ${{ env.TEST_JAVA_VERSION }}
- uses: actions/setup-java@v6
+ uses: $/.github/actions/setup-java-with-cache
with:
- distribution: 'temurin'
java-version: ${{ env.TEST_JAVA_VERSION }}
- name: Calculate combined coverage
run: ./hadoop-ozone/dev-support/checks/coverage.sh
diff --git a/.github/workflows/intermittent-test-check.yml
b/.github/workflows/intermittent-test-check.yml
index 5235d4be0ca..4172da2517f 100644
--- a/.github/workflows/intermittent-test-check.yml
+++ b/.github/workflows/intermittent-test-check.yml
@@ -112,15 +112,10 @@ jobs:
with:
persist-credentials: false
ref: ${{ github.event.inputs.ref }}
- - name: Cache for maven dependencies
- uses: actions/cache/restore@v6
+ - name: Setup java
+ uses: $/.github/actions/setup-java-with-cache
with:
- path: |
- ~/.m2/repository/*/*/*
- !~/.m2/repository/org/apache/ozone
- key: maven-repo-${{ hashFiles('**/pom.xml') }}
- restore-keys: |
- maven-repo-
+ java-version: ${{ github.event.inputs.java-version }}
- name: Download Ratis repo
if: ${{ github.event.inputs.ratis-ref != '' }}
uses: actions/download-artifact@v8
@@ -128,11 +123,6 @@ jobs:
name: ratis-jars
path: |
~/.m2/repository/org/apache/ratis
- - name: Setup java
- uses: actions/setup-java@v6
- with:
- distribution: 'temurin'
- java-version: ${{ github.event.inputs.java-version }}
- name: Build (most) of Ozone
run: |
args="-DskipRecon -DskipShade -Dmaven.javadoc.skip=true
-Drocks_tools_native"
@@ -166,15 +156,10 @@ jobs:
with:
persist-credentials: false
ref: ${{ github.event.inputs.ref }}
- - name: Cache for maven dependencies
- uses: actions/cache/restore@v6
+ - name: Setup java
+ uses: $/.github/actions/setup-java-with-cache
with:
- path: |
- ~/.m2/repository/*/*/*
- !~/.m2/repository/org/apache/ozone
- key: maven-repo-${{ hashFiles('**/pom.xml') }}
- restore-keys: |
- maven-repo-
+ java-version: ${{ github.event.inputs.java-version }}
- name: Download Ratis repo
if: ${{ github.event.inputs.ratis-ref != '' }}
uses: actions/download-artifact@v8
@@ -189,11 +174,6 @@ jobs:
name: ozone-repo
path: |
~/.m2/repository/org/apache/ozone
- - name: Setup java
- uses: actions/setup-java@v6
- with:
- distribution: 'temurin'
- java-version: ${{ github.event.inputs.java-version }}
- name: Execute tests
run: |
if [[ -e "$repo_path" ]]; then
diff --git a/.github/workflows/populate-cache.yml
b/.github/workflows/populate-cache.yml
index 2f958dce3b8..93b3de36b4d 100644
--- a/.github/workflows/populate-cache.yml
+++ b/.github/workflows/populate-cache.yml
@@ -26,7 +26,9 @@ on:
paths:
- 'pom.xml'
- '**/pom.xml'
+ - '.github/actions/setup-java-with-cache/action.yml'
- '.github/workflows/populate-cache.yml'
+ - '.mvn/extensions.xml'
workflow_call:
workflow_dispatch:
@@ -53,20 +55,12 @@ jobs:
with:
persist-credentials: false
- - name: Restore cache for Maven dependencies
- id: restore-cache
- uses: actions/cache/restore@v6
- with:
- path: |
- ~/.m2/repository/*/*/*
- !~/.m2/repository/org/apache/ozone
- key: maven-repo-${{ hashFiles('**/pom.xml') }}
-
- name: Setup Java
- uses: actions/setup-java@v6
+ id: restore-cache
+ uses: $/.github/actions/setup-java-with-cache
with:
- distribution: 'temurin'
java-version: ${{ env.TEST_JAVA_VERSION }}
+ only-exact-hit: true
- name: Get versions
id: versions
@@ -151,10 +145,6 @@ jobs:
if: always()
run: find ~/.m2/repository -type f | sort | xargs ls -lh
- - name: Clean workspace
- if: always()
- run: mvn $BUILD_ARGS $MAVEN_ARGS --no-transfer-progress --show-version
-Pgo-offline -Dscan=false clean
-
- name: Save cache for Maven dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
@@ -162,4 +152,4 @@ jobs:
path: |
~/.m2/repository/*/*/*
!~/.m2/repository/org/apache/ozone
- key: maven-repo-${{ hashFiles('**/pom.xml') }}
+ key: ${{ steps.restore-cache.outputs.cache-key }}
diff --git a/.github/workflows/post-commit.yml
b/.github/workflows/post-commit.yml
index f6fd8d84104..d5900da387c 100644
--- a/.github/workflows/post-commit.yml
+++ b/.github/workflows/post-commit.yml
@@ -42,6 +42,7 @@ on:
- '!hadoop-ozone/dist/src/main/license/jar-report.txt'
# ignore .github except this workflow and the ones used transitively
- '.github/**'
+ - '!.github/actions/setup-java-with-cache/**'
- '!.github/workflows/check.yml'
- '!.github/workflows/ci.yml'
- '!.github/workflows/post-commit.yml'
diff --git a/.github/workflows/repeat-acceptance.yml
b/.github/workflows/repeat-acceptance.yml
index ab82f0b0038..680336adffd 100644
--- a/.github/workflows/repeat-acceptance.yml
+++ b/.github/workflows/repeat-acceptance.yml
@@ -97,20 +97,9 @@ jobs:
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
- - name: Cache for maven dependencies
- uses: actions/cache/restore@v6
- with:
- path: |
- ~/.m2/repository/*/*/*
- !~/.m2/repository/org/apache/ozone
- key: maven-repo-${{ hashFiles('**/pom.xml') }}-${{ env.JAVA_VERSION
}}
- restore-keys: |
- maven-repo-${{ hashFiles('**/pom.xml') }}
- maven-repo-
- name: Setup java
- uses: actions/setup-java@v6
+ uses: $/.github/actions/setup-java-with-cache
with:
- distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
- name: Run a full build
run: hadoop-ozone/dev-support/checks/build.sh -Pdist -Psrc
-Dmaven.javadoc.skip=true
diff --git a/.github/workflows/zizmor.yml b/.github/workflows/zizmor.yml
index f6f7726d87d..abd9727ef6f 100644
--- a/.github/workflows/zizmor.yml
+++ b/.github/workflows/zizmor.yml
@@ -22,10 +22,12 @@ on:
tags:
- '**'
paths:
+ - ".github/actions/**"
- '.github/workflows/**'
- '.github/zizmor.yml'
pull_request:
paths:
+ - ".github/actions/**"
- '.github/workflows/**'
- '.github/zizmor.yml'
diff --git a/dev-support/ci/selective_ci_checks.sh
b/dev-support/ci/selective_ci_checks.sh
index ff75ad246ec..ad9f63653f5 100755
--- a/dev-support/ci/selective_ci_checks.sh
+++ b/dev-support/ci/selective_ci_checks.sh
@@ -346,6 +346,7 @@ function get_count_robot_files() {
function check_needs_build() {
start_end::group_start "Check if build is needed"
local pattern_array=(
+ "^.github/actions/setup-java-with-cache"
"^.github/workflows/generate-config-doc.yml"
"^dev-support/ci/xml_to_md.py"
"^hadoop-ozone/dev-support/checks/_build.sh"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]