Skip to content

Commit

Permalink
chore: test android workflow (#619)
Browse files Browse the repository at this point in the history
* chore: test android workflow

Signed-off-by: Mark Phelps <[email protected]>

* chore: try workflow dispatch event

Signed-off-by: Mark Phelps <[email protected]>

* chore: seperate notify job

Signed-off-by: Mark Phelps <[email protected]>

* chore: try once more sigh

Signed-off-by: Mark Phelps <[email protected]>

* chore: omg workflows

Signed-off-by: Mark Phelps <[email protected]>

* chore: try to trigger workflow again

Signed-off-by: Mark Phelps <[email protected]>

* chore: use headref for trigger

Signed-off-by: Mark Phelps <[email protected]>

* chore: try to use caller_run_id instead

Signed-off-by: Mark Phelps <[email protected]>

* chore: omg inputs

Signed-off-by: Mark Phelps <[email protected]>

* chore: already decompressed

Signed-off-by: Mark Phelps <[email protected]>

* chore: omg

Signed-off-by: Mark Phelps <[email protected]>

* chore: tree should be there

Signed-off-by: Mark Phelps <[email protected]>

* chore: try to boot emu

Signed-off-by: Mark Phelps <[email protected]>

* chore: mkdirs

Signed-off-by: Mark Phelps <[email protected]>

* chore: mkdir

Signed-off-by: Mark Phelps <[email protected]>

* chore: fix relative paths

Signed-off-by: Mark Phelps <[email protected]>

* update the gh action for android

Signed-off-by: Roman Dmytrenko <[email protected]>

* wait a bit

Signed-off-by: Roman Dmytrenko <[email protected]>

* try android-emulator-runner

Signed-off-by: Roman Dmytrenko <[email protected]>

* checking the env variables

Signed-off-by: Roman Dmytrenko <[email protected]>

* chore: clear space

Signed-off-by: Mark Phelps <[email protected]>

* chore: add healthcheck to ensure we can access Flipt server

Signed-off-by: Mark Phelps <[email protected]>

* chore: hopefully enable http

Signed-off-by: Mark Phelps <[email protected]>

* chore: once more try to get tests to run

Signed-off-by: Mark Phelps <[email protected]>

* chore: connectedAndroidTests

Signed-off-by: Mark Phelps <[email protected]>

* chore: try dns

Signed-off-by: Mark Phelps <[email protected]>

* fix(kotlin): remove type from authentication strategy serialization

* chore(kotlin): try to fix json serialization options for auth

* chore: log options

Signed-off-by: Mark Phelps <[email protected]>

* change auth strategy implementation

Signed-off-by: Roman Dmytrenko <[email protected]>

* cleanup

* chore: configure auth when testing Flipt Android IT

Signed-off-by: Mark Phelps <[email protected]>

* chore: upload artifacts v4

Signed-off-by: Mark Phelps <[email protected]>

---------

Signed-off-by: Mark Phelps <[email protected]>
Signed-off-by: Roman Dmytrenko <[email protected]>
Co-authored-by: Roman Dmytrenko <[email protected]>
  • Loading branch information
markphelps and erka authored Jan 16, 2025
1 parent 2b1546d commit 869ceaa
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 99 deletions.
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 }}"}}'
129 changes: 66 additions & 63 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 @@ -12,7 +14,17 @@ jobs:
test:
name: Integration Tests
runs-on: ubuntu-latest
timeout-minutes: 10
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: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Checkout Sources
uses: actions/checkout@v4

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

- name: Set up JDK 17
uses: actions/setup-java@v4
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 +46,65 @@ 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&
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: Install System Image
# run: |
# echo "Installing system image..."
# sdkmanager "system-images;android-33;google_apis;x86_64"

# - 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: 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"
FLIPT_AUTHENTICATION_REQUIRED: true
FLIPT_AUTHENTICATION_METHODS_TOKEN_ENABLED: true
FLIPT_AUTHENTICATION_METHODS_TOKEN_BOOTSTRAP_TOKEN: "secret"
run: flipt&

- name: Wait for Flipt to be ready
run: |
while ! curl -s http://0.0.0.0:8080/health | grep -q "SERVING"; do
echo "Waiting for Flipt to be ready..."
sleep 1
done
- 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

# - name: Stop Emulator
# if: always()
# run: |
# echo "Stopping emulator..."
# adb emu kill
- name: (Fail-only) Upload the build reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-reports
path: ./flipt-client-kotlin-android/build/reports
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
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application android:networkSecurityConfig="@xml/network_security_config" />
</manifest>
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)
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()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
4 changes: 1 addition & 3 deletions flipt-client-kotlin-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />


</manifest>
</manifest>
54 changes: 54 additions & 0 deletions flipt-client-kotlin-android/src/main/cpp/include/flipt_engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

/**
* # Safety
*
* This function will initialize an Engine and return a pointer back to the caller.
*/
void *initialize_engine(const char *namespace_, const char *opts);

/**
* # Safety
*
* This function will take in a pointer to the engine and return a variant evaluation response.
*/
const char *evaluate_variant(void *engine_ptr, const char *evaluation_request);

/**
* # Safety
*
* This function will take in a pointer to the engine and return a boolean evaluation response.
*/
const char *evaluate_boolean(void *engine_ptr, const char *evaluation_request);

/**
* # Safety
*
* This function will take in a pointer to the engine and return a batch evaluation response.
*/
const char *evaluate_batch(void *engine_ptr, const char *batch_evaluation_request);

/**
* # Safety
*
* This function will take in a pointer to the engine and return a list of flags for the given namespace.
*/
const char *list_flags(void *engine_ptr);

/**
* # Safety
*
* This function will free the memory occupied by the engine.
*/
void destroy_engine(void *engine_ptr);

/**
* # Safety
*
* This function will take in a pointer to the string and free the memory.
* See Rust the safety section in CString::from_raw.
*/
void destroy_string(char *ptr);
Loading

0 comments on commit 869ceaa

Please sign in to comment.