From 665acdde15ffa8773f0dcc82170bf47242238c16 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 7 Mar 2024 22:45:14 +0100 Subject: [PATCH 1/4] ci: use .java-version and prepare to use VM with installed tools in BK --- .buildkite/hooks/pre-command | 27 ++++++++++++++++--------- .buildkite/release.yml | 1 + .buildkite/snapshot.yml | 1 + .ci/release.sh | 15 +++++++++----- .ci/snapshot.sh | 15 +++++++++----- .github/workflows/maven-goal/action.yml | 6 +----- .java-version | 1 + 7 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 .java-version diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index d5ee33e..6b2dd13 100755 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -45,16 +45,23 @@ echo "--- Configure git context :git:" git config --global user.email "infra-root+apmmachine@elastic.co" git config --global user.name "apmmachine" -echo "--- Install JDK17 :java:" -JAVA_URL=https://jvm-catalog.elastic.co/jdk -JAVA_HOME=$(pwd)/.openjdk17 -JAVA_PKG="$JAVA_URL/latest_openjdk_17_linux.tar.gz" -curl -L --output /tmp/jdk.tar.gz "$JAVA_PKG" -mkdir -p "$JAVA_HOME" -tar --extract --file /tmp/jdk.tar.gz --directory "$JAVA_HOME" --strip-components 1 - +# Configure the java version +JAVA_VERSION=$(cat .java-version | xargs | tr -dc '[:print:]') +JAVA_HOME="${HOME}/.java/openjdk${JAVA_VERSION}" export JAVA_HOME -PATH=$JAVA_HOME/bin:$PATH +PATH="${JAVA_HOME}/bin:$PATH" export PATH -java -version || true +# Fallback to install at runtime +if [ ! -d "${JAVA_HOME}" ] ; then + # This should not be the case normally untless the .java-version file has been changed + # and the VM Image is not yet available with the latest version. + echo "--- Install JDK${JAVA_VERSION} :java:" + JAVA_URL=https://jvm-catalog.elastic.co/jdk + JAVA_PKG="${JAVA_URL}/latest_openjdk_${JAVA_VERSION}_linux.tar.gz" + curl -L --output /tmp/jdk.tar.gz "$JAVA_PKG" + mkdir -p "$JAVA_HOME" + tar --extract --file /tmp/jdk.tar.gz --directory "$JAVA_HOME" --strip-components 1 +fi + +java -version \ No newline at end of file diff --git a/.buildkite/release.yml b/.buildkite/release.yml index 1b8638b..e55b845 100644 --- a/.buildkite/release.yml +++ b/.buildkite/release.yml @@ -1,5 +1,6 @@ agents: provider: "gcp" + #image: "family/ecs-logging-java-ubuntu-2204" steps: - label: "Run the release" diff --git a/.buildkite/snapshot.yml b/.buildkite/snapshot.yml index c33406f..94a548b 100644 --- a/.buildkite/snapshot.yml +++ b/.buildkite/snapshot.yml @@ -1,5 +1,6 @@ agents: provider: "gcp" + #image: "family/ecs-logging-java-ubuntu-2204" steps: - label: "Run the snapshot" diff --git a/.ci/release.sh b/.ci/release.sh index d2cf966..7fa3f43 100755 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -27,9 +27,14 @@ echo $PATH java -version set +x -echo "--- Release the binaries to Maven Central :maven:" -if [[ "${dry_run}" == "true" ]] ; then - ./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee release.txt -else - ./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee release.txt +# Default in dry-run mode +GOAL="install" +DRY_RUN_MSG="(dry-run)" +# Otherwise, a RELEASE +if [[ "$dry_run" == "false" ]] ; then + GOAL="deploy" + DRY_RUN_MSG="" fi + +echo "--- Release the binaries to Maven Central :maven: [./mvnw $GOAL)] $DRY_RUN_MSG" +./mvnw -V -s .ci/settings.xml -Pgpg clean $GOAL -DskipTests --batch-mode | tee release.txt diff --git a/.ci/snapshot.sh b/.ci/snapshot.sh index 98996c9..89a0055 100755 --- a/.ci/snapshot.sh +++ b/.ci/snapshot.sh @@ -24,9 +24,14 @@ echo $PATH java -version set +x -echo "--- Deploy the snapshot :package:" -if [[ "$dry_run" == "true" ]] ; then - ./mvnw -V -s .ci/settings.xml -Pgpg clean package --batch-mode | tee snapshot.txt -else - ./mvnw -V -s .ci/settings.xml -Pgpg clean deploy --batch-mode | tee snapshot.txt +# Default in dry-run mode +GOAL="install" +DRY_RUN_MSG="(dry-run)" +# Otherwise, a RELEASE +if [[ "$dry_run" == "false" ]] ; then + GOAL="deploy" + DRY_RUN_MSG="" fi + +echo "--- Deploy the snapshot :package: [./mvnw $GOAL)] $DRY_RUN_MSG" +./mvnw -V -s .ci/settings.xml -Pgpg clean $GOAL -DskipTests --batch-mode | tee release.txt diff --git a/.github/workflows/maven-goal/action.yml b/.github/workflows/maven-goal/action.yml index 4a2468a..7b8dbb9 100644 --- a/.github/workflows/maven-goal/action.yml +++ b/.github/workflows/maven-goal/action.yml @@ -4,10 +4,6 @@ name: maven-goal description: Install specific JDK and run a command inputs: - version: - description: 'Java version' - required: true - default: '17' distribution: description: 'Java distribution' required: true @@ -26,7 +22,7 @@ runs: - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: ${{ inputs.version }} + java-version-file: .java-version distribution: ${{ inputs.distribution }} cache: 'maven' - run: ${{ inputs.command }} diff --git a/.java-version b/.java-version new file mode 100644 index 0000000..8e2afd3 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +17 \ No newline at end of file From 3d2fa192ac4baddeeca0e4c04bbc9718700c96ac Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 8 Mar 2024 13:46:45 +0100 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> --- .ci/release.sh | 2 +- .ci/snapshot.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci/release.sh b/.ci/release.sh index 7fa3f43..b0eaa1c 100755 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -28,7 +28,7 @@ java -version set +x # Default in dry-run mode -GOAL="install" +GOAL="package" DRY_RUN_MSG="(dry-run)" # Otherwise, a RELEASE if [[ "$dry_run" == "false" ]] ; then diff --git a/.ci/snapshot.sh b/.ci/snapshot.sh index 89a0055..b60f566 100755 --- a/.ci/snapshot.sh +++ b/.ci/snapshot.sh @@ -25,7 +25,7 @@ java -version set +x # Default in dry-run mode -GOAL="install" +GOAL="package" DRY_RUN_MSG="(dry-run)" # Otherwise, a RELEASE if [[ "$dry_run" == "false" ]] ; then @@ -34,4 +34,4 @@ if [[ "$dry_run" == "false" ]] ; then fi echo "--- Deploy the snapshot :package: [./mvnw $GOAL)] $DRY_RUN_MSG" -./mvnw -V -s .ci/settings.xml -Pgpg clean $GOAL -DskipTests --batch-mode | tee release.txt +./mvnw -V -s .ci/settings.xml -Pgpg clean $GOAL -DskipTests --batch-mode | tee snapshot.txt From 4f9f5d737d82a2070f101d03b40689d878ef2b31 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 8 Mar 2024 15:36:49 +0100 Subject: [PATCH 3/4] skip slack messages for dry-run --- .buildkite/release.yml | 6 +++--- .buildkite/snapshot.yml | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.buildkite/release.yml b/.buildkite/release.yml index e55b845..e486e89 100644 --- a/.buildkite/release.yml +++ b/.buildkite/release.yml @@ -9,6 +9,6 @@ steps: artifact_paths: "release.txt" notify: - - slack: - channels: - - "#apm-agent-java" + - slack: "#apm-agent-java" + # skip slack messages if no failures and dry-run mode + if: 'build.state != "passed" && build.env("dry_run") == "false"' diff --git a/.buildkite/snapshot.yml b/.buildkite/snapshot.yml index 94a548b..e240188 100644 --- a/.buildkite/snapshot.yml +++ b/.buildkite/snapshot.yml @@ -12,4 +12,5 @@ steps: notify: - slack: "#apm-agent-java" - if: 'build.state != "passed"' + # skip slack messages if no failures and dry-run mode + if: 'build.state != "passed" && build.env("dry_run") == "false"' From 594190c4ab9549939d43ffb5e2d0e22cb0e6172a Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 11 Mar 2024 12:39:37 +0100 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> --- .buildkite/hooks/pre-command | 6 +++--- .ci/release.sh | 2 +- .ci/snapshot.sh | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index 6b2dd13..5debc14 100755 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -49,7 +49,7 @@ git config --global user.name "apmmachine" JAVA_VERSION=$(cat .java-version | xargs | tr -dc '[:print:]') JAVA_HOME="${HOME}/.java/openjdk${JAVA_VERSION}" export JAVA_HOME -PATH="${JAVA_HOME}/bin:$PATH" +PATH="${JAVA_HOME}/bin:${PATH}" export PATH # Fallback to install at runtime @@ -59,9 +59,9 @@ if [ ! -d "${JAVA_HOME}" ] ; then echo "--- Install JDK${JAVA_VERSION} :java:" JAVA_URL=https://jvm-catalog.elastic.co/jdk JAVA_PKG="${JAVA_URL}/latest_openjdk_${JAVA_VERSION}_linux.tar.gz" - curl -L --output /tmp/jdk.tar.gz "$JAVA_PKG" + curl -L --output /tmp/jdk.tar.gz "${JAVA_PKG}" mkdir -p "$JAVA_HOME" - tar --extract --file /tmp/jdk.tar.gz --directory "$JAVA_HOME" --strip-components 1 + tar --extract --file /tmp/jdk.tar.gz --directory "${JAVA_HOME}" --strip-components 1 fi java -version \ No newline at end of file diff --git a/.ci/release.sh b/.ci/release.sh index b0eaa1c..7e40208 100755 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -36,5 +36,5 @@ if [[ "$dry_run" == "false" ]] ; then DRY_RUN_MSG="" fi -echo "--- Release the binaries to Maven Central :maven: [./mvnw $GOAL)] $DRY_RUN_MSG" +echo "--- Release the binaries to Maven Central :maven: [./mvnw ${GOAL})] ${DRY_RUN_MSG}" ./mvnw -V -s .ci/settings.xml -Pgpg clean $GOAL -DskipTests --batch-mode | tee release.txt diff --git a/.ci/snapshot.sh b/.ci/snapshot.sh index b60f566..80e4614 100755 --- a/.ci/snapshot.sh +++ b/.ci/snapshot.sh @@ -33,5 +33,5 @@ if [[ "$dry_run" == "false" ]] ; then DRY_RUN_MSG="" fi -echo "--- Deploy the snapshot :package: [./mvnw $GOAL)] $DRY_RUN_MSG" -./mvnw -V -s .ci/settings.xml -Pgpg clean $GOAL -DskipTests --batch-mode | tee snapshot.txt +echo "--- Deploy the snapshot :package: [./mvnw ${GOAL})] ${DRY_RUN_MSG}" +./mvnw -V -s .ci/settings.xml -Pgpg clean ${GOAL} -DskipTests --batch-mode | tee snapshot.txt