Skip to content

Commit

Permalink
Add cache action to speed up mvn workflow [skip ci] (#9674)
Browse files Browse the repository at this point in the history
* add cache for testing

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change cache key file

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add cache for all stages

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change key path

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add mvn help to test

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add isolated cache job

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add checkout

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add java setup

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* remove distribution

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add distribution

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add retry for cache

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add project param

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* make sure cache finished before shim version matrix

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add cache

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add cache

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add cache

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add check

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* remove test step

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add ls before cache

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add check

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* removed test steps

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add new mvn command, and changed key

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change mvn command

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change mvn command

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* Update .github/workflows/mvn-verify-check.yml

Co-authored-by: Gera Shegalov <gshegalov@nvidia.com>

* Update .github/workflows/mvn-verify-check.yml

Co-authored-by: Gera Shegalov <gshegalov@nvidia.com>

* change key format

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change time format

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add date

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* fix bug

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* fix time

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* chang key name

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* fix bug

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change time def

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change time

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add step to get current date

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* recover excess deletion.

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change ref to target branch

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* generate key in cache job

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* upadte key

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* echo key for testing

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* fix bug of time

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* test date

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* remove java version matrix

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* add runner os

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* Update .github/workflows/mvn-verify-check.yml

Co-authored-by: Gera Shegalov <gshegalov@nvidia.com>

* Update .github/workflows/mvn-verify-check.yml

Co-authored-by: Gera Shegalov <gshegalov@nvidia.com>

* add scala 213, and adjusted sequence of steps

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* change iteration var name

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>

* Update .github/workflows/mvn-verify-check.yml

Co-authored-by: Gera Shegalov <gshegalov@nvidia.com>

---------

Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com>
Co-authored-by: Gera Shegalov <gshegalov@nvidia.com>
  • Loading branch information
YanxuanLiu and gerashegalov authored Dec 1, 2023
1 parent fcad227 commit 8adc3cb
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 additions & 4 deletions .github/workflows/mvn-verify-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,49 @@ env:
-Dmaven.scaladoc.skip
jobs:
cache-dependencies:
runs-on: ubuntu-latest
outputs:
dailyCacheKey: ${{ steps.generateCacheKey.outputs.dailyCacheKey }}
steps:
- uses: actions/checkout@v3 # refs/pull/:prNumber/merge
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
- name: Generate daily cache key
id: generateCacheKey
run: |
set -x
cacheKey="${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ github.event.pull_request.base.ref }}-$(date +'%Y-%m-%d')"
echo "dailyCacheKey=$cacheKey" | tee $GITHUB_ENV $GITHUB_OUTPUT
- name: Cache local Maven repository
id: cache
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ env.dailyCacheKey }}
- name: populate-daily-cache
if: steps.cache.outputs.cache-hit != 'true'
run: |
set -x
max_retry=3; delay=30; i=1
while true; do
for pom in pom.xml scala2.13/pom.xml; do
mvn -f $pom help:evaluate -pl dist -Dexpression=included_buildvers \
-DforceStdout -PnoSnapshots -q | tr -d ',' | \
xargs -n 1 bash -c 'mvn -f $1 initialize -pl sql-plugin-api -am -Dbuildver=$2' _ $pom;
done && break || {
if [[ $i -le $max_retry ]]; then
echo "mvn command failed. Retry $i/$max_retry."; ((i++)); sleep $delay; ((delay=delay*2))
else
echo "mvn command failed. Exit 1"; exit 1
fi
}
done
get-shim-versions-from-dist:
needs: cache-dependencies
runs-on: ubuntu-latest
outputs:
defaultSparkVersion: ${{ steps.allShimVersionsStep.outputs.defaultSparkVersion }}
Expand Down Expand Up @@ -97,7 +139,7 @@ jobs:
echo "scala213Versions=$svJsonStr" >> $GITHUB_OUTPUT
package-tests:
needs: get-shim-versions-from-dist
needs: [get-shim-versions-from-dist, cache-dependencies]
continue-on-error: ${{ matrix.isSnapshot }}
strategy:
matrix: ${{ fromJSON(needs.get-shim-versions-from-dist.outputs.sparkTailVersions) }}
Expand All @@ -112,6 +154,12 @@ jobs:
distribution: adopt
java-version: 8

- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ needs.cache-dependencies.outputs.dailyCacheKey }}

- name: check runtime before tests
run: |
env | grep JAVA
Expand Down Expand Up @@ -142,7 +190,7 @@ jobs:
done
package-tests-scala213:
needs: get-shim-versions-from-dist
needs: [get-shim-versions-from-dist, cache-dependencies]
continue-on-error: ${{ matrix.isSnapshot }}
strategy:
matrix: ${{ fromJSON(needs.get-shim-versions-from-dist.outputs.scala213Versions) }}
Expand All @@ -157,6 +205,12 @@ jobs:
distribution: adopt
java-version: 8

- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ needs.cache-dependencies.outputs.dailyCacheKey }}

- name: check runtime before tests
run: |
env | grep JAVA
Expand Down Expand Up @@ -198,7 +252,7 @@ jobs:
verify-all-modules:
needs: get-shim-versions-from-dist
needs: [get-shim-versions-from-dist, cache-dependencies]
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.get-shim-versions-from-dist.outputs.sparkJDKVersions) }}
Expand All @@ -211,6 +265,12 @@ jobs:
distribution: adopt
java-version: ${{ matrix.java-version }}

- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ needs.cache-dependencies.outputs.dailyCacheKey }}

- name: check runtime before tests
run: |
env | grep JAVA
Expand Down Expand Up @@ -240,7 +300,7 @@ jobs:
done
install-modules:
needs: get-shim-versions-from-dist
needs: [get-shim-versions-from-dist, cache-dependencies]
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -254,6 +314,12 @@ jobs:
distribution: adopt
java-version: 11

- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ needs.cache-dependencies.outputs.dailyCacheKey }}

- name: Setup Maven Wrapper
run: mvn wrapper:wrapper -Dmaven=${{ matrix.maven-version }}

Expand Down

0 comments on commit 8adc3cb

Please sign in to comment.