diff --git a/.buildkite/hooks/prepare-common.sh b/.buildkite/hooks/prepare-common.sh index 68cf0d4ad4..50b3d3388e 100644 --- a/.buildkite/hooks/prepare-common.sh +++ b/.buildkite/hooks/prepare-common.sh @@ -1,17 +1,23 @@ #!/usr/bin/env bash set -euo pipefail -echo "--- Install JDK17 :java:" -# JDK version is defined in two different locations, here and .github/workflows/maven-goal/action.yml -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 diff --git a/.buildkite/release.yml b/.buildkite/release.yml index 1b6a41fae7..b646bf3309 100644 --- a/.buildkite/release.yml +++ b/.buildkite/release.yml @@ -1,5 +1,6 @@ agents: provider: "gcp" + #image: "family/apm-agent-java-ubuntu-2204" steps: - label: "Run the release" @@ -11,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"' diff --git a/.buildkite/snapshot.yml b/.buildkite/snapshot.yml index c33406f9f4..6421fad588 100644 --- a/.buildkite/snapshot.yml +++ b/.buildkite/snapshot.yml @@ -1,5 +1,6 @@ agents: provider: "gcp" + #image: "family/apm-agent-java-ubuntu-2204" steps: - label: "Run the snapshot" @@ -11,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"' diff --git a/.ci/release.sh b/.ci/release.sh index 77a418d863..b05947ce95 100755 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -21,5 +21,14 @@ echo $PATH java -version set +x -echo "--- Deploy the release :package:" -./mvnw -V -s .ci/settings.xml -Pgpg clean deploy -DskipTests --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 "--- Deploy the release :package: [./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 63ec170778..a11cd4eb9a 100755 --- a/.ci/snapshot.sh +++ b/.ci/snapshot.sh @@ -23,9 +23,14 @@ echo $PATH java -version set +x -echo "--- Deploy the snapshot :package:" -if [[ "$dry_run" == "true" ]] ; then - echo './mvnw -V -s .ci/settings.xml -Pgpg clean deploy -DskipTests --batch-mode' -else - ./mvnw -V -s .ci/settings.xml -Pgpg clean deploy -DskipTests --batch-mode | tee snapshot.txt +# Default in dry-run mode +GOAL="install" +DRY_RUN_MSG="(dry-run)" +# Otherwise, a snapshot +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 snapshot.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e31fd70f5..419c369cd3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -305,7 +305,7 @@ jobs: distribution: 'temurin' steps: - uses: actions/checkout@v4 - - uses: ./.github/workflows/maven-goal + - uses: ./.github/workflows/maven-goal-jdk with: test-java-version: ${{ matrix.version }} test-java-distribution: ${{ matrix.distribution }} diff --git a/.github/workflows/maven-goal-jdk/action.yml b/.github/workflows/maven-goal-jdk/action.yml new file mode 100644 index 0000000000..43379e2fcf --- /dev/null +++ b/.github/workflows/maven-goal-jdk/action.yml @@ -0,0 +1,44 @@ +--- + +name: common build tasks +description: Install specific JDK and run a command + +inputs: + test-java-version: + description: 'Testing Java version' + required: true + default: '17' + test-java-distribution: + description: 'Testing Java distribution' + required: true + default: 'temurin' + command: + description: 'Command to execute' + required: true + shell: + description: 'Default shell' + default: 'bash' + required: false + +runs: + using: "composite" + steps: + - name: Set up testing JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ inputs.test-java-version}} + distribution: ${{ inputs.test-java-distribution}} + + - name: Set up TEST_JAVA_BINARY environment variable + shell: bash + run: | + major_version="$(echo '${{ inputs.test-java-version }}' | sed 's/\([0-9]*\).*/\1/')" + java_home_var=JAVA_HOME_${major_version}_${{ runner.arch }} + echo "TEST_JAVA_BINARY=${!java_home_var}/bin/java" >> $GITHUB_ENV + + - uses: ./.github/workflows/maven-goal + with: + command: ${{ inputs.command }} + shell: ${{ inputs.shell }} + env: + TEST_JAVA_BINARY: ${{ env.TEST_JAVA_BINARY }} diff --git a/.github/workflows/maven-goal/action.yml b/.github/workflows/maven-goal/action.yml index a2ddbea62b..371934f3a4 100644 --- a/.github/workflows/maven-goal/action.yml +++ b/.github/workflows/maven-goal/action.yml @@ -4,14 +4,6 @@ name: common build tasks description: Install specific JDK and run a command inputs: - test-java-version: - description: 'Testing Java version' - required: true - default: '17' - test-java-distribution: - description: 'Testing Java distribution' - required: true - default: 'temurin' command: description: 'Command to execute' required: true @@ -23,23 +15,11 @@ inputs: runs: using: "composite" steps: - - name: Set up testing JDK - if: ${{ inputs.test-java-version != '17' }} - uses: actions/setup-java@v4 - with: - java-version: ${{ inputs.test-java-version}} - distribution: ${{ inputs.test-java-distribution}} - name: Set up build JDK uses: actions/setup-java@v4 with: - java-version: 17 # NOTE: This version is also defined in .buildkite/hooks/pre-command + java-version-file: .java-version distribution: temurin cache: 'maven' - - name: Set up TEST_JAVA_BINARY environment variable - shell: bash - run: | - major_version="$(echo '${{ inputs.test-java-version }}' | sed 's/\([0-9]*\).*/\1/')" - java_home_var=JAVA_HOME_${major_version}_${{ runner.arch }} - echo "TEST_JAVA_BINARY=${!java_home_var}/bin/java" >> $GITHUB_ENV - run: ${{ inputs.command }} shell: ${{ inputs.shell }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 04915c1910..d15ea5f5bc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,10 +34,12 @@ on: type: boolean required: true default: false + dry_run: + description: If set, run a dry-run release + default: false + type: boolean env: - JAVA_VERSION: 17 - JAVA_DIST: temurin TAG_NAME: v${{ inputs.version }} permissions: @@ -68,21 +70,21 @@ jobs: with: ref: ${{ inputs.branch }} token: ${{ env.GITHUB_TOKEN }} - - name: Set up JDK ${{ env.JAVA_VERSION }} - uses: actions/setup-java@v4 + - name: Install JDK and mvn clean + uses: ./.github/workflows/maven-goal with: - java-version: ${{ env.JAVA_VERSION }} - distribution: ${{ env.JAVA_DIST }} - cache: 'maven' + command: ./mvnw clean - name: Prepare changelog for release - if: ${{ inputs.update_changelog }} + if: ${{ inputs.update_changelog && ! inputs.dry_run }} run: | java .ci/ReleaseChangelog.java CHANGELOG.asciidoc ${{ inputs.version }} git commit -m "Prepare changelog for release ${{ inputs.version }}" CHANGELOG.asciidoc - name: Bump version and add git tag + if: ${{ ! inputs.dry_run }} run: ./mvnw release:prepare -B -DpushChanges=false "-Darguments=-DskipTests -Dmaven.javadoc.skip=true" -DreleaseVersion=${{ inputs.version }} - - run: git push --atomic origin ${{ inputs.branch }} ${{ env.TAG_NAME }} - + - name: Push changes + if: ${{ ! inputs.dry_run }} + run: git push --atomic origin ${{ inputs.branch }} ${{ env.TAG_NAME }} maven_central_deploy: name: "Deploy to Maven Central (Buildkite)" @@ -103,12 +105,8 @@ jobs: pipelineCommit: ${{ env.TAG_NAME }} waitFor: true printBuildLogs: false - # The action fails with .github/actions/buildkite/run.sh: line 24: 3: parameter missing. - # Which is an unexpected bug. - # Adding a random buildEnvVar to circumvent the behaviour. buildEnvVars: | - something_something=true - + dry_run=${{ inputs.dry_run || 'false' }} await_artifact_on_maven_central: name: "Wait for artifacts to be available on maven central" @@ -116,6 +114,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Await artifacts published in maven central + if: ${{ ! inputs.dry_run }} shell: bash timeout-minutes: 120 run: | @@ -147,8 +146,11 @@ jobs: with: ref: ${{ env.TAG_NAME }} token: ${{ env.GITHUB_TOKEN }} - - run: .ci/release/update_major_branch.sh ${{ inputs.version }} - - run: git push -f origin "$(echo '${{ inputs.version }}' | sed -E 's/\..+/.x/')" + - name: Update major branch + run: .ci/release/update_major_branch.sh ${{ inputs.version }} + - name: Push changes + if: ${{ ! inputs.dry_run }} + run: git push -f origin "$(echo '${{ inputs.version }}' | sed -E 's/\..+/.x/')" update_cloudfoundry: name: "Update Cloudfoundry" @@ -175,8 +177,9 @@ jobs: - name: "Update Cloudfoundry index.yml file" shell: bash run: .ci/release/update_cloudfoundry.sh ${{ inputs.version }} - - run: git push origin ${{ inputs.branch }} - + - name: Push changes + if: ${{ ! inputs.dry_run }} + run: git push origin ${{ inputs.branch }} build_and_push_docker_images: name: "Build and push docker images" @@ -199,9 +202,11 @@ jobs: secretId: ${{ secrets.VAULT_SECRET_ID }} - name: "Build docker image" shell: bash - run: | - ./scripts/docker-release/build_docker.sh - ./scripts/docker-release/push_docker.sh + run: ./scripts/docker-release/build_docker.sh + - name: "Push docker image" + if: ${{ ! inputs.dry_run }} + shell: bash + run: ./scripts/docker-release/push_docker.sh publish_aws_lambda: name: "Publish AWS Lambda" @@ -218,14 +223,10 @@ jobs: - uses: actions/checkout@v4 with: ref: ${{ env.TAG_NAME }} - - name: Set up JDK ${{ env.JAVA_VERSION }} - uses: actions/setup-java@v4 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: ${{ env.JAVA_DIST }} - cache: 'maven' - name: Build Lambda-layer zip using agent from maven-central - run: ./mvnw dependency:purge-local-repository package -pl apm-agent-lambda-layer + uses: ./.github/workflows/maven-goal + with: + command: ./mvnw dependency:purge-local-repository package -pl apm-agent-lambda-layer - uses: hashicorp/vault-action@v3.0.0 with: url: ${{ secrets.VAULT_ADDR }} @@ -236,6 +237,7 @@ jobs: secret/observability-team/ci/service-account/apm-aws-lambda access_key_id | AWS_ACCESS_KEY_ID ; secret/observability-team/ci/service-account/apm-aws-lambda secret_access_key | AWS_SECRET_ACCESS_KEY - name: Publish + if: ${{ ! inputs.dry_run }} run: | # Convert v1.2.3 to ver-1-2-3 VERSION=${TAG_NAME/v/ver-} @@ -243,23 +245,25 @@ jobs: ELASTIC_LAYER_NAME="elastic-apm-java-${VERSION}" .ci/publish-aws.sh - uses: actions/upload-artifact@v4 + if: ${{ ! inputs.dry_run }} with: name: arn-file path: .ci/.arn-file.md - name: Add ARN file to output + if: ${{ ! inputs.dry_run }} id: arn_output run: | echo 'arn_content<> $GITHUB_OUTPUT cat .ci/.arn-file.md >> $GITHUB_OUTPUT echo 'ARN_CONTENT_EOF' >> $GITHUB_OUTPUT - create_github_release: name: "Create GitHub Release" needs: - publish_aws_lambda - update_major_branch runs-on: ubuntu-latest + if: ${{ ! inputs.dry_run }} permissions: contents: write steps: @@ -286,10 +290,9 @@ jobs: --title="Release ${{ inputs.version }}" \ --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 }}) ${{ needs.publish_aws_lambda.outputs.arn_content }}" - notify: - if: always() + if: ${{ always() && ! inputs.dry_run }} needs: - prepare_release - maven_central_deploy diff --git a/.java-version b/.java-version new file mode 100644 index 0000000000..8e2afd3427 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +17 \ No newline at end of file