Skip to content

Commit 72a74e5

Browse files
authored
ci: use .java-version and prepare to use VM with installed tools in BK (#3554)
1 parent c7f7f2c commit 72a74e5

File tree

10 files changed

+126
-74
lines changed

10 files changed

+126
-74
lines changed

.buildkite/hooks/prepare-common.sh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
echo "--- Install JDK17 :java:"
5-
# JDK version is defined in two different locations, here and .github/workflows/maven-goal/action.yml
6-
JAVA_URL=https://jvm-catalog.elastic.co/jdk
7-
JAVA_HOME=$(pwd)/.openjdk17
8-
JAVA_PKG="$JAVA_URL/latest_openjdk_17_linux.tar.gz"
9-
curl -L --output /tmp/jdk.tar.gz "$JAVA_PKG"
10-
mkdir -p "$JAVA_HOME"
11-
tar --extract --file /tmp/jdk.tar.gz --directory "$JAVA_HOME" --strip-components 1
12-
4+
# Configure the java version
5+
JAVA_VERSION=$(cat .java-version | xargs | tr -dc '[:print:]')
6+
JAVA_HOME="${HOME}/.java/openjdk${JAVA_VERSION}"
137
export JAVA_HOME
14-
PATH=$JAVA_HOME/bin:$PATH
8+
PATH="${JAVA_HOME}/bin:$PATH"
159
export PATH
1610

17-
java -version || true
11+
# Fallback to install at runtime
12+
if [ ! -d "${JAVA_HOME}" ] ; then
13+
# This should not be the case normally untless the .java-version file has been changed
14+
# and the VM Image is not yet available with the latest version.
15+
echo "--- Install JDK${JAVA_VERSION} :java:"
16+
JAVA_URL=https://jvm-catalog.elastic.co/jdk
17+
JAVA_PKG="${JAVA_URL}/latest_openjdk_${JAVA_VERSION}_linux.tar.gz"
18+
curl -L --output /tmp/jdk.tar.gz "$JAVA_PKG"
19+
mkdir -p "$JAVA_HOME"
20+
tar --extract --file /tmp/jdk.tar.gz --directory "$JAVA_HOME" --strip-components 1
21+
fi
22+
23+
java -version

.buildkite/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
agents:
22
provider: "gcp"
3+
#image: "family/apm-agent-java-ubuntu-2204"
34

45
steps:
56
- label: "Run the release"
@@ -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"'

.buildkite/snapshot.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
agents:
22
provider: "gcp"
3+
#image: "family/apm-agent-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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ echo $PATH
2121
java -version
2222

2323
set +x
24-
echo "--- Deploy the release :package:"
25-
./mvnw -V -s .ci/settings.xml -Pgpg clean deploy -DskipTests --batch-mode | tee release.txt
24+
# Default in dry-run mode
25+
GOAL="install"
26+
DRY_RUN_MSG="(dry-run)"
27+
# Otherwise, a RELEASE
28+
if [[ "$dry_run" == "false" ]] ; then
29+
GOAL="deploy"
30+
DRY_RUN_MSG=""
31+
fi
32+
33+
echo "--- Deploy the release :package: [./mvnw $GOAL)] $DRY_RUN_MSG"
34+
./mvnw -V -s .ci/settings.xml -Pgpg clean $GOAL -DskipTests --batch-mode | tee release.txt

.ci/snapshot.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ echo $PATH
2323
java -version
2424

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

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ jobs:
305305
distribution: 'temurin'
306306
steps:
307307
- uses: actions/checkout@v4
308-
- uses: ./.github/workflows/maven-goal
308+
- uses: ./.github/workflows/maven-goal-jdk
309309
with:
310310
test-java-version: ${{ matrix.version }}
311311
test-java-distribution: ${{ matrix.distribution }}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
3+
name: common build tasks
4+
description: Install specific JDK and run a command
5+
6+
inputs:
7+
test-java-version:
8+
description: 'Testing Java version'
9+
required: true
10+
default: '17'
11+
test-java-distribution:
12+
description: 'Testing Java distribution'
13+
required: true
14+
default: 'temurin'
15+
command:
16+
description: 'Command to execute'
17+
required: true
18+
shell:
19+
description: 'Default shell'
20+
default: 'bash'
21+
required: false
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
- name: Set up testing JDK
27+
uses: actions/setup-java@v4
28+
with:
29+
java-version: ${{ inputs.test-java-version}}
30+
distribution: ${{ inputs.test-java-distribution}}
31+
32+
- name: Set up TEST_JAVA_BINARY environment variable
33+
shell: bash
34+
run: |
35+
major_version="$(echo '${{ inputs.test-java-version }}' | sed 's/\([0-9]*\).*/\1/')"
36+
java_home_var=JAVA_HOME_${major_version}_${{ runner.arch }}
37+
echo "TEST_JAVA_BINARY=${!java_home_var}/bin/java" >> $GITHUB_ENV
38+
39+
- uses: ./.github/workflows/maven-goal
40+
with:
41+
command: ${{ inputs.command }}
42+
shell: ${{ inputs.shell }}
43+
env:
44+
TEST_JAVA_BINARY: ${{ env.TEST_JAVA_BINARY }}

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ name: common build tasks
44
description: Install specific JDK and run a command
55

66
inputs:
7-
test-java-version:
8-
description: 'Testing Java version'
9-
required: true
10-
default: '17'
11-
test-java-distribution:
12-
description: 'Testing Java distribution'
13-
required: true
14-
default: 'temurin'
157
command:
168
description: 'Command to execute'
179
required: true
@@ -23,23 +15,11 @@ inputs:
2315
runs:
2416
using: "composite"
2517
steps:
26-
- name: Set up testing JDK
27-
if: ${{ inputs.test-java-version != '17' }}
28-
uses: actions/setup-java@v4
29-
with:
30-
java-version: ${{ inputs.test-java-version}}
31-
distribution: ${{ inputs.test-java-distribution}}
3218
- name: Set up build JDK
3319
uses: actions/setup-java@v4
3420
with:
35-
java-version: 17 # NOTE: This version is also defined in .buildkite/hooks/pre-command
21+
java-version-file: .java-version
3622
distribution: temurin
3723
cache: 'maven'
38-
- name: Set up TEST_JAVA_BINARY environment variable
39-
shell: bash
40-
run: |
41-
major_version="$(echo '${{ inputs.test-java-version }}' | sed 's/\([0-9]*\).*/\1/')"
42-
java_home_var=JAVA_HOME_${major_version}_${{ runner.arch }}
43-
echo "TEST_JAVA_BINARY=${!java_home_var}/bin/java" >> $GITHUB_ENV
4424
- run: ${{ inputs.command }}
4525
shell: ${{ inputs.shell }}

.github/workflows/release.yml

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ on:
3434
type: boolean
3535
required: true
3636
default: false
37+
dry_run:
38+
description: If set, run a dry-run release
39+
default: false
40+
type: boolean
3741

3842
env:
39-
JAVA_VERSION: 17
40-
JAVA_DIST: temurin
4143
TAG_NAME: v${{ inputs.version }}
4244

4345
permissions:
@@ -68,21 +70,21 @@ jobs:
6870
with:
6971
ref: ${{ inputs.branch }}
7072
token: ${{ env.GITHUB_TOKEN }}
71-
- name: Set up JDK ${{ env.JAVA_VERSION }}
72-
uses: actions/setup-java@v4
73+
- name: Install JDK and mvn clean
74+
uses: ./.github/workflows/maven-goal
7375
with:
74-
java-version: ${{ env.JAVA_VERSION }}
75-
distribution: ${{ env.JAVA_DIST }}
76-
cache: 'maven'
76+
command: ./mvnw clean
7777
- name: Prepare changelog for release
78-
if: ${{ inputs.update_changelog }}
78+
if: ${{ inputs.update_changelog && ! inputs.dry_run }}
7979
run: |
8080
java .ci/ReleaseChangelog.java CHANGELOG.asciidoc ${{ inputs.version }}
8181
git commit -m "Prepare changelog for release ${{ inputs.version }}" CHANGELOG.asciidoc
8282
- name: Bump version and add git tag
83+
if: ${{ ! inputs.dry_run }}
8384
run: ./mvnw release:prepare -B -DpushChanges=false "-Darguments=-DskipTests -Dmaven.javadoc.skip=true" -DreleaseVersion=${{ inputs.version }}
84-
- run: git push --atomic origin ${{ inputs.branch }} ${{ env.TAG_NAME }}
85-
85+
- name: Push changes
86+
if: ${{ ! inputs.dry_run }}
87+
run: git push --atomic origin ${{ inputs.branch }} ${{ env.TAG_NAME }}
8688

8789
maven_central_deploy:
8890
name: "Deploy to Maven Central (Buildkite)"
@@ -103,19 +105,16 @@ jobs:
103105
pipelineCommit: ${{ env.TAG_NAME }}
104106
waitFor: true
105107
printBuildLogs: false
106-
# The action fails with .github/actions/buildkite/run.sh: line 24: 3: parameter missing.
107-
# Which is an unexpected bug.
108-
# Adding a random buildEnvVar to circumvent the behaviour.
109108
buildEnvVars: |
110-
something_something=true
111-
109+
dry_run=${{ inputs.dry_run || 'false' }}
112110
113111
await_artifact_on_maven_central:
114112
name: "Wait for artifacts to be available on maven central"
115113
runs-on: ubuntu-latest
116114
steps:
117115
- uses: actions/checkout@v4
118116
- name: Await artifacts published in maven central
117+
if: ${{ ! inputs.dry_run }}
119118
shell: bash
120119
timeout-minutes: 120
121120
run: |
@@ -147,8 +146,11 @@ jobs:
147146
with:
148147
ref: ${{ env.TAG_NAME }}
149148
token: ${{ env.GITHUB_TOKEN }}
150-
- run: .ci/release/update_major_branch.sh ${{ inputs.version }}
151-
- run: git push -f origin "$(echo '${{ inputs.version }}' | sed -E 's/\..+/.x/')"
149+
- name: Update major branch
150+
run: .ci/release/update_major_branch.sh ${{ inputs.version }}
151+
- name: Push changes
152+
if: ${{ ! inputs.dry_run }}
153+
run: git push -f origin "$(echo '${{ inputs.version }}' | sed -E 's/\..+/.x/')"
152154

153155
update_cloudfoundry:
154156
name: "Update Cloudfoundry"
@@ -175,8 +177,9 @@ jobs:
175177
- name: "Update Cloudfoundry index.yml file"
176178
shell: bash
177179
run: .ci/release/update_cloudfoundry.sh ${{ inputs.version }}
178-
- run: git push origin ${{ inputs.branch }}
179-
180+
- name: Push changes
181+
if: ${{ ! inputs.dry_run }}
182+
run: git push origin ${{ inputs.branch }}
180183

181184
build_and_push_docker_images:
182185
name: "Build and push docker images"
@@ -199,9 +202,11 @@ jobs:
199202
secretId: ${{ secrets.VAULT_SECRET_ID }}
200203
- name: "Build docker image"
201204
shell: bash
202-
run: |
203-
./scripts/docker-release/build_docker.sh
204-
./scripts/docker-release/push_docker.sh
205+
run: ./scripts/docker-release/build_docker.sh
206+
- name: "Push docker image"
207+
if: ${{ ! inputs.dry_run }}
208+
shell: bash
209+
run: ./scripts/docker-release/push_docker.sh
205210

206211
publish_aws_lambda:
207212
name: "Publish AWS Lambda"
@@ -218,14 +223,10 @@ jobs:
218223
- uses: actions/checkout@v4
219224
with:
220225
ref: ${{ env.TAG_NAME }}
221-
- name: Set up JDK ${{ env.JAVA_VERSION }}
222-
uses: actions/setup-java@v4
223-
with:
224-
java-version: ${{ env.JAVA_VERSION }}
225-
distribution: ${{ env.JAVA_DIST }}
226-
cache: 'maven'
227226
- name: Build Lambda-layer zip using agent from maven-central
228-
run: ./mvnw dependency:purge-local-repository package -pl apm-agent-lambda-layer
227+
uses: ./.github/workflows/maven-goal
228+
with:
229+
command: ./mvnw dependency:purge-local-repository package -pl apm-agent-lambda-layer
229230
- uses: hashicorp/[email protected]
230231
with:
231232
url: ${{ secrets.VAULT_ADDR }}
@@ -236,30 +237,33 @@ jobs:
236237
secret/observability-team/ci/service-account/apm-aws-lambda access_key_id | AWS_ACCESS_KEY_ID ;
237238
secret/observability-team/ci/service-account/apm-aws-lambda secret_access_key | AWS_SECRET_ACCESS_KEY
238239
- name: Publish
240+
if: ${{ ! inputs.dry_run }}
239241
run: |
240242
# Convert v1.2.3 to ver-1-2-3
241243
VERSION=${TAG_NAME/v/ver-}
242244
VERSION=${VERSION//./-}
243245
244246
ELASTIC_LAYER_NAME="elastic-apm-java-${VERSION}" .ci/publish-aws.sh
245247
- uses: actions/upload-artifact@v4
248+
if: ${{ ! inputs.dry_run }}
246249
with:
247250
name: arn-file
248251
path: .ci/.arn-file.md
249252
- name: Add ARN file to output
253+
if: ${{ ! inputs.dry_run }}
250254
id: arn_output
251255
run: |
252256
echo 'arn_content<<ARN_CONTENT_EOF' >> $GITHUB_OUTPUT
253257
cat .ci/.arn-file.md >> $GITHUB_OUTPUT
254258
echo 'ARN_CONTENT_EOF' >> $GITHUB_OUTPUT
255259
256-
257260
create_github_release:
258261
name: "Create GitHub Release"
259262
needs:
260263
- publish_aws_lambda
261264
- update_major_branch
262265
runs-on: ubuntu-latest
266+
if: ${{ ! inputs.dry_run }}
263267
permissions:
264268
contents: write
265269
steps:
@@ -286,10 +290,9 @@ jobs:
286290
--title="Release ${{ inputs.version }}" \
287291
--notes="[Release Notes for ${{ inputs.version }}](https://www.elastic.co/guide/en/apm/agent/java/current/release-notes-${{ steps.get_dotx_branch.outputs.dotx_branch }}.html#release-notes-${{ inputs.version }})
288292
${{ needs.publish_aws_lambda.outputs.arn_content }}"
289-
290293
291294
notify:
292-
if: always()
295+
if: ${{ always() && ! inputs.dry_run }}
293296
needs:
294297
- prepare_release
295298
- maven_central_deploy

.java-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17

0 commit comments

Comments
 (0)