From f48ee590fa125d9b597e227b6821e4d86eb7b646 Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Tue, 20 Aug 2024 12:48:24 -0400 Subject: [PATCH] CUST-110209: do SDK maven snapshot release on push and use the snapshot SDK in smoke test. Add a new app test the sdk without the agent being attached --- .github/workflows/push.yml | 76 ++++++++++++++++++- .../netty-test-no-agent/build.gradle.kts | 52 +++++++++++++ .../java/com/solarwinds/netty/NettyApp.java | 35 +++++++++ smoke-tests/netty-test/build.gradle.kts | 12 ++- .../java/com/solarwinds/netty/NettyApp.java | 2 + smoke-tests/settings.gradle | 1 + smoke-tests/spring-boot-webmvc/build.gradle | 10 ++- solarwinds-otel-sdk/build.gradle | 12 ++- 8 files changed, 194 insertions(+), 6 deletions(-) create mode 100644 smoke-tests/netty-test-no-agent/build.gradle.kts create mode 100644 smoke-tests/netty-test-no-agent/src/main/java/com/solarwinds/netty/NettyApp.java diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index d9392ff6..adbf1307 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -22,9 +22,16 @@ env: SWO_EMAIL: ${{ secrets.SWO_EMAIL }} SWO_PWORD: ${{ secrets.SWO_PWORD }} STAGE_BUCKET: ${{ secrets.STAGE_BUCKET }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_TOKEN: ${{ secrets.SONATYPE_TOKEN }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PRIVATE_KEY_PASSPHRASE: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }} jobs: s3-stage-upload: # this job uploads the jar to stage s3 + needs: + - maven_snapshot_release runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -178,10 +185,16 @@ jobs: - name: Docker login run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin + - name: Set agent version env + run: | + ./gradlew build -x test + GIT_HASH=$(git rev-parse --short "$GITHUB_SHA") + echo "AGENT_VERSION=$(cd agent/build/libs && unzip -p solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }' | sed 's/[^a-z0-9.-]//g').$GIT_HASH" >> $GITHUB_ENV + - name: Execute smoke tests run: | cd smoke-tests - ./gradlew test -s + ./gradlew test - uses: actions/upload-artifact@v4 if: always() @@ -309,6 +322,12 @@ jobs: java-version: '17' distribution: 'temurin' + - name: Set agent version env + run: | + ./gradlew build -x test + GIT_HASH=$(git rev-parse --short "$GITHUB_SHA") + echo "AGENT_VERSION=$(cd agent/build/libs && unzip -p solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }' | sed 's/[^a-z0-9.-]//g').$GIT_HASH" >> $GITHUB_ENV + - name: Run application working-directory: smoke-tests run: | @@ -316,6 +335,30 @@ jobs: env: SW_APM_SERVICE_KEY: ${{ secrets.SW_APM_SERVICE_KEY }}:smoke-test-linux + smoke-test-no-agent: + runs-on: ubuntu-latest + needs: + - s3-stage-upload + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Set agent version env + run: | + ./gradlew build -x test + GIT_HASH=$(git rev-parse --short "$GITHUB_SHA") + echo "AGENT_VERSION=$(cd agent/build/libs && unzip -p solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }' | sed 's/[^a-z0-9.-]//g').$GIT_HASH" >> $GITHUB_ENV + + - name: Run application + working-directory: smoke-tests + run: | + ./gradlew :netty-test-no-agent:run + smoke-test-windows: runs-on: windows-latest needs: @@ -354,6 +397,12 @@ jobs: - name: Docker login run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin + - name: Set agent version env + run: | + ./gradlew build -x test + GIT_HASH=$(git rev-parse --short "$GITHUB_SHA") + echo "AGENT_VERSION=$(cd agent/build/libs && unzip -p solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }' | sed 's/[^a-z0-9.-]//g').$GIT_HASH" >> $GITHUB_ENV + - name: Build smoke-test run: | cd smoke-tests @@ -420,3 +469,28 @@ jobs: - name: Docker logout if: always() run: docker logout + + maven_snapshot_release: + runs-on: ubuntu-latest + env: + SNAPSHOT_BUILD: true + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Set agent version env + run: | + ./gradlew build -x test + GIT_HASH=$(git rev-parse --short "$GITHUB_SHA") + echo "AGENT_VERSION=$(cd agent/build/libs && unzip -p solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }' | sed 's/[^a-z0-9.-]//g').$GIT_HASH" >> $GITHUB_ENV + + - name: Publish + run: ./gradlew publish \ No newline at end of file diff --git a/smoke-tests/netty-test-no-agent/build.gradle.kts b/smoke-tests/netty-test-no-agent/build.gradle.kts new file mode 100644 index 00000000..4531beca --- /dev/null +++ b/smoke-tests/netty-test-no-agent/build.gradle.kts @@ -0,0 +1,52 @@ +import java.net.URI + +/* + * © SolarWinds Worldwide, LLC. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + java + application +} + +group = "com.solarwinds" +version = "unspecified" + +repositories { + mavenCentral() + maven { + url = URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/") + credentials { + username = System.getenv("SONATYPE_USERNAME") + password = System.getenv("SONATYPE_TOKEN") + } + } +} + +val sdkVersion = System.getenv("AGENT_VERSION")?.also { println("Using SDK version: $it") } ?: "2.6.0" +dependencies { + implementation("io.netty:netty-common:4.1.94.Final") + implementation("io.github.appoptics:solarwinds-otel-sdk:$sdkVersion-SNAPSHOT") + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} + +application { + mainClass.set("com.solarwinds.netty.NettyApp") +} diff --git a/smoke-tests/netty-test-no-agent/src/main/java/com/solarwinds/netty/NettyApp.java b/smoke-tests/netty-test-no-agent/src/main/java/com/solarwinds/netty/NettyApp.java new file mode 100644 index 00000000..4086bbe7 --- /dev/null +++ b/smoke-tests/netty-test-no-agent/src/main/java/com/solarwinds/netty/NettyApp.java @@ -0,0 +1,35 @@ +/* + * © SolarWinds Worldwide, LLC. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.solarwinds.netty; + +import io.netty.util.NetUtil; +import com.solarwinds.api.ext.SolarwindsAgent; + +import java.util.concurrent.TimeUnit; + +public class NettyApp { + public static void main(String[] args){ + SolarwindsAgent.setTransactionName("hello world!"); + System.out.printf("Number of interfaces: %d%n",NetUtil.NETWORK_INTERFACES.size()); + try { + TimeUnit.MINUTES.sleep(1); + } catch (InterruptedException ignore) { + + } + System.out.printf("Shutting down%n"); + } +} diff --git a/smoke-tests/netty-test/build.gradle.kts b/smoke-tests/netty-test/build.gradle.kts index 73924ce2..c6aadded 100644 --- a/smoke-tests/netty-test/build.gradle.kts +++ b/smoke-tests/netty-test/build.gradle.kts @@ -1,3 +1,5 @@ +import java.net.URI + /* * © SolarWinds Worldwide, LLC. All rights reserved. * @@ -25,10 +27,19 @@ version = "unspecified" repositories { mavenCentral() + maven { + url = URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/") + credentials { + username = System.getenv("SONATYPE_USERNAME") + password = System.getenv("SONATYPE_TOKEN") + } + } } +val sdkVersion = System.getenv("AGENT_VERSION")?.also { println("Using SDK version: $it") } ?: "2.6.0" dependencies { implementation("io.netty:netty-common:4.1.94.Final") + implementation("io.github.appoptics:solarwinds-otel-sdk:$sdkVersion-SNAPSHOT") testImplementation(platform("org.junit:junit-bom:5.9.1")) testImplementation("org.junit.jupiter:junit-jupiter") } @@ -38,7 +49,6 @@ tasks.test { } val swoAgentPath = project.buildDir.toString() + "/swo/solarwinds-apm-agent.jar" - fun getAgentPath(downloadPath: String) = if (System.getenv("AGENT_PATH") == null) downloadPath else System.getenv("AGENT_PATH") diff --git a/smoke-tests/netty-test/src/main/java/com/solarwinds/netty/NettyApp.java b/smoke-tests/netty-test/src/main/java/com/solarwinds/netty/NettyApp.java index cde783c6..4086bbe7 100644 --- a/smoke-tests/netty-test/src/main/java/com/solarwinds/netty/NettyApp.java +++ b/smoke-tests/netty-test/src/main/java/com/solarwinds/netty/NettyApp.java @@ -17,11 +17,13 @@ package com.solarwinds.netty; import io.netty.util.NetUtil; +import com.solarwinds.api.ext.SolarwindsAgent; import java.util.concurrent.TimeUnit; public class NettyApp { public static void main(String[] args){ + SolarwindsAgent.setTransactionName("hello world!"); System.out.printf("Number of interfaces: %d%n",NetUtil.NETWORK_INTERFACES.size()); try { TimeUnit.MINUTES.sleep(1); diff --git a/smoke-tests/settings.gradle b/smoke-tests/settings.gradle index 3ea0c9d8..f84d8528 100644 --- a/smoke-tests/settings.gradle +++ b/smoke-tests/settings.gradle @@ -28,4 +28,5 @@ rootProject.name = 'smoke-tests' include 'netty-test' include 'spring-boot-webmvc' +include 'netty-test-no-agent' diff --git a/smoke-tests/spring-boot-webmvc/build.gradle b/smoke-tests/spring-boot-webmvc/build.gradle index 7665dde9..4f431649 100644 --- a/smoke-tests/spring-boot-webmvc/build.gradle +++ b/smoke-tests/spring-boot-webmvc/build.gradle @@ -29,10 +29,18 @@ version = "0.0.1-SNAPSHOT" repositories { mavenCentral() + maven { + url = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + credentials { + username = System.getenv("SONATYPE_USERNAME") + password = System.getenv("SONATYPE_TOKEN") + } + } } +def sdkVersion = System.getenv("AGENT_VERSION") ?: "2.6.0" dependencies { - implementation("io.github.appoptics:solarwinds-otel-sdk:2.2.0") + implementation("io.github.appoptics:solarwinds-otel-sdk:$sdkVersion-SNAPSHOT") implementation("io.github.microutils:kotlin-logging-jvm:3.0.5") implementation("org.springframework.boot:spring-boot-starter-actuator") diff --git a/solarwinds-otel-sdk/build.gradle b/solarwinds-otel-sdk/build.gradle index 793010b4..0211530a 100644 --- a/solarwinds-otel-sdk/build.gradle +++ b/solarwinds-otel-sdk/build.gradle @@ -83,9 +83,12 @@ publishing { name = 'Apache License, Version 2.0' } } + groupId = 'io.github.appoptics' artifactId = "${archivesBaseName}" - version = "${versions.agent}" + def sdkVersion = System.getenv("AGENT_VERSION") ?: "2.6.0" + version = Boolean.parseBoolean(System.getenv("SNAPSHOT_BUILD")) ? "$sdkVersion-SNAPSHOT" : "${versions.agent}" + from components.java artifact sourcesJar artifact javadocJar @@ -93,10 +96,14 @@ publishing { } publishToMavenLocal } + repositories { maven { name = "OSSRH" - url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + + url = Boolean.parseBoolean(System.getenv("SNAPSHOT_BUILD")) ? snapshotsRepoUrl : releasesRepoUrl credentials { username = System.getenv("SONATYPE_USERNAME") password = System.getenv("SONATYPE_TOKEN") @@ -115,7 +122,6 @@ signing { sign publishing.publications.mavenJava } - test { useJUnitPlatform() testLogging {