Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test android workflow #619

Merged
merged 36 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
070e8f8
chore: test android workflow
markphelps Jan 4, 2025
8d10a86
chore: try workflow dispatch event
markphelps Jan 4, 2025
e637c7d
chore: seperate notify job
markphelps Jan 4, 2025
e0944a8
chore: try once more sigh
markphelps Jan 4, 2025
2f2877f
chore: omg workflows
markphelps Jan 4, 2025
7e9b05d
chore: try to trigger workflow again
markphelps Jan 4, 2025
0e323c3
chore: use headref for trigger
markphelps Jan 4, 2025
af1792a
chore: try to use caller_run_id instead
markphelps Jan 4, 2025
9e522be
chore: omg inputs
markphelps Jan 4, 2025
779279d
chore: already decompressed
markphelps Jan 4, 2025
d2dec30
chore: omg
markphelps Jan 4, 2025
22a15ec
chore: tree should be there
markphelps Jan 4, 2025
1180e04
chore: try to boot emu
markphelps Jan 4, 2025
9867206
chore: mkdirs
markphelps Jan 4, 2025
3b089c2
chore: mkdir
markphelps Jan 4, 2025
93c6497
chore: fix relative paths
markphelps Jan 5, 2025
d2b6d41
update the gh action for android
erka Jan 5, 2025
6a54fce
wait a bit
erka Jan 5, 2025
bc2b4f6
try android-emulator-runner
erka Jan 8, 2025
e072cf5
checking the env variables
erka Jan 8, 2025
4ff07f2
Merge branch 'main' into android-sdk-tests
markphelps Jan 8, 2025
ac4e226
chore: clear space
markphelps Jan 11, 2025
09b6655
chore: add healthcheck to ensure we can access Flipt server
markphelps Jan 11, 2025
802122b
chore: hopefully enable http
markphelps Jan 11, 2025
0778858
chore: once more try to get tests to run
markphelps Jan 11, 2025
45fe620
chore: connectedAndroidTests
markphelps Jan 11, 2025
968e515
chore: try dns
markphelps Jan 12, 2025
dd090e4
fix(kotlin): remove type from authentication strategy serialization
markphelps Jan 14, 2025
5237a9a
Merge branch 'main' into android-sdk-tests
markphelps Jan 14, 2025
a3ac2c3
chore(kotlin): try to fix json serialization options for auth
markphelps Jan 15, 2025
66e7b19
Merge branch 'android-sdk-tests' of https://github.com/flipt-io/flipt…
markphelps Jan 15, 2025
f8ae712
chore: log options
markphelps Jan 15, 2025
a7f246f
change auth strategy implementation
erka Jan 15, 2025
f28d41e
cleanup
erka Jan 15, 2025
06ea3cc
chore: configure auth when testing Flipt Android IT
markphelps Jan 16, 2025
4cdbc1b
chore: upload artifacts v4
markphelps Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/workflows/package-ffi-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
key: ${{ runner.os }}-${{ matrix.platform.target}}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Set RUSTFLAGS
if: endsWith(matrix.platform.target, '-musl')
if: endsWith(matrix.platform.target, '-musl') || endsWith(matrix.platform.target, '-android')
run: |
echo "RUSTFLAGS=-C target-feature=-crt-static" >> $GITHUB_ENV

Expand Down Expand Up @@ -159,3 +159,22 @@ jobs:
tag_name: flipt-engine-ffi-${{ github.event.inputs.tag }}
files: |
flipt-engine-ffi-${{ matrix.platform.name }}${{ startsWith(matrix.platform.name, 'Windows') && '.zip' || '.tar.gz' }}

notify:
runs-on: ubuntu-latest
needs: build
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.FLIPT_RELEASE_BOT_APP_ID }}
private_key: ${{ secrets.FLIPT_RELEASE_BOT_APP_PEM }}
installation_id: ${{ secrets.FLIPT_RELEASE_BOT_INSTALLATION_ID }}

- name: Trigger Test Android SDK
run: |
curl -X POST -H "Authorization: Bearer ${{ steps.generate_token.outputs.token }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/flipt-io/flipt-client-sdks/actions/workflows/test-android-sdk.yml/dispatches \
-d '{"ref":"${{ github.head_ref }}", "inputs":{"caller_run_id":"${{ github.run_id }}"}}'
109 changes: 45 additions & 64 deletions .github/workflows/test-android-sdk.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Test Android SDK
on:
workflow_run:
workflows: ["Package FFI Engine"]
types: [completed]
workflow_dispatch:
inputs:
caller_run_id:
type: string
required: true

permissions:
contents: write
Expand All @@ -13,6 +15,11 @@ jobs:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Checkout Sources
uses: actions/checkout@v4

Expand All @@ -21,21 +28,6 @@ jobs:
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin"

- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
api-level: 33
target: default
arch: x86_64
profile: default
emulator-build: stable

- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
Expand All @@ -49,59 +41,48 @@ jobs:
with:
github-token: ${{ steps.generate_token.outputs.token }}
name: flipt-engine-ffi-Android-x86_64.tar.gz
path: flipt-engine-ffi-Android-x86_64.tar.gz
path: /tmp
run-id: ${{ inputs.caller_run_id }}

- name: Download Artifact (arm64)
uses: actions/download-artifact@v4
with:
github-token: ${{ steps.generate_token.outputs.token }}
name: flipt-engine-ffi-Android-arm64.tar.gz
path: flipt-engine-ffi-Android-arm64.tar.gz
path: /tmp
run-id: ${{ inputs.caller_run_id }}

- name: Extract Artifacts
run: |
tar -xzvf flipt-engine-ffi-Android-x86_64.tar.gz -C ./flipt-engine-ffi-Android-x86_64
tar -xzvf flipt-engine-ffi-Android-arm64.tar.gz -C ./flipt-engine-ffi-Android-arm64
ls -la ./flipt-engine-ffi-Android-x86_64
ls -la ./flipt-engine-ffi-Android-arm64

# - name: Run flipt
# env:
# FLIPT_STORAGE_TYPE: "local"
# FLIPT_STORAGE_LOCAL_PATH: "./test/fixtures/testdata"
# run: flipt&

# - name: Install System Image
# run: |
# echo "Installing system image..."
# sdkmanager "system-images;android-33;google_apis;x86_64"
mkdir -p /tmp/flipt-engine-ffi-Android-x86_64
mkdir -p /tmp/flipt-engine-ffi-Android-arm64
tar -xzvf /tmp/flipt-engine-ffi-Android-x86_64.tar.gz -C /tmp/flipt-engine-ffi-Android-x86_64
tar -xzvf /tmp/flipt-engine-ffi-Android-arm64.tar.gz -C /tmp/flipt-engine-ffi-Android-arm64

# - name: Create Emulator
# run: |
# echo "Creating emulator..."
# echo "no" | avdmanager create avd -n test -k "system-images;android-33;google_apis;x86_64" --device "pixel"

# - name: Start Emulator
# run: |
# echo "Starting emulator..."
# $ANDROID_HOME/emulator/emulator -avd test -no-audio -no-boot-anim -no-window -gpu swiftshader_indirect &

# - name: Wait for Emulator to Boot
# run: |
# echo "Waiting for emulator to boot..."
# adb wait-for-device
# adb shell getprop init.svc.bootanim | grep -m 1 stopped

# - name: Run Integration Tests
# env:
# FLIPT_URL: "http://0.0.0.0:8080"
# FLIPT_AUTH_TOKEN: "secret"
# run: |
# cd ./flipt-client-kotlin-android
# ./gradlew connectedAndroidTest

# - name: Stop Emulator
# if: always()
# run: |
# echo "Stopping emulator..."
# adb emu kill
- name: Move Artifacts
run: |
mkdir -p flipt-client-kotlin-android/src/main/cpp/libs/x86_64
mkdir -p flipt-client-kotlin-android/src/main/cpp/libs/arm64-v8a
mkdir -p flipt-client-kotlin-android/src/main/cpp/include
mv /tmp/flipt-engine-ffi-Android-x86_64/target/x86_64-linux-android/release/libfliptengine.a flipt-client-kotlin-android/src/main/cpp/libs/x86_64/
mv /tmp/flipt-engine-ffi-Android-arm64/target/aarch64-linux-android/release/libfliptengine.a flipt-client-kotlin-android/src/main/cpp/libs/arm64-v8a/
cp -r flipt-engine-ffi/include/* flipt-client-kotlin-android/src/main/cpp/include

- name: Run flipt
env:
FLIPT_STORAGE_TYPE: "local"
FLIPT_STORAGE_LOCAL_PATH: "./test/fixtures/testdata"
run: flipt&

- name: Run Integration Tests
uses: reactivecircus/android-emulator-runner@v2
env:
FLIPT_URL: "http://10.0.2.2:8080"
FLIPT_AUTH_TOKEN: "secret"
with:
api-level: 33
target: default
arch: x86_64
script: ./gradlew connectedAndroidTest
working-directory: ./flipt-client-kotlin-android
emulator-options: -no-window -no-snapshot -screen no-touch -noaudio -no-boot-anim -camera-back none
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ Cargo.lock
tmp
.envrc
.vscode
staging
*.h
staging
13 changes: 6 additions & 7 deletions flipt-client-kotlin-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ android {
ndk {
abiFilters "x86_64", "arm64-v8a"
}
def fliptUrl = System.getenv("FLIPT_URL") ?: ""
def fliptAuthToken = System.getenv("FLIPT_AUTH_TOKEN") ?: ""
buildConfigField("String", "FLIPT_URL", "\"$fliptUrl\"")
buildConfigField("String", "FLIPT_AUTH_TOKEN", "\"$fliptAuthToken\"")
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField("String", "FLIPT_URL", "\"${System.getenv("FLIPT_URL") ?: ""}\"")
buildConfigField("String", "FLIPT_AUTH_TOKEN", "\"${System.getenv("FLIPT_AUTH_TOKEN") ?: ""}\"")
}
debug {
buildConfigField("String", "FLIPT_URL", "\"${System.getenv("FLIPT_URL") ?: ""}\"")
buildConfigField("String", "FLIPT_AUTH_TOKEN", "\"${System.getenv("FLIPT_AUTH_TOKEN") ?: ""}\"")
}
}
compileOptions {
Expand All @@ -38,6 +36,7 @@ android {

kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += '-opt-in=kotlin.RequiresOptIn'
}

externalNativeBuild {
Expand All @@ -53,4 +52,4 @@ dependencies {
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.junit.After
import org.junit.Before
import org.junit.Test


class TestFliptEvaluationClient {
private var fliptClient: FliptEvaluationClient? = null

Expand All @@ -15,14 +14,16 @@ class TestFliptEvaluationClient {
fun initAll() {
val fliptURL = BuildConfig.FLIPT_URL
val clientToken = BuildConfig.FLIPT_AUTH_TOKEN

assert("http://10.0.2.2:8080" == fliptURL)
erka marked this conversation as resolved.
Show resolved Hide resolved
assert(!fliptURL.isEmpty())
assert(!clientToken.isEmpty())
fliptClient = FliptEvaluationClient.builder()
.url(url = fliptURL)
.namespace("default")
.authentication(ClientTokenAuthentication(clientToken))
.build()
fliptClient =
FliptEvaluationClient
.builder()
.url(url = fliptURL)
.namespace("default")
.authentication(ClientTokenAuthentication(clientToken))
.build()
}

@Test
Expand All @@ -31,7 +32,7 @@ class TestFliptEvaluationClient {
val context: MutableMap<String, String> = HashMap()
context["fizz"] = "buzz"

val response = fliptClient?.evaluateVariant("flag1", "entity", context)
val response = fliptClient?.evaluateVariant("flag1", "entity", context)

assert("flag1" == response?.flagKey)
assert(response?.match ?: false)
Expand Down Expand Up @@ -59,19 +60,20 @@ class TestFliptEvaluationClient {
val context: MutableMap<String, String> = HashMap()
context["fizz"] = "buzz"

val evalRequests: Array<EvaluationRequest> = arrayOf(
EvaluationRequest("flag1", "entity", context),
EvaluationRequest("flag_boolean", "entity", context),
EvaluationRequest("notfound", "entity", context)
)
val evalRequests: Array<EvaluationRequest> =
arrayOf(
EvaluationRequest("flag1", "entity", context),
EvaluationRequest("flag_boolean", "entity", context),
EvaluationRequest("notfound", "entity", context),
)

val response = fliptClient?.evaluateBatch(evalRequests)

assert(3 == response?.responses?.size)
val responses = response?.responses

assert(responses?.get(0)?.variantEvaluationResponse != null)
val variantResponse = responses?.get(0)?.variantEvaluationResponse
val variantResponse = responses?.get(0)?.variantEvaluationResponse
assert("flag1" == variantResponse?.flagKey)
assert(variantResponse?.match ?: false)
assert("MATCH_EVALUATION_REASON" == variantResponse?.reason)
Expand Down Expand Up @@ -103,5 +105,4 @@ class TestFliptEvaluationClient {
fun tearDownAll() {
fliptClient?.close()
}

}
Loading