Skip to content

Commit d862272

Browse files
bowenliang123pan3793
authored andcommitted
[KYUUBI #4274] [INFRA] Introduce mvnd to speed up CI jobs of Dependency, Licence and Style Check
### _Why are the changes needed?_ #### Motivation: - speed up maven building and testing with `mvnd` (https://github.com/apache/maven-mvnd). `mvnd` itself embeds exactly the same distribution of maven with more improvements and features on the client side and compilation server in daemon mode. - also inspired by custom github action for mvnd installing in Apache Camel (https://github.com/apache/camel/blob/main/.github/actions/install-mvnd/action.yml) #### Changes in this PR: - introducing `mvnd` by adding `build/mvnd` script - use `mvnd` version `0.9.0` which embeds `maven` 3.8.7. The maven version embedded in `mvnd` is also check and guaranteed the same as maven version required in pom by `build/mvnd` script. - use mvnd in CI jobs of Depedency Check and Style Check #### Comparision - CI jobs (both with maven dependencies cached in local repo) Job | with `build/mvn` | with `build/mvnd` --- | --- | --- Dependency Check | 9min1sec;[see log](https://github.com/apache/kyuubi/actions/runs/3966175262/jobs/6796688187) | 6min 46 sec ; [see log](https://github.com/apache/kyuubi/actions/runs/4124518481/jobs/7123867015) Style Check | 10min32sec ; [see log](https://github.com/apache/kyuubi/actions/runs/4122613274/jobs/7119603428) | 7min50s ; [see log](https://github.com/apache/kyuubi/actions/runs/4125013599/jobs/7125006946) Licence Check | 32s ; [see log](https://github.com/apache/kyuubi/actions/runs/4130799867/jobs/7137835062) | 21s ; [see log](https://github.com/apache/kyuubi/actions/runs/4130923126/jobs/7138088114) - building entire maven project on local machine (skipping test running and style checking with `fast` profile) `build/mvnd clean install -Pfast` <img width="645" alt="Pasted Graphic" src="https://user-images.githubusercontent.com/1935105/217001594-52dfd19d-6c57-4bc4-8336-90bb0c030bd4.png"> `build/mvn clean install -Pfast` <img width="643" alt="Pasted Graphic 1" src="https://user-images.githubusercontent.com/1935105/217001619-c2ebe7e3-bd14-4f5c-bb02-2ae4ae99cf7f.png"> ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request Closes #4274 from bowenliang123/ci-mvnd. Closes #4274 380c1c9 [liangbowen] update cache key a93bba7 [liangbowen] style bc8da13 [Bowen Liang] Merge branch 'master' into ci-mvnd 97becc0 [liangbowen] add `build/maven-mvnd-*/**` to rat-excludes 5b61f50 [liangbowen] apply mvnd to license check 7be181d [liangbowen] typo in build/mvnd c52861d [liangbowen] update f6d0eb2 [liangbowen] introduce mvnd Lead-authored-by: liangbowen <liangbowen@gf.com.cn> Co-authored-by: Bowen Liang <bowenliang@apache.org> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 4e226ac commit d862272

File tree

8 files changed

+185
-9
lines changed

8 files changed

+185
-9
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
name: 'setup-mvnd'
19+
description: 'Setup the maven daemon'
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Cache Mvnd
24+
uses: actions/cache@v3
25+
with:
26+
path: |
27+
build/maven-mvnd-*
28+
build/apache-maven-*
29+
key: setup-mvnd-${{ runner.os }}-mvnd
30+
- name: Check Mvnd
31+
run: build/mvnd -v
32+
shell: bash

.github/workflows/dep.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ on:
2626
# when pom or dependency workflow changes
2727
- '**/pom.xml'
2828
- '.github/workflows/dep.yml'
29+
- .github/actions/setup-mvnd/*.yaml
2930

3031
concurrency:
3132
group: dep-${{ github.head_ref || github.run_id }}
@@ -44,11 +45,13 @@ jobs:
4445
java-version: 8
4546
cache: 'maven'
4647
check-latest: false
48+
- name: Setup Mvnd
49+
uses: ./.github/actions/setup-mvnd
4750
- name: build
4851
env:
4952
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.defaultLogLevel=error
5053
run: >-
51-
build/mvn clean install
54+
build/mvnd clean install
5255
-Pflink-provided,spark-provided,hive-provided
5356
-Dmaven.javadoc.skip=true
5457
-Drat.skip=true

.github/workflows/license.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ jobs:
4242
java-version: 8
4343
cache: 'maven'
4444
check-latest: false
45+
- name: Setup Mvnd
46+
uses: ./.github/actions/setup-mvnd
4547
- run: >-
46-
build/mvn org.apache.rat:apache-rat-plugin:check
48+
build/mvnd org.apache.rat:apache-rat-plugin:check
4749
-Ptpcds -Pspark-block-cleaner -Pkubernetes-it
4850
-Pspark-3.1 -Pspark-3.2 -Pspark-3.3
4951
- name: Upload rat report

.github/workflows/style.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ jobs:
4545
java-version: 8
4646
cache: 'maven'
4747
check-latest: false
48+
- name: Setup Mvnd
49+
uses: ./.github/actions/setup-mvnd
4850
- name: Setup Python 3
4951
uses: actions/setup-python@v4
5052
with:
5153
python-version: '3.9'
5254
cache: 'pip'
53-
- name: Check kyuubi modules avaliable
55+
- name: Check kyuubi modules available
5456
id: modules-check
55-
run: build/mvn dependency:resolve -DincludeGroupIds="org.apache.kyuubi" -DincludeScope="compile" -DexcludeTransitive=true ${{ matrix.profiles }}
57+
run: build/mvnd dependency:resolve -DincludeGroupIds="org.apache.kyuubi" -DincludeScope="compile" -DexcludeTransitive=true ${{ matrix.profiles }}
5658
continue-on-error: true
5759

5860
- name: Install
@@ -61,13 +63,13 @@ jobs:
6163
if: steps.modules-check.conclusion == 'success' && steps.modules-check.outcome == 'failure'
6264
run: |
6365
MVN_OPT="-DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=warn -Dmaven.javadoc.skip=true -Drat.skip=true -Dscalastyle.skip=true -Dspotless.check.skip"
64-
build/mvn clean install ${MVN_OPT} -Pflink-provided,hive-provided,spark-provided,spark-block-cleaner,spark-3.2,tpcds
65-
build/mvn clean install ${MVN_OPT} -pl extensions/spark/kyuubi-extension-spark-3-1 -Pspark-3.1
66-
build/mvn clean install ${MVN_OPT} -pl extensions/spark/kyuubi-extension-spark-3-3,extensions/spark/kyuubi-spark-connector-kudu,extensions/spark/kyuubi-spark-connector-hive -Pspark-3.3
66+
build/mvnd clean install ${MVN_OPT} -Pflink-provided,hive-provided,spark-provided,spark-block-cleaner,spark-3.2,tpcds
67+
build/mvnd clean install ${MVN_OPT} -pl extensions/spark/kyuubi-extension-spark-3-1 -Pspark-3.1
68+
build/mvnd clean install ${MVN_OPT} -pl extensions/spark/kyuubi-extension-spark-3-3,extensions/spark/kyuubi-spark-connector-kudu,extensions/spark/kyuubi-spark-connector-hive -Pspark-3.3
6769
6870
- name: Scalastyle with maven
6971
id: scalastyle-check
70-
run: build/mvn scalastyle:check ${{ matrix.profiles }}
72+
run: build/mvnd scalastyle:check ${{ matrix.profiles }}
7173
- name: Print scalastyle error report
7274
if: failure() && steps.scalastyle-check.outcome != 'success'
7375
run: >-
@@ -81,7 +83,7 @@ jobs:
8183
run: |
8284
SPOTLESS_BLACK_VERSION=$(build/mvn help:evaluate -Dexpression=spotless.python.black.version -q -DforceStdout)
8385
pip install black==$SPOTLESS_BLACK_VERSION
84-
build/mvn spotless:check ${{ matrix.profiles }} -Pspotless-python
86+
build/mvnd spotless:check ${{ matrix.profiles }} -Pspotless-python
8587
- name: setup npm
8688
uses: actions/setup-node@v3
8789
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
.scala_dependencies
4141
.settings
4242
build/apache-maven*
43+
build/maven-mvnd*
4344
build/release/tmp
4445
build/scala*
4546
build/test

.rat-excludes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
NOTICE*
3333
docs/**
3434
build/apache-maven-*/**
35+
build/maven-mvnd-*/**
3536
build/scala-*/**
3637
**/**/operation_logs/**/**
3738
**/**/server_operation_logs/**/**

build/mvnd

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership.
7+
# The ASF licenses this file to You under the Apache License, Version 2.0
8+
# (the "License"); you may not use this file except in compliance with
9+
# the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# Determine the current working directory
21+
_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
22+
# Preserve the calling directory
23+
_CALLING_DIR="$(pwd)"
24+
# Options used during compilation
25+
_COMPILE_JVM_OPTS="-Xms2g -Xmx2g -XX:ReservedCodeCacheSize=1g -Xss128m"
26+
27+
if [ "$CI" ]; then
28+
export MAVEN_CLI_OPTS="--no-transfer-progress --errors --fail-fast"
29+
fi
30+
31+
# Installs any application tarball given a URL, the expected tarball name,
32+
# and, optionally, a checkable binary path to determine if the binary has
33+
# already been installed
34+
## Arg1 - URL
35+
## Arg2 - Tarball Name
36+
## Arg3 - Checkable Binary
37+
install_app() {
38+
local remote_tarball="$1/$2"
39+
local local_tarball="${_DIR}/$2"
40+
local binary="${_DIR}/$3"
41+
42+
# setup `curl` and `wget` silent options if we're running on Jenkins
43+
local curl_opts="-L"
44+
local wget_opts=""
45+
curl_opts="--progress-bar ${curl_opts}"
46+
wget_opts="--progress=bar:force ${wget_opts}"
47+
48+
if [ -z "$3" ] || [ ! -f "$binary" ]; then
49+
# check if we already have the tarball
50+
# check if we have curl installed
51+
# download application
52+
rm -f "$local_tarball"
53+
[ ! -f "${local_tarball}" ] && [ "$(command -v curl)" ] && \
54+
echo "exec: curl ${curl_opts} ${remote_tarball}" 1>&2 && \
55+
curl ${curl_opts} "${remote_tarball}" > "${local_tarball}"
56+
# if the file still doesn't exist, lets try `wget` and cross our fingers
57+
[ ! -f "${local_tarball}" ] && [ "$(command -v wget)" ] && \
58+
echo "exec: wget ${wget_opts} ${remote_tarball}" 1>&2 && \
59+
wget ${wget_opts} -O "${local_tarball}" "${remote_tarball}"
60+
# if both were unsuccessful, exit
61+
[ ! -f "${local_tarball}" ] && \
62+
echo -n "ERROR: Cannot download $2 with cURL or wget; " && \
63+
echo "please install manually and try again." && \
64+
exit 2
65+
cd "${_DIR}" && tar -xzf "$2"
66+
rm -rf "$local_tarball"
67+
fi
68+
}
69+
70+
function get_os_type() {
71+
local unameOsOut=$(uname -s)
72+
local osType
73+
case "${unameOsOut}" in
74+
Linux*) osType=linux ;;
75+
Darwin*) osType=darwin ;;
76+
CYGWIN*) osType=windows ;;
77+
MINGW*) osType=windows ;;
78+
*) osType="UNKNOWN:${unameOsOut}" ;;
79+
esac
80+
echo "$osType"
81+
}
82+
83+
function get_os_arch() {
84+
local unameArchOut="$(uname -m)"
85+
local arch
86+
case "${unameArchOut}" in
87+
x86_64*) arch=amd64 ;;
88+
arm64*) arch=aarch64 ;;
89+
*) arch="UNKNOWN:${unameOsOut}" ;;
90+
esac
91+
echo "$arch"
92+
}
93+
94+
# Determine the Mvnd version from the root pom.xml file and
95+
# install mvnd under the build/ folder if needed.
96+
function install_mvnd() {
97+
local MVND_VERSION=$(grep "<mvnd.version>" "${_DIR}/../pom.xml" | head -n1 | awk -F '[<>]' '{print $3}')
98+
local MVN_VERSION=$(grep "<maven.version>" "${_DIR}/../pom.xml" | head -n1 | awk -F '[<>]' '{print $3}')
99+
MVND_BIN="$(command -v mvnd)"
100+
if [ "$MVND_BIN" ]; then
101+
local MVND_DETECTED_VERSION="$(mvnd -v 2>&1 | grep '(mvnd)' | awk '{print $5}')"
102+
local MVN_DETECTED_VERSION="$(mvnd -v 2>&1 | grep 'Apache Maven' | awk 'NR==2 {print $3}')"
103+
fi
104+
# See simple version normalization: http://stackoverflow.com/questions/16989598/bash-comparing-version-numbers
105+
function version { echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'; }
106+
107+
if [ $(version $MVND_DETECTED_VERSION) -ne $(version $MVND_VERSION) ]; then
108+
local APACHE_MIRROR=${APACHE_MIRROR:-'https://downloads.apache.org'}
109+
local OS_TYPE=$(get_os_type)
110+
local ARCH=$(get_os_arch)
111+
112+
install_app \
113+
"${APACHE_MIRROR}/maven/mvnd/${MVND_VERSION}" \
114+
"maven-mvnd-${MVND_VERSION}-${OS_TYPE}-${ARCH}.tar.gz" \
115+
"maven-mvnd-${MVND_VERSION}-${OS_TYPE}-${ARCH}/bin/mvnd"
116+
117+
MVND_BIN="${_DIR}/maven-mvnd-${MVND_VERSION}-${OS_TYPE}-${ARCH}/bin/mvnd"
118+
else
119+
if [ "$(version $MVN_DETECTED_VERSION)" -ne "$(version $MVN_VERSION)" ]; then
120+
echo "Mvnd $MVND_DETECTED_VERSION embedded maven version $MVN_DETECTED_VERSION is not equivalent to $MVN_VERSION required in pom."
121+
exit 1
122+
fi
123+
fi
124+
}
125+
126+
install_mvnd
127+
128+
cd "${_CALLING_DIR}"
129+
130+
# Set any `mvn` options if not already present
131+
export MAVEN_OPTS=${MAVEN_OPTS:-"$_COMPILE_JVM_OPTS"}
132+
133+
echo "Using \`mvnd\` from path: $MVND_BIN" 1>&2
134+
${MVND_BIN} $MAVEN_CLI_OPTS "$@"

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<properties>
110110
<java.version>1.8</java.version>
111111
<maven.version>3.8.7</maven.version>
112+
<mvnd.version>0.9.0</mvnd.version>
112113
<maven.compiler.source>${java.version}</maven.compiler.source>
113114
<maven.compiler.target>${java.version}</maven.compiler.target>
114115
<scala.version>2.12.17</scala.version>

0 commit comments

Comments
 (0)