Skip to content
Merged
Show file tree
Hide file tree
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
119 changes: 119 additions & 0 deletions .github/actions/setup-java-with-cache/action.yml
Original file line number Diff line number Diff line change
@@ -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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since the key now includes .mvn/extensions.xml, should populate-cache also trigger on it and on this action?


- name: Remove any leftover Maven repo
id: cleanup
shell: bash
run: |
rm -frv ~/.m2/repository

- name: Restore cache with exact key

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a thought, what do you think about a single restore step here? Leaving restore-keys empty keeps it exact-only, and cache-matched-key shows whether anything was restored. That could replace the -d checks and the Any hit? step. For example:

- name: Restore cache
  id: restore
  uses: actions/cache/restore@v6
  with:
    path: |
      ~/.m2/repository/*/*/*
      !~/.m2/repository/org/apache/ozone
    key: ${{ steps.cache-key.outputs.value }}
    restore-keys: ${{ inputs.only-exact-hit != 'true' && 'maven-repo-' || '' }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I intend to start using apache/infrastructure-actions/stash:

  • does not have restore-keys
  • exact stash should precede "generic" cache lookup (which would be kept for some time for stability)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the explanation! In this case, would it make sense to drop the if: on Any hit? step? Otherwise restored stays empty on an exact hit.

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 }}
4 changes: 3 additions & 1 deletion .github/workflows/asf-allowlist-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ on:
workflow_dispatch:
pull_request:
paths:
- ".github/actions/**"
- ".github/workflows/**"
push:
branches-ignore:
- 'dependabot/**'
tags:
- '**'
paths:
- ".github/actions/**"
- ".github/workflows/**"

permissions:
Expand All @@ -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"
26 changes: 4 additions & 22 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -195,16 +189,11 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-

- name: Cache for Maven dependencies
if: ${{ inputs.needs-maven-cache }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: needs-maven-cache looks unused now that this step checks java-version. Could we remove the input and its uses in basic and dependency too?

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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
32 changes: 6 additions & 26 deletions .github/workflows/intermittent-test-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,17 @@ 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
with:
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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 6 additions & 16 deletions .github/workflows/populate-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down Expand Up @@ -151,15 +145,11 @@ 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
with:
path: |
~/.m2/repository/*/*/*
!~/.m2/repository/org/apache/ozone
key: maven-repo-${{ hashFiles('**/pom.xml') }}
key: ${{ steps.restore-cache.outputs.cache-key }}
1 change: 1 addition & 0 deletions .github/workflows/post-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just noticed one more thing, should we add this to run_all_tests_if_environment_files_changed too, so a change to only this action runs the full CI?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I think it's enough to trigger build to exercise the check, no need to run all tests. If you agree, I will push a commit to make this change. (BTW selective checks are currently unused on master, since there are no PR runs. We should start using it for push runs in forks.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed, build sounds enough. Thanks!

- '!.github/workflows/check.yml'
- '!.github/workflows/ci.yml'
- '!.github/workflows/post-commit.yml'
Expand Down
13 changes: 1 addition & 12 deletions .github/workflows/repeat-acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/zizmor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ on:
tags:
- '**'
paths:
- ".github/actions/**"
- '.github/workflows/**'
- '.github/zizmor.yml'
pull_request:
paths:
- ".github/actions/**"
- '.github/workflows/**'
- '.github/zizmor.yml'

Expand Down
1 change: 1 addition & 0 deletions dev-support/ci/selective_ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down