From d50c5f97ab9e50e63bc01593fc6568b7e14946fe Mon Sep 17 00:00:00 2001 From: Jean-Michel Fayard Date: Tue, 15 Sep 2020 18:26:31 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8F=97=20Setup=20a=20GitHub=20Action?= =?UTF-8?q?=20using=20Gradle=20to=20run=20the=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/fake-google-services.json | 40 +++++++++++++++++++ .github/workflows/android-unittests.yml | 24 +++++++++++ .../view/main/view/MainActivityTest.kt | 3 ++ build.gradle.kts | 13 ++++++ settings.gradle.kts | 10 +++++ 5 files changed, 90 insertions(+) create mode 100644 .github/fake-google-services.json create mode 100644 .github/workflows/android-unittests.yml diff --git a/.github/fake-google-services.json b/.github/fake-google-services.json new file mode 100644 index 0000000..b0d249d --- /dev/null +++ b/.github/fake-google-services.json @@ -0,0 +1,40 @@ +{ + "project_info": { + "project_number": "1092521184945", + "firebase_url": "https://dev-personal-XXX.firebaseio.com", + "project_id": "dev-personal-XXX", + "storage_bucket": "dev-personal-XXX.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:1092521184945:android:af137629aab59de5af1c90", + "android_client_info": { + "package_name": "to.dev.dev_android.debug" + } + }, + "oauth_client": [ + { + "client_id": "XX.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "XXX" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "XXX.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/.github/workflows/android-unittests.yml b/.github/workflows/android-unittests.yml new file mode 100644 index 0000000..38a5a3a --- /dev/null +++ b/.github/workflows/android-unittests.yml @@ -0,0 +1,24 @@ +# .github/workflows/android.yml +# https://github.com/marketplace/actions/gradle-command +name: Android unit tests + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] +jobs: + gradle: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Copy fake google-services.json + run: cp -f .github/fake-google-services.json app/google-services.json + - uses: actions/setup-java@v1 + with: + java-version: 8 + - uses: eskatos/gradle-command-action@v1 + with: + arguments: githubAction diff --git a/app/src/test/java/to/dev/dev_android/view/main/view/MainActivityTest.kt b/app/src/test/java/to/dev/dev_android/view/main/view/MainActivityTest.kt index 7912322..301eab5 100644 --- a/app/src/test/java/to/dev/dev_android/view/main/view/MainActivityTest.kt +++ b/app/src/test/java/to/dev/dev_android/view/main/view/MainActivityTest.kt @@ -8,6 +8,9 @@ class MainActivityTest { @Test fun onCreate() { + val sum = 5 + assertTrue(2+2 == sum) + } @Test diff --git a/build.gradle.kts b/build.gradle.kts index 1855aac..da98302 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -78,3 +78,16 @@ detekt { tasks.named("wrapper") { distributionType = Wrapper.DistributionType.ALL } + +tasks.register("githubAction") { + // tasks to run before ./githubAction + dependsOn(":app:testDebugUnitTest") + group = "custom" + description = """ + GitHub Action is configured in + ./github/workflows/android.yml + to run on each commit + $ ./gradlew githubAction + This task will run the unit tests + """".trimIndent() +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 15a801b..e168e27 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,11 @@ +plugins { + id("com.gradle.enterprise").version("3.1.1") +} +gradleEnterprise { + buildScan { + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" + } +} + include(":app") From b964e1078158c1b7ba8c4719367d8fa6d89f759c Mon Sep 17 00:00:00 2001 From: Jean-Michel Fayard Date: Tue, 15 Sep 2020 18:36:37 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8F=97=20Setup=20a=20GitHub=20Action?= =?UTF-8?q?=20using=20Gradle=20to=20run=20the=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit enable build scan for better test failures reporting https://scans.gradle.com/s/2tzis4ikslecg/tests --- .github/workflows/android-unittests.yml | 4 ++-- .../to/dev/dev_android/view/main/view/MainActivityTest.kt | 8 ++++++-- settings.gradle.kts | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/android-unittests.yml b/.github/workflows/android-unittests.yml index 38a5a3a..ebc737a 100644 --- a/.github/workflows/android-unittests.yml +++ b/.github/workflows/android-unittests.yml @@ -6,9 +6,9 @@ name: Android unit tests # events but only for the master branch on: push: - branches: [ master ] + branches: [ master, main ] pull_request: - branches: [ master ] + branches: [ master, main ] jobs: gradle: runs-on: ubuntu-latest diff --git a/app/src/test/java/to/dev/dev_android/view/main/view/MainActivityTest.kt b/app/src/test/java/to/dev/dev_android/view/main/view/MainActivityTest.kt index 301eab5..89b778c 100644 --- a/app/src/test/java/to/dev/dev_android/view/main/view/MainActivityTest.kt +++ b/app/src/test/java/to/dev/dev_android/view/main/view/MainActivityTest.kt @@ -6,10 +6,14 @@ import org.junit.Assert.* class MainActivityTest { + @Test + fun `2 plus 2 equals 4`() { + assertEquals(2+2, 4) + } + @Test fun onCreate() { - val sum = 5 - assertTrue(2+2 == sum) + } diff --git a/settings.gradle.kts b/settings.gradle.kts index e168e27..247fe5d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,10 +1,12 @@ plugins { id("com.gradle.enterprise").version("3.1.1") } + gradleEnterprise { buildScan { termsOfServiceUrl = "https://gradle.com/terms-of-service" termsOfServiceAgree = "yes" + publishOnFailure() } } From 48a62d90490c5f958668e266d5c44013ac21873d Mon Sep 17 00:00:00 2001 From: Jean-Michel Fayard Date: Tue, 15 Sep 2020 20:30:15 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=8F=97=20Setup=20a=20GitHub=20Action?= =?UTF-8?q?=20using=20Gradle=20to=20run=20the=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{android-unittests.yml => runOnGitHub.yml} | 11 +++++++---- build.gradle.kts | 12 +++--------- 2 files changed, 10 insertions(+), 13 deletions(-) rename .github/workflows/{android-unittests.yml => runOnGitHub.yml} (67%) diff --git a/.github/workflows/android-unittests.yml b/.github/workflows/runOnGitHub.yml similarity index 67% rename from .github/workflows/android-unittests.yml rename to .github/workflows/runOnGitHub.yml index ebc737a..854210f 100644 --- a/.github/workflows/android-unittests.yml +++ b/.github/workflows/runOnGitHub.yml @@ -1,6 +1,9 @@ -# .github/workflows/android.yml -# https://github.com/marketplace/actions/gradle-command -name: Android unit tests +# .github/workflows/runOnGitHub.yml +# GitHub Actions documentation +# => https://docs.github.com/en/actions +# Execute Gradle commands in GitHub Actions workflows +# => https://github.com/marketplace/actions/gradle-command +name: runOnGitHub # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch @@ -21,4 +24,4 @@ jobs: java-version: 8 - uses: eskatos/gradle-command-action@v1 with: - arguments: githubAction + arguments: runOnGitHub diff --git a/build.gradle.kts b/build.gradle.kts index da98302..6bfae41 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -79,15 +79,9 @@ tasks.named("wrapper") { distributionType = Wrapper.DistributionType.ALL } -tasks.register("githubAction") { - // tasks to run before ./githubAction +tasks.register("runOnGitHub") { + // Documentation: https://guides.gradle.org/writing-gradle-tasks/ dependsOn(":app:testDebugUnitTest") group = "custom" - description = """ - GitHub Action is configured in - ./github/workflows/android.yml - to run on each commit - $ ./gradlew githubAction - This task will run the unit tests - """".trimIndent() + description = "$ ./gradlew runOnGitHub # runs on GitHub Action" } \ No newline at end of file From 9adeba0d167d0d1f74748e90a54e5afdc4670536 Mon Sep 17 00:00:00 2001 From: Jean-Michel Fayard Date: Tue, 15 Sep 2020 21:03:15 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8F=97=20GitHub=20Action:=20use=20cac?= =?UTF-8?q?he?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/runOnGitHub.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/runOnGitHub.yml b/.github/workflows/runOnGitHub.yml index 854210f..5ce3205 100644 --- a/.github/workflows/runOnGitHub.yml +++ b/.github/workflows/runOnGitHub.yml @@ -1,8 +1,6 @@ # .github/workflows/runOnGitHub.yml # GitHub Actions documentation # => https://docs.github.com/en/actions -# Execute Gradle commands in GitHub Actions workflows -# => https://github.com/marketplace/actions/gradle-command name: runOnGitHub # Controls when the action will run. Triggers the workflow on push or pull request @@ -22,6 +20,12 @@ jobs: - uses: actions/setup-java@v1 with: java-version: 8 + + # Execute Gradle commands in GitHub Actions workflows + # => https://github.com/marketplace/actions/gradle-command - uses: eskatos/gradle-command-action@v1 with: arguments: runOnGitHub + wrapper-cache-enabled: true + dependencies-cache-enabled: true + configuration-cache-enabled: true