Add github action workflow (#1016)
* Add build steps for github action * Fix build commands * Checkout submodule recursively and don't fail fast * Fix mention view model tests * Upload test result when failed * Temporarily disable variants * Fix tests * Fix tests * Fix tests * Fix tests * Remove deprecated properties * Fixes up artifact uploading * Fixes tests * Fixes tests * Huawei artifact matching and gradle caching * PR triggerpull/1712/head
parent
e95fa6cc03
commit
9575db64fd
@ -0,0 +1,63 @@
|
|||||||
|
name: Build and test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "dev", "master" ]
|
||||||
|
pull_request:
|
||||||
|
types: [synchronize]
|
||||||
|
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false # Continue with other matrix items if one fails
|
||||||
|
matrix:
|
||||||
|
variant: [ 'play', 'website', 'huawei' ]
|
||||||
|
build_type: [ 'debug' ]
|
||||||
|
include:
|
||||||
|
- variant: 'huawei'
|
||||||
|
extra_build_command_options: '-Phuawei=1'
|
||||||
|
steps:
|
||||||
|
- name: Cache Gradle
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.gradle/caches
|
||||||
|
.gradle
|
||||||
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'gradle.properties') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-gradle-
|
||||||
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: 'recursive'
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '17'
|
||||||
|
|
||||||
|
- name: Build and test with Gradle
|
||||||
|
id: build
|
||||||
|
run: ./gradlew assemble${{ matrix.variant }}${{ matrix.build_type }} test${{ matrix.variant }}${{ matrix.build_type }}UnitTest ${{ matrix.extra_build_command_options }}
|
||||||
|
|
||||||
|
- name: Upload build reports regardless
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: build-reports-${{ matrix.variant }}-${{ matrix.build_type }}
|
||||||
|
path: app/build/reports
|
||||||
|
if-no-files-found: ignore
|
||||||
|
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: session-${{ matrix.variant }}-${{ matrix.build_type }}
|
||||||
|
path: app/build/outputs/apk/${{ matrix.variant }}/${{ matrix.build_type }}/*-universal*apk
|
||||||
|
if-no-files-found: error
|
||||||
|
compression-level: 0
|
@ -1,15 +1,11 @@
|
|||||||
package org.thoughtcrime.securesms
|
package org.thoughtcrime.securesms
|
||||||
|
|
||||||
import kotlinx.coroutines.test.TestCoroutineScope
|
import kotlinx.coroutines.test.TestScope
|
||||||
import kotlinx.coroutines.test.runBlockingTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Rule
|
|
||||||
|
|
||||||
open class BaseCoroutineTest {
|
open class BaseCoroutineTest {
|
||||||
|
|
||||||
@get:Rule
|
protected fun runBlockingTest(test: suspend TestScope.() -> Unit) = runTest {
|
||||||
var coroutinesTestRule = CoroutineTestRule()
|
test()
|
||||||
|
}
|
||||||
protected fun runBlockingTest(test: suspend TestCoroutineScope.() -> Unit) =
|
|
||||||
coroutinesTestRule.runBlockingTest { test() }
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,50 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms
|
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.test.TestCoroutineScope
|
|
||||||
import kotlinx.coroutines.test.resetMain
|
|
||||||
import kotlinx.coroutines.test.setMain
|
|
||||||
import org.junit.rules.TestWatcher
|
|
||||||
import org.junit.runner.Description
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the main coroutines dispatcher to a [TestCoroutineScope] for unit testing. A
|
|
||||||
* [TestCoroutineScope] provides control over the execution of coroutines.
|
|
||||||
*
|
|
||||||
* Declare it as a JUnit Rule:
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* @get:Rule
|
|
||||||
* var coroutineTestRule = CoroutineTestRule()
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* Use it directly as a [TestCoroutineScope]:
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* coroutineTestRule.pauseDispatcher()
|
|
||||||
* ...
|
|
||||||
* coroutineTestRule.resumeDispatcher()
|
|
||||||
* ...
|
|
||||||
* coroutineTestRule.runBlockingTest { }
|
|
||||||
* ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
class CoroutineTestRule(
|
|
||||||
val dispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()
|
|
||||||
) : TestWatcher(), TestCoroutineScope by TestCoroutineScope(dispatcher) {
|
|
||||||
|
|
||||||
override fun starting(description: Description?) {
|
|
||||||
super.starting(description)
|
|
||||||
Dispatchers.setMain(dispatcher)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun finished(description: Description?) {
|
|
||||||
super.finished(description)
|
|
||||||
cleanupTestCoroutines()
|
|
||||||
Dispatchers.resetMain()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue