Skip to content

Commit

Permalink
support two modes of okhttp instrumentation via plugin + wire up rele…
Browse files Browse the repository at this point in the history
…ase 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]>
  • Loading branch information
snowp and murki authored Dec 9, 2024
1 parent 64a7ce7 commit 418d77c
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 94 deletions.
38 changes: 33 additions & 5 deletions .github/workflows/integrations_android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ on:
required: true
type: string
jobs:
build-capture-timber:
name: Build Capture Timber
build-gradle-libraries:
name: Build Gradle Libraries
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -31,17 +31,45 @@ jobs:
cache: gradle
- name: Install Rust target
run: rustup update && rustup target add aarch64-linux-android && rustup target add x86_64-linux-android
- name: Build artifacts with Gradle
- name: Build Timber artifacts with Gradle
run: ./gradlew :capture-timber:publish -PVERSION_NAME="${{ inputs.version }}" --info
env:
SKIP_PROTO_GEN: 1
- name: Compress artifacts
- name: Build Apollo artifacts with Gradle
run: ./gradlew :capture-apollo3:publish -PVERSION_NAME="${{ inputs.version }}" --info
env:
SKIP_PROTO_GEN: 1
- name: Build Gradle Plugin artifacts with Gradle
run: ./gradlew :capture-plugin:publish -PVERSION_NAME="${{ inputs.version }}" --info
env:
SKIP_PROTO_GEN: 1
- name: Compress Timber artifacts
run: |
readonly dir=$(pwd)
(cd capture-timber/build/repos/releases/io/bitdrift/capture-timber/${{ inputs.version }} && zip -r "$dir/capture-timber.zip" ./*)
- name: Upload artifacts
- name: Compress Apollo artifacts
run: |
readonly dir=$(pwd)
(cd capture-apollo3/build/repos/releases/io/bitdrift/capture-apollo3/${{ inputs.version }} && zip -r "$dir/capture-apollo3.zip" ./*)
- name: Compress Android Plugin artifacts
run: |
readonly dir=$(pwd)
(cd capture-plugin/build/repos/releases/io/bitdrift/capture-plugin/${{ inputs.version }} && zip -r "$dir/capture-plugin.zip" ./*)
- name: Upload Timber artifacts
uses: actions/upload-artifact@v4
with:
name: capture-timber.zip
path: platform/jvm/capture-timber.zip
if-no-files-found: error
- name: Upload Apollo artifacts
uses: actions/upload-artifact@v4
with:
name: capture-apollo3.zip
path: platform/jvm/capture-apollo3.zip
if-no-files-found: error
- name: Upload Gradle Plugin artifacts
uses: actions/upload-artifact@v4
with:
name: capture-plugin.zip
path: platform/jvm/capture-plugin.zip
if-no-files-found: error
10 changes: 9 additions & 1 deletion .github/workflows/release_gh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: capture-timber.zip
- uses: actions/download-artifact@v4
with:
name: capture-apollo3.zip
- uses: actions/download-artifact@v4
with:
name: capture-plugin.zip
- name: Prepare Android artifacts
run: ./ci/gh_prepare_android_artifacts.sh "$VERSION"
env:
Expand All @@ -223,7 +229,9 @@ jobs:
"Capture-$VERSION.android.zip" \
"example-apps.ios.zip" \
"example-apps.android.zip" \
"capture-timber-$VERSION.android.zip"
"capture-timber-$VERSION.android.zip" \
"capture-apollo3-$VERSION.android.zip" \
"capture-plugin-$VERSION.android.zip"
env:
VERSION: ${{ inputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/release_public.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ jobs:
run: |
gh release download "v$VERSION" -p 'Capture*.android.zip'
gh release download "v$VERSION" -p 'capture-timber*.android.zip'
gh release download "v$VERSION" -p 'capture-plugin*.android.zip'
env:
VERSION: ${{ inputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Android Artifacts to aws bucket
run: ./ci/capture_android_release.sh ${{ inputs.version }} "Capture-${{ inputs.version }}.android.zip" "capture-timber-${{ inputs.version }}.android.zip"
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"

41 changes: 18 additions & 23 deletions ci/capture_android_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ readonly remote_location_root_prefix="s3://bitdrift-public-dl/sdk/android-maven/
readonly version="$1"
readonly capture_archive="$2"
readonly capture_timber_archive="$3"
readonly capture_apollo3_archive="$4"
readonly capture_plugin_archive="$5"

function upload_file() {
local -r location="$1"
Expand Down Expand Up @@ -78,36 +80,29 @@ function release_capture_sdk() {
popd
}

function release_capture_timber() {
function release_gradle_library() {
local -r library_name="$1"
local -r archive="$2"

echo "+++ dl.bitdrift.io Android Capture Timber artifacts upload"

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

pushd "$(mktemp -d)"
unzip -o "$sdk_repo/$capture_timber_archive"

echo "+++ Uploading artifacts to s3 bucket"
unzip -o "$archive"

# Make sure we update the top-level maven-metadata.xml file with the new release version
aws s3 cp maven-metadata.xml* "$remote_location_prefix/" --region us-east-1

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

files=(\
"$sdk_repo/ci/LICENSE.txt" \
"$sdk_repo/ci/NOTICE.txt" \
"$name.pom" \
"$name-javadoc.jar" \
"$name-sources.jar" \
"$name.module" \
"$name.aar" \
)

for file in "${files[@]}"; do
upload_file "$remote_location_prefix/$version" "$file"
done

generate_maven_file "$remote_location_prefix"
aws s3 cp "$version" "$remote_location_prefix/$version/" --recursive --region us-east-1
popd
}

release_capture_sdk
release_capture_timber
release_gradle_library "capture-timber" "$capture_timber_archive"
release_gradle_library "capture-apollo3" "$capture_apollo3_archive"
release_gradle_library "capture-plugin" "$capture_plugin_archive"
32 changes: 10 additions & 22 deletions ci/gh_prepare_android_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,21 @@ function prepare_capture_sdk() {
function prepare_capture_timber() {
echo "+++ Preparing Android Capture Timber library artifacts for '$version' version"

pushd "$(mktemp -d)"
local -r out_artifacts_dir="capture-timber-out"

unzip "$sdk_repo/capture-timber.zip"

mkdir "$out_artifacts_dir"
cp "$sdk_repo/capture-timber.zip" "$sdk_repo/capture-timber-$version.android.zip"
}

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

files=(\
"$name.aar" \
"$name.module" \
"$name.pom" \
"$name-javadoc.jar" \
"$name-sources.jar" \
"$sdk_repo/ci/LICENSE.txt" \
"$sdk_repo/ci/NOTICE.txt" \
)
cp "$sdk_repo/capture-apollo3.zip" "$sdk_repo/capture-apollo4-$version.android.zip"
}

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

(cd "$out_artifacts_dir" && zip -r "$sdk_repo/capture-timber-$version.android.zip" ./*)
popd
cp "$sdk_repo/capture-plugin.zip" "$sdk_repo/capture-plugin-$version.android.zip"
}

prepare_capture_sdk
prepare_capture_timber
prepare_capture_plugin
54 changes: 50 additions & 4 deletions platform/jvm/capture-apollo3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.detekt)

// Publish
alias(libs.plugins.dokka) // Must be applied here for publish plugin.
alias(libs.plugins.maven.publish)
signing

id("dependency-license-config")
}

Expand Down Expand Up @@ -55,9 +60,50 @@ tasks.preBuild {

dependencies {
implementation(project(":capture"))
implementation("com.apollographql.apollo3:apollo-runtime:3.8.3")
implementation(libs.apollo.runtime)

testImplementation(libs.truth)
testImplementation(libs.junit)
testImplementation(libs.kotlin.mockito.kotlin)
}

testImplementation("com.google.truth:truth:1.4.4")
testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") // last version with Java 8 support
mavenPublishing {
pom {
name.set("CaptureApollo")
description.set("Official Capture integration for Apollo v3 (GraphQL).")
url.set("https://bitdrift.io")
licenses {
license {
name.set("BITDRIFT SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT")
url.set("https://dl.bitdrift.io/sdk/android-maven/io/bitdrift/capture-timber/${findProperty("VERSION_NAME")}/LICENSE.txt")
distribution.set("repo")
}
license {
name.set("NOTICE")
url.set("https://dl.bitdrift.io/sdk/android-maven/io/bitdrift/capture-timber/${findProperty("VERSION_NAME")}/NOTICE.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("bitdriftlabs")
name.set("Bitdrift, Inc.")
url.set("https://github.com/bitdriftlabs")
email.set("[email protected]")
}
scm {
connection.set("scm:git:git://github.com/bitdriftlabs/capture-sdk.git")
developerConnection.set("scm:git:ssh://[email protected]:bitdriftlabs/capture-sdk.git")
url.set("https://github.com/bitdriftlabs/capture-sdk")
}
}
}
}

publishing {
repositories {
maven {
url = uri(layout.buildDirectory.dir("repos/releases"))
}
}
}
46 changes: 41 additions & 5 deletions platform/jvm/capture-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
id("java-gradle-plugin")
}

group = "io.bitdrift"

dependencies {
compileOnly("com.android.tools.build:gradle:7.4.0")
compileOnly("org.ow2.asm:asm-commons:9.4")
Expand All @@ -22,17 +24,51 @@ dependencies {
gradlePlugin {
plugins {
create("capturePlugin") {
id = "io.bitdrift.capture.capture-plugin"
id = "io.bitdrift.capture-plugin"
implementationClass = "io.bitdrift.capture.CapturePlugin"
}
}
}

mavenPublishing {
configureBasedOnAppliedPlugins()

pom {
name.set("CapturePlugin")
description.set("Official Capture Gradle plugin.")
url.set("https://bitdrift.io")
licenses {
license {
name.set("BITDRIFT SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT")
url.set("https://dl.bitdrift.io/sdk/android-maven/io/bitdrift/capture-plugin/${findProperty("VERSION_NAME")}/LICENSE.txt")
distribution.set("repo")
}
license {
name.set("NOTICE")
url.set("https://dl.bitdrift.io/sdk/android-maven/io/bitdrift/capture-plugin/${findProperty("VERSION_NAME")}/NOTICE.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("bitdriftlabs")
name.set("Bitdrift, Inc.")
url.set("https://github.com/bitdriftlabs")
email.set("[email protected]")
}
scm {
connection.set("scm:git:git://github.com/bitdriftlabs/capture-sdk.git")
developerConnection.set("scm:git:ssh://[email protected]:bitdriftlabs/capture-sdk.git")
url.set("https://github.com/bitdriftlabs/capture-sdk")
}
}
}
}

publishing {
repositories {
mavenLocal()
maven {
url = uri(layout.buildDirectory.dir("repos/releases"))
}
}
}

group = "io.bitdrift.capture.capture-plugin"
version = "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ fun AndroidComponentsExtension<*, *, *>.configure(
FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS,
) { params ->
params.tmpDir.set(tmpDir)
params.debug.set(false)
params.debug.set(extension.instrumentation.debug)
params.proxyOkHttpEventListener.set(extension.instrumentation.proxyOkHttpEventListener)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ open class InstrumentationExtension @Inject constructor(objects: ObjectFactory)
val debug: Property<Boolean> = objects.property(Boolean::class.java).convention(
false
)

val proxyOkHttpEventListener: Property<Boolean> = objects.property(Boolean::class.java).convention(false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ abstract class SpanAddingClassVisitorFactory : AsmClassVisitorFactory<SpanAdding
@get:Input
val debug: Property<Boolean>

@get:Input
val proxyOkHttpEventListener: Property<Boolean>

@get:Internal
val tmpDir: Property<File>

Expand Down
Loading

0 comments on commit 418d77c

Please sign in to comment.