Skip to content

Commit 43a6501

Browse files
authored
setup github actions (#52)
* Create android.yml * add synk * update synk * fix synk failure * add download dependencies and remove snyk for now * rename yml file * test snyk * Update build.yml * Update build.yml * fix flaky test * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * add snyk plugin * Update build.yml * Update build.yml * Update build.yml * fix snyk reported vulnerable library * omit snyk reported vulnerable library error * attempt to fix flaky test * adjust order * attempt to fix flaky test * attempt to fix flaky test * split jobs * attemt to fix flaky test * Revert "attemt to fix flaky test" This reverts commit 5d07077 * split jobs * Delete .circleci directory * update libraries version * fix flaky test * add cache * update job name * split jobs * use memory shared preference * address comment
1 parent 9b6540e commit 43a6501

File tree

11 files changed

+152
-92
lines changed

11 files changed

+152
-92
lines changed

.circleci/config.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Android CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
core-test:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Grant execute permission for gradlew
18+
run: chmod +x gradlew
19+
- name: cache gradle dependencies
20+
uses: actions/cache@v2
21+
with:
22+
path: |
23+
~/.gradle/caches
24+
~/.gradle/wrapper
25+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
26+
restore-keys: |
27+
${{ runner.os }}-gradle-
28+
- name: Run Tests
29+
run: ./gradlew core:test
30+
31+
android-test:
32+
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- uses: actions/checkout@v2
37+
- name: Grant execute permission for gradlew
38+
run: chmod +x gradlew
39+
- name: cache gradle dependencies
40+
uses: actions/cache@v2
41+
with:
42+
path: |
43+
~/.gradle/caches
44+
~/.gradle/wrapper
45+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
46+
restore-keys: |
47+
${{ runner.os }}-gradle-
48+
- name: Run Tests
49+
run: ./gradlew android:test
50+
51+
destination-test:
52+
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- uses: actions/checkout@v2
57+
- name: Grant execute permission for gradlew
58+
run: chmod +x gradlew
59+
- name: cache gradle dependencies
60+
uses: actions/cache@v2
61+
with:
62+
path: |
63+
~/.gradle/caches
64+
~/.gradle/wrapper
65+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
66+
restore-keys: |
67+
${{ runner.os }}-gradle-
68+
- name: Run Tests
69+
run: ./gradlew samples:kotlin-android-app-destinations:test
70+
71+
security:
72+
73+
runs-on: ubuntu-latest
74+
75+
steps:
76+
- uses: actions/checkout@v2
77+
- name: Grant execute permission for gradlew
78+
run: chmod +x gradlew
79+
- name: Snyk
80+
run: ./gradlew snyk-test
81+
env:
82+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

android/build.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ dependencies {
4747
// MAIN DEPS
4848
api project(':core')
4949
api 'com.github.segmentio:sovran-kotlin:1.1.0'
50-
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1"
51-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
52-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
50+
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
51+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
52+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
5353
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
5454
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
5555

@@ -58,23 +58,23 @@ dependencies {
5858
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
5959

6060
// TESTING
61-
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'
61+
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
6262
testImplementation 'io.mockk:mockk:1.10.6'
6363
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
64-
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
65-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
64+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
65+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
6666

6767
// Add JUnit5 dependencies.
68-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
69-
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0'
68+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
69+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.2'
7070

7171
// Add JUnit4 legacy dependencies.
7272
testImplementation 'junit:junit:4.13.2'
73-
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.0'
73+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.2'
7474

7575
// Add Roboelectric dependencies.
7676
testImplementation 'org.robolectric:robolectric:4.5'
77-
testImplementation 'androidx.test:core:1.3.0'
77+
testImplementation 'androidx.test:core:1.4.0'
7878
}
7979

8080
apply from: rootProject.file('gradle/jitpack-android.gradle')

android/src/test/java/com/segment/analytics/kotlin/android/AndroidContextCollectorTests.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.segment.analytics.kotlin.android
22

33
import android.content.Context
4+
import android.content.SharedPreferences
45
import androidx.test.platform.app.InstrumentationRegistry
56
import com.segment.analytics.kotlin.core.*
67
import com.segment.analytics.kotlin.android.plugins.AndroidContextPlugin
8+
import com.segment.analytics.kotlin.android.utils.MemorySharedPreferences
9+
import io.mockk.every
10+
import io.mockk.spyk
711
import kotlinx.serialization.json.*
812
import org.junit.Assert.*
913
import org.junit.Test
@@ -16,14 +20,22 @@ import java.util.*
1620
@Config(manifest = Config.NONE)
1721
class AndroidContextCollectorTests {
1822

19-
val appContext: Context = InstrumentationRegistry.getInstrumentation().targetContext
20-
val analytics = Analytics(
21-
Configuration(
22-
writeKey = "123",
23-
application = appContext,
24-
storageProvider = AndroidStorageProvider
23+
val appContext: Context
24+
val analytics: Analytics
25+
26+
init {
27+
appContext = spyk(InstrumentationRegistry.getInstrumentation().targetContext)
28+
val sharedPreferences: SharedPreferences = MemorySharedPreferences()
29+
every { appContext.getSharedPreferences(any(), any()) } returns sharedPreferences
30+
31+
analytics = Analytics(
32+
Configuration(
33+
writeKey = "123",
34+
application = appContext,
35+
storageProvider = AndroidStorageProvider
36+
)
2537
)
26-
)
38+
}
2739

2840
@Test
2941
fun `context fields applied correctly`() {

android/src/test/java/com/segment/analytics/kotlin/android/AndroidLifecyclePluginTests.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import com.segment.analytics.kotlin.android.plugins.AndroidLifecycle
1414
import com.segment.analytics.kotlin.android.plugins.AndroidLifecyclePlugin
1515
import com.segment.analytics.kotlin.android.utils.mockHTTPClient
1616
import io.mockk.*
17+
import kotlinx.coroutines.delay
18+
import kotlinx.coroutines.runBlocking
1719
import kotlinx.serialization.json.buildJsonObject
1820
import kotlinx.serialization.json.put
1921
import org.junit.Assert.*
@@ -119,7 +121,7 @@ class AndroidLifecyclePluginTests {
119121
}
120122

121123
@Test
122-
fun `application opened is tracked`() {
124+
fun `application opened is tracked`() = runBlocking{
123125
analytics.configuration.trackApplicationLifecycleEvents = true
124126
analytics.configuration.trackDeepLinks = false
125127
analytics.configuration.useLifecycleObserver = false
@@ -132,7 +134,9 @@ class AndroidLifecyclePluginTests {
132134

133135
// Simulate activity startup
134136
lifecyclePlugin.onActivityCreated(mockActivity, mockBundle)
137+
delay(500)
135138
lifecyclePlugin.onActivityStarted(mockActivity)
139+
delay(500)
136140
lifecyclePlugin.onActivityResumed(mockActivity)
137141

138142
verify (timeout = 2000){ mockPlugin.updateState(true) }

build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.5.30"
3+
ext.kotlin_version = "1.5.31"
44
ext.writeKey = "hAh3QxoRCsQsnyabTLMpWbpxoIN4O2mU"
55
repositories {
66
google()
@@ -22,6 +22,10 @@ buildscript {
2222
}
2323
}
2424

25+
plugins {
26+
id "io.snyk.gradle.plugin.snykplugin" version "0.4"
27+
}
28+
2529
allprojects {
2630
repositories {
2731
google()
@@ -33,6 +37,13 @@ allprojects {
3337
}
3438
}
3539

40+
snyk {
41+
// severity = 'high'
42+
autoDownload = true
43+
autoUpdate = true
44+
arguments = '--all-sub-projects --fail-on=upgradable'
45+
}
46+
3647
task clean(type: Delete) {
3748
delete rootProject.buildDir
3849
}

core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ dependencies {
1717
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
1818
// MAIN DEPS
1919
api 'com.github.segmentio:sovran-kotlin:1.1.0'
20-
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1"
21-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
20+
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
21+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
2222

2323
// TESTING
2424
repositories { mavenCentral() }

samples/java-android-app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ android {
3333
dependencies {
3434
implementation project(':android')
3535

36-
implementation 'androidx.appcompat:appcompat:1.2.0'
37-
implementation 'com.google.android.material:material:1.3.0'
38-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
39-
testImplementation 'junit:junit:4.+'
40-
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
41-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
36+
implementation 'androidx.appcompat:appcompat:1.3.1'
37+
implementation 'com.google.android.material:material:1.4.0'
38+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
39+
testImplementation 'junit:junit:4.13.2'
40+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
41+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
4242
}

samples/kotlin-android-app-destinations/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ dependencies {
8383

8484
// Test Dependencies
8585
dependencies {
86-
testImplementation 'junit:junit:4.+'
87-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
88-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
86+
testImplementation 'junit:junit:4.13.2'
87+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
88+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
8989
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
9090

9191
testImplementation 'io.mockk:mockk:1.10.6'
@@ -94,13 +94,13 @@ dependencies {
9494

9595
// Add Roboelectric dependencies.
9696
testImplementation 'org.robolectric:robolectric:4.5'
97-
testImplementation 'androidx.test:core:1.3.0'
97+
testImplementation 'androidx.test:core:1.4.0'
9898

9999
// Add JUnit4 legacy dependencies.
100100
testImplementation 'junit:junit:4.13.2'
101-
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.0'
101+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.2'
102102

103103
// For JSON Object testing
104-
testImplementation 'org.json:json:20180813'
104+
testImplementation 'org.json:json:20200518'
105105
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
106106
}

samples/kotlin-android-app/build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ dependencies {
4242

4343
implementation 'androidx.multidex:multidex:2.0.1'
4444

45-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
46-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
45+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
46+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
4747

4848
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
49-
implementation 'androidx.core:core-ktx:1.3.2'
50-
implementation 'androidx.appcompat:appcompat:1.2.0'
51-
implementation 'com.google.android.material:material:1.3.0'
52-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
49+
implementation 'androidx.core:core-ktx:1.6.0'
50+
implementation 'androidx.appcompat:appcompat:1.3.1'
51+
implementation 'com.google.android.material:material:1.4.0'
52+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
5353

5454
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
5555
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
@@ -60,7 +60,7 @@ dependencies {
6060
implementation 'com.google.firebase:firebase-analytics-ktx'
6161
implementation 'com.google.firebase:firebase-messaging:19.0.0'
6262

63-
testImplementation 'junit:junit:4.+'
64-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
65-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
63+
testImplementation 'junit:junit:4.13.2'
64+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
65+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
6666
}

0 commit comments

Comments
 (0)