Repository navigation
HDDS-17790. Create setup-java-with-cache action #12023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5263c9d
717c68d
b2a8c96
28ac2fe
f6be3db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
|
|
||
| - name: Remove any leftover Maven repo | ||
| id: cleanup | ||
| shell: bash | ||
| run: | | ||
| rm -frv ~/.m2/repository | ||
|
|
||
| - name: Restore cache with exact key | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 - 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-' || '' }}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intend to start using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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/**' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I think it's enough to trigger
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, |
||
| - '!.github/workflows/check.yml' | ||
| - '!.github/workflows/ci.yml' | ||
| - '!.github/workflows/post-commit.yml' | ||
|
|
||
There was a problem hiding this comment.
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, shouldpopulate-cachealso trigger on it and on this action?