Skip to content

Commit 418d77c

Browse files
snowpmurki
andauthored
support two modes of okhttp instrumentation via plugin + wire up release pipeline (#144)
* wire up plugin release, add another okhttp instrumentation option * simplify build * fixes * update CI to include apollo3 --------- Co-authored-by: Miguel Juarez Lopez <[email protected]>
1 parent 64a7ce7 commit 418d77c

14 files changed

+247
-94
lines changed

.github/workflows/integrations_android.yaml

+33-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ on:
1313
required: true
1414
type: string
1515
jobs:
16-
build-capture-timber:
17-
name: Build Capture Timber
16+
build-gradle-libraries:
17+
name: Build Gradle Libraries
1818
runs-on: ubuntu-latest
1919
defaults:
2020
run:
@@ -31,17 +31,45 @@ jobs:
3131
cache: gradle
3232
- name: Install Rust target
3333
run: rustup update && rustup target add aarch64-linux-android && rustup target add x86_64-linux-android
34-
- name: Build artifacts with Gradle
34+
- name: Build Timber artifacts with Gradle
3535
run: ./gradlew :capture-timber:publish -PVERSION_NAME="${{ inputs.version }}" --info
3636
env:
3737
SKIP_PROTO_GEN: 1
38-
- name: Compress artifacts
38+
- name: Build Apollo artifacts with Gradle
39+
run: ./gradlew :capture-apollo3:publish -PVERSION_NAME="${{ inputs.version }}" --info
40+
env:
41+
SKIP_PROTO_GEN: 1
42+
- name: Build Gradle Plugin artifacts with Gradle
43+
run: ./gradlew :capture-plugin:publish -PVERSION_NAME="${{ inputs.version }}" --info
44+
env:
45+
SKIP_PROTO_GEN: 1
46+
- name: Compress Timber artifacts
3947
run: |
4048
readonly dir=$(pwd)
4149
(cd capture-timber/build/repos/releases/io/bitdrift/capture-timber/${{ inputs.version }} && zip -r "$dir/capture-timber.zip" ./*)
42-
- name: Upload artifacts
50+
- name: Compress Apollo artifacts
51+
run: |
52+
readonly dir=$(pwd)
53+
(cd capture-apollo3/build/repos/releases/io/bitdrift/capture-apollo3/${{ inputs.version }} && zip -r "$dir/capture-apollo3.zip" ./*)
54+
- name: Compress Android Plugin artifacts
55+
run: |
56+
readonly dir=$(pwd)
57+
(cd capture-plugin/build/repos/releases/io/bitdrift/capture-plugin/${{ inputs.version }} && zip -r "$dir/capture-plugin.zip" ./*)
58+
- name: Upload Timber artifacts
4359
uses: actions/upload-artifact@v4
4460
with:
4561
name: capture-timber.zip
4662
path: platform/jvm/capture-timber.zip
4763
if-no-files-found: error
64+
- name: Upload Apollo artifacts
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: capture-apollo3.zip
68+
path: platform/jvm/capture-apollo3.zip
69+
if-no-files-found: error
70+
- name: Upload Gradle Plugin artifacts
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: capture-plugin.zip
74+
path: platform/jvm/capture-plugin.zip
75+
if-no-files-found: error

.github/workflows/release_gh.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ jobs:
198198
- uses: actions/download-artifact@v4
199199
with:
200200
name: capture-timber.zip
201+
- uses: actions/download-artifact@v4
202+
with:
203+
name: capture-apollo3.zip
204+
- uses: actions/download-artifact@v4
205+
with:
206+
name: capture-plugin.zip
201207
- name: Prepare Android artifacts
202208
run: ./ci/gh_prepare_android_artifacts.sh "$VERSION"
203209
env:
@@ -223,7 +229,9 @@ jobs:
223229
"Capture-$VERSION.android.zip" \
224230
"example-apps.ios.zip" \
225231
"example-apps.android.zip" \
226-
"capture-timber-$VERSION.android.zip"
232+
"capture-timber-$VERSION.android.zip" \
233+
"capture-apollo3-$VERSION.android.zip" \
234+
"capture-plugin-$VERSION.android.zip"
227235
env:
228236
VERSION: ${{ inputs.version }}
229237
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release_public.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ jobs:
9090
run: |
9191
gh release download "v$VERSION" -p 'Capture*.android.zip'
9292
gh release download "v$VERSION" -p 'capture-timber*.android.zip'
93+
gh release download "v$VERSION" -p 'capture-plugin*.android.zip'
9394
env:
9495
VERSION: ${{ inputs.version }}
9596
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9697
- name: Upload Android Artifacts to aws bucket
97-
run: ./ci/capture_android_release.sh ${{ inputs.version }} "Capture-${{ inputs.version }}.android.zip" "capture-timber-${{ inputs.version }}.android.zip"
98+
run: ./ci/capture_android_release.sh ${{ inputs.version }} "Capture-${{ inputs.version }}.android.zip" "capture-timber-${{ inputs.version }}.android.zip" "capture-apollo3-${{ inputs.version }}.android.zip" "capture-plugin-${{ inputs.version }}.android.zip"
9899

ci/capture_android_release.sh

+18-23
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ readonly remote_location_root_prefix="s3://bitdrift-public-dl/sdk/android-maven/
99
readonly version="$1"
1010
readonly capture_archive="$2"
1111
readonly capture_timber_archive="$3"
12+
readonly capture_apollo3_archive="$4"
13+
readonly capture_plugin_archive="$5"
1214

1315
function upload_file() {
1416
local -r location="$1"
@@ -78,36 +80,29 @@ function release_capture_sdk() {
7880
popd
7981
}
8082

81-
function release_capture_timber() {
83+
function release_gradle_library() {
84+
local -r library_name="$1"
85+
local -r archive="$2"
86+
8287
echo "+++ dl.bitdrift.io Android Capture Timber artifacts upload"
8388

84-
# We get a zip containing the artifacts named per Maven conventions.
89+
local -r remote_location_prefix="$remote_location_root_prefix/$library_name"
8590

8691
pushd "$(mktemp -d)"
87-
unzip -o "$sdk_repo/$capture_timber_archive"
88-
89-
echo "+++ Uploading artifacts to s3 bucket"
92+
unzip -o "$archive"
93+
94+
# Make sure we update the top-level maven-metadata.xml file with the new release version
95+
aws s3 cp maven-metadata.xml* "$remote_location_prefix/" --region us-east-1
9096

91-
local -r remote_location_prefix="$remote_location_root_prefix/capture-timber"
92-
local -r name="capture-timber-$version"
97+
# Update the per-version files
98+
aws s3 cp "$sdk_repo/ci/LICENSE.txt" "$remote_location_prefix/$version/LICENSE.txt" --region us-east-1
99+
aws s3 cp "$sdk_repo/ci/NOTICE.txt" "$remote_location_prefix/$version/NOTICE.txt" --region us-east-1
93100

94-
files=(\
95-
"$sdk_repo/ci/LICENSE.txt" \
96-
"$sdk_repo/ci/NOTICE.txt" \
97-
"$name.pom" \
98-
"$name-javadoc.jar" \
99-
"$name-sources.jar" \
100-
"$name.module" \
101-
"$name.aar" \
102-
)
103-
104-
for file in "${files[@]}"; do
105-
upload_file "$remote_location_prefix/$version" "$file"
106-
done
107-
108-
generate_maven_file "$remote_location_prefix"
101+
aws s3 cp "$version" "$remote_location_prefix/$version/" --recursive --region us-east-1
109102
popd
110103
}
111104

112105
release_capture_sdk
113-
release_capture_timber
106+
release_gradle_library "capture-timber" "$capture_timber_archive"
107+
release_gradle_library "capture-apollo3" "$capture_apollo3_archive"
108+
release_gradle_library "capture-plugin" "$capture_plugin_archive"

ci/gh_prepare_android_artifacts.sh

+10-22
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,21 @@ function prepare_capture_sdk() {
4343
function prepare_capture_timber() {
4444
echo "+++ Preparing Android Capture Timber library artifacts for '$version' version"
4545

46-
pushd "$(mktemp -d)"
47-
local -r out_artifacts_dir="capture-timber-out"
48-
49-
unzip "$sdk_repo/capture-timber.zip"
50-
51-
mkdir "$out_artifacts_dir"
46+
cp "$sdk_repo/capture-timber.zip" "$sdk_repo/capture-timber-$version.android.zip"
47+
}
5248

53-
local -r name="capture-timber-$version"
49+
function prepare_capture_apollo3() {
50+
echo "+++ Preparing Android Capture Apollo3 library artifacts for '$version' version"
5451

55-
files=(\
56-
"$name.aar" \
57-
"$name.module" \
58-
"$name.pom" \
59-
"$name-javadoc.jar" \
60-
"$name-sources.jar" \
61-
"$sdk_repo/ci/LICENSE.txt" \
62-
"$sdk_repo/ci/NOTICE.txt" \
63-
)
52+
cp "$sdk_repo/capture-apollo3.zip" "$sdk_repo/capture-apollo4-$version.android.zip"
53+
}
6454

65-
for file in "${files[@]}"; do
66-
filename=$(basename "$file")
67-
mv "$file" "$out_artifacts_dir/$filename"
68-
done
55+
function prepare_capture_plugin() {
56+
echo "+++ Preparing Android Capture Android Plugin artifacts for '$version' version"
6957

70-
(cd "$out_artifacts_dir" && zip -r "$sdk_repo/capture-timber-$version.android.zip" ./*)
71-
popd
58+
cp "$sdk_repo/capture-plugin.zip" "$sdk_repo/capture-plugin-$version.android.zip"
7259
}
7360

7461
prepare_capture_sdk
7562
prepare_capture_timber
63+
prepare_capture_plugin

platform/jvm/capture-apollo3/build.gradle.kts

+50-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ plugins {
33
alias(libs.plugins.kotlin.android)
44
alias(libs.plugins.detekt)
55

6+
// Publish
7+
alias(libs.plugins.dokka) // Must be applied here for publish plugin.
8+
alias(libs.plugins.maven.publish)
9+
signing
10+
611
id("dependency-license-config")
712
}
813

@@ -55,9 +60,50 @@ tasks.preBuild {
5560

5661
dependencies {
5762
implementation(project(":capture"))
58-
implementation("com.apollographql.apollo3:apollo-runtime:3.8.3")
63+
implementation(libs.apollo.runtime)
64+
65+
testImplementation(libs.truth)
66+
testImplementation(libs.junit)
67+
testImplementation(libs.kotlin.mockito.kotlin)
68+
}
5969

60-
testImplementation("com.google.truth:truth:1.4.4")
61-
testImplementation("junit:junit:4.13.2")
62-
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") // last version with Java 8 support
70+
mavenPublishing {
71+
pom {
72+
name.set("CaptureApollo")
73+
description.set("Official Capture integration for Apollo v3 (GraphQL).")
74+
url.set("https://bitdrift.io")
75+
licenses {
76+
license {
77+
name.set("BITDRIFT SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT")
78+
url.set("https://dl.bitdrift.io/sdk/android-maven/io/bitdrift/capture-timber/${findProperty("VERSION_NAME")}/LICENSE.txt")
79+
distribution.set("repo")
80+
}
81+
license {
82+
name.set("NOTICE")
83+
url.set("https://dl.bitdrift.io/sdk/android-maven/io/bitdrift/capture-timber/${findProperty("VERSION_NAME")}/NOTICE.txt")
84+
distribution.set("repo")
85+
}
86+
}
87+
developers {
88+
developer {
89+
id.set("bitdriftlabs")
90+
name.set("Bitdrift, Inc.")
91+
url.set("https://github.com/bitdriftlabs")
92+
email.set("[email protected]")
93+
}
94+
scm {
95+
connection.set("scm:git:git://github.com/bitdriftlabs/capture-sdk.git")
96+
developerConnection.set("scm:git:ssh://[email protected]:bitdriftlabs/capture-sdk.git")
97+
url.set("https://github.com/bitdriftlabs/capture-sdk")
98+
}
99+
}
100+
}
101+
}
102+
103+
publishing {
104+
repositories {
105+
maven {
106+
url = uri(layout.buildDirectory.dir("repos/releases"))
107+
}
108+
}
63109
}

platform/jvm/capture-plugin/build.gradle.kts

+41-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
id("java-gradle-plugin")
66
}
77

8+
group = "io.bitdrift"
9+
810
dependencies {
911
compileOnly("com.android.tools.build:gradle:7.4.0")
1012
compileOnly("org.ow2.asm:asm-commons:9.4")
@@ -22,17 +24,51 @@ dependencies {
2224
gradlePlugin {
2325
plugins {
2426
create("capturePlugin") {
25-
id = "io.bitdrift.capture.capture-plugin"
27+
id = "io.bitdrift.capture-plugin"
2628
implementationClass = "io.bitdrift.capture.CapturePlugin"
2729
}
2830
}
2931
}
3032

33+
mavenPublishing {
34+
configureBasedOnAppliedPlugins()
35+
36+
pom {
37+
name.set("CapturePlugin")
38+
description.set("Official Capture Gradle plugin.")
39+
url.set("https://bitdrift.io")
40+
licenses {
41+
license {
42+
name.set("BITDRIFT SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT")
43+
url.set("https://dl.bitdrift.io/sdk/android-maven/io/bitdrift/capture-plugin/${findProperty("VERSION_NAME")}/LICENSE.txt")
44+
distribution.set("repo")
45+
}
46+
license {
47+
name.set("NOTICE")
48+
url.set("https://dl.bitdrift.io/sdk/android-maven/io/bitdrift/capture-plugin/${findProperty("VERSION_NAME")}/NOTICE.txt")
49+
distribution.set("repo")
50+
}
51+
}
52+
developers {
53+
developer {
54+
id.set("bitdriftlabs")
55+
name.set("Bitdrift, Inc.")
56+
url.set("https://github.com/bitdriftlabs")
57+
email.set("[email protected]")
58+
}
59+
scm {
60+
connection.set("scm:git:git://github.com/bitdriftlabs/capture-sdk.git")
61+
developerConnection.set("scm:git:ssh://[email protected]:bitdriftlabs/capture-sdk.git")
62+
url.set("https://github.com/bitdriftlabs/capture-sdk")
63+
}
64+
}
65+
}
66+
}
67+
3168
publishing {
3269
repositories {
33-
mavenLocal()
70+
maven {
71+
url = uri(layout.buildDirectory.dir("repos/releases"))
72+
}
3473
}
3574
}
36-
37-
group = "io.bitdrift.capture.capture-plugin"
38-
version = "0.1.0"

platform/jvm/capture-plugin/src/main/kotlin/io/bitdrift/capture/AndroidComponentsConfig.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ fun AndroidComponentsExtension<*, *, *>.configure(
6161
FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS,
6262
) { params ->
6363
params.tmpDir.set(tmpDir)
64-
params.debug.set(false)
64+
params.debug.set(extension.instrumentation.debug)
65+
params.proxyOkHttpEventListener.set(extension.instrumentation.proxyOkHttpEventListener)
6566
}
6667
}
6768
}

platform/jvm/capture-plugin/src/main/kotlin/io/bitdrift/capture/extension/InstrumentationExtension.kt

+2
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ open class InstrumentationExtension @Inject constructor(objects: ObjectFactory)
1919
val debug: Property<Boolean> = objects.property(Boolean::class.java).convention(
2020
false
2121
)
22+
23+
val proxyOkHttpEventListener: Property<Boolean> = objects.property(Boolean::class.java).convention(false)
2224
}

platform/jvm/capture-plugin/src/main/kotlin/io/bitdrift/capture/instrumentation/SpanAddingClassVisitorFactory.kt

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ abstract class SpanAddingClassVisitorFactory : AsmClassVisitorFactory<SpanAdding
5454
@get:Input
5555
val debug: Property<Boolean>
5656

57+
@get:Input
58+
val proxyOkHttpEventListener: Property<Boolean>
59+
5760
@get:Internal
5861
val tmpDir: Property<File>
5962

0 commit comments

Comments
 (0)