Skip to content

Commit 4365056

Browse files
authored
ci: use .java-version and prepare to use VM with installed tools in BK (#241)
1 parent ddcf03a commit 4365056

File tree

7 files changed

+46
-29
lines changed

7 files changed

+46
-29
lines changed

.buildkite/hooks/pre-command

+17-10
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,23 @@ echo "--- Configure git context :git:"
4545
git config --global user.email "infra-root+apmmachine@elastic.co"
4646
git config --global user.name "apmmachine"
4747

48-
echo "--- Install JDK17 :java:"
49-
JAVA_URL=https://jvm-catalog.elastic.co/jdk
50-
JAVA_HOME=$(pwd)/.openjdk17
51-
JAVA_PKG="$JAVA_URL/latest_openjdk_17_linux.tar.gz"
52-
curl -L --output /tmp/jdk.tar.gz "$JAVA_PKG"
53-
mkdir -p "$JAVA_HOME"
54-
tar --extract --file /tmp/jdk.tar.gz --directory "$JAVA_HOME" --strip-components 1
55-
48+
# Configure the java version
49+
JAVA_VERSION=$(cat .java-version | xargs | tr -dc '[:print:]')
50+
JAVA_HOME="${HOME}/.java/openjdk${JAVA_VERSION}"
5651
export JAVA_HOME
57-
PATH=$JAVA_HOME/bin:$PATH
52+
PATH="${JAVA_HOME}/bin:${PATH}"
5853
export PATH
5954

60-
java -version || true
55+
# Fallback to install at runtime
56+
if [ ! -d "${JAVA_HOME}" ] ; then
57+
# This should not be the case normally untless the .java-version file has been changed
58+
# and the VM Image is not yet available with the latest version.
59+
echo "--- Install JDK${JAVA_VERSION} :java:"
60+
JAVA_URL=https://jvm-catalog.elastic.co/jdk
61+
JAVA_PKG="${JAVA_URL}/latest_openjdk_${JAVA_VERSION}_linux.tar.gz"
62+
curl -L --output /tmp/jdk.tar.gz "${JAVA_PKG}"
63+
mkdir -p "$JAVA_HOME"
64+
tar --extract --file /tmp/jdk.tar.gz --directory "${JAVA_HOME}" --strip-components 1
65+
fi
66+
67+
java -version

.buildkite/release.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
agents:
22
provider: "gcp"
3+
#image: "family/ecs-logging-java-ubuntu-2204"
34

45
steps:
56
- label: "Run the release"
@@ -8,6 +9,6 @@ steps:
89
artifact_paths: "release.txt"
910

1011
notify:
11-
- slack:
12-
channels:
13-
- "#apm-agent-java"
12+
- slack: "#apm-agent-java"
13+
# skip slack messages if no failures and dry-run mode
14+
if: 'build.state != "passed" && build.env("dry_run") == "false"'

.buildkite/snapshot.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
agents:
22
provider: "gcp"
3+
#image: "family/ecs-logging-java-ubuntu-2204"
34

45
steps:
56
- label: "Run the snapshot"
@@ -11,4 +12,5 @@ steps:
1112

1213
notify:
1314
- slack: "#apm-agent-java"
14-
if: 'build.state != "passed"'
15+
# skip slack messages if no failures and dry-run mode
16+
if: 'build.state != "passed" && build.env("dry_run") == "false"'

.ci/release.sh

+10-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ echo $PATH
2727
java -version
2828

2929
set +x
30-
echo "--- Release the binaries to Maven Central :maven:"
31-
if [[ "${dry_run}" == "true" ]] ; then
32-
./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee release.txt
33-
else
34-
./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee release.txt
30+
# Default in dry-run mode
31+
GOAL="package"
32+
DRY_RUN_MSG="(dry-run)"
33+
# Otherwise, a RELEASE
34+
if [[ "$dry_run" == "false" ]] ; then
35+
GOAL="deploy"
36+
DRY_RUN_MSG=""
3537
fi
38+
39+
echo "--- Release the binaries to Maven Central :maven: [./mvnw ${GOAL})] ${DRY_RUN_MSG}"
40+
./mvnw -V -s .ci/settings.xml -Pgpg clean $GOAL -DskipTests --batch-mode | tee release.txt

.ci/snapshot.sh

+10-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ echo $PATH
2424
java -version
2525

2626
set +x
27-
echo "--- Deploy the snapshot :package:"
28-
if [[ "$dry_run" == "true" ]] ; then
29-
./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee snapshot.txt
30-
else
31-
./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee snapshot.txt
27+
# Default in dry-run mode
28+
GOAL="package"
29+
DRY_RUN_MSG="(dry-run)"
30+
# Otherwise, a RELEASE
31+
if [[ "$dry_run" == "false" ]] ; then
32+
GOAL="deploy"
33+
DRY_RUN_MSG=""
3234
fi
35+
36+
echo "--- Deploy the snapshot :package: [./mvnw ${GOAL})] ${DRY_RUN_MSG}"
37+
./mvnw -V -s .ci/settings.xml -Pgpg clean ${GOAL} -DskipTests --batch-mode | tee snapshot.txt

.github/workflows/maven-goal/action.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ name: maven-goal
44
description: Install specific JDK and run a command
55

66
inputs:
7-
version:
8-
description: 'Java version'
9-
required: true
10-
default: '17'
117
distribution:
128
description: 'Java distribution'
139
required: true
@@ -26,7 +22,7 @@ runs:
2622
- name: Set up JDK
2723
uses: actions/setup-java@v4
2824
with:
29-
java-version: ${{ inputs.version }}
25+
java-version-file: .java-version
3026
distribution: ${{ inputs.distribution }}
3127
cache: 'maven'
3228
- run: ${{ inputs.command }}

.java-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17

0 commit comments

Comments
 (0)