Эх сурвалжийг харах

Merge pull request #10113 from nextcloud/chore/unit-tests-gh-actions

Run unit tests in GH actions
Álvaro Brey 3 жил өмнө
parent
commit
23dd1f30f1

+ 1 - 6
.drone.yml

@@ -20,17 +20,12 @@ steps:
       - scripts/checkIfRunDrone.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST || exit 0
       - emulator -avd android -no-snapshot -gpu swiftshader_indirect -no-window -no-audio -skin 500x833 &
       - sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g app/src/main/res/values/setup.xml
-      - sed -i s"#server#server#" gradle.properties
-      - ./gradlew assembleGplay
-      - ./gradlew assembleGplayDebug
+      - ./gradlew assembleGplayDebugAndroidTest
       - scripts/wait_for_emulator.sh
-      - scripts/deleteOldComments.sh "stable" "Unit" $DRONE_PULL_REQUEST $GIT_TOKEN
-      - ./gradlew jacocoTestGplayDebugUnitTestReport || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "stable" "Unit" $DRONE_PULL_REQUEST $GIT_TOKEN
       - ./gradlew installGplayDebugAndroidTest
       - scripts/wait_for_server.sh "server"
       - scripts/deleteOldComments.sh "stable" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN
       - ./gradlew createGplayDebugCoverageReport -Pcoverage -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "stable" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN
-      - ./gradlew combinedTestReport
 
 services:
   - name: server

+ 41 - 0
.github/workflows/unit-tests.yml

@@ -0,0 +1,41 @@
+name: Unit tests
+
+on:
+    pull_request:
+        branches: [ master, stable-* ]
+    push:
+        branches: [ master, stable-* ]
+
+jobs:
+    test:
+        runs-on: ubuntu-latest
+        steps:
+            -   uses: actions/checkout@v3
+            -   name: Set up JDK 11
+                uses: actions/setup-java@v3
+                with:
+                    distribution: "temurin"
+                    java-version: 11
+            -   name: Delete old comments
+                if: ${{ always() }}
+                run: scripts/deleteOldComments.sh "test" "Unit" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }}
+            -   name: Run unit tests with coverage
+                uses: gradle/gradle-build-action@v2
+                with:
+                    arguments: jacocoTestGplayDebugUnitTest
+            -   name: Upload failing results
+                if: ${{ failure() }}
+                run:
+                    scripts/uploadReport.sh "${{ secrets.LOG_USERNAME }}" "${{ secrets.LOG_PASSWORD }}" ${{github.event.number}} "test" "Unit" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }}
+            -   name: Upload coverage to codecov
+                uses: codecov/codecov-action@v2
+                with:
+                    token: ${{ secrets.CODECOV_TOKEN }}
+                    flags: unit
+                    fail_ci_if_error: true
+            -   name: Upload jacoco artifacts
+                if: ${{ failure() }}
+                uses: actions/upload-artifact@v3
+                with:
+                    name: test-results
+                    path: app/build/reports/tests/testGplayDebugUnitTest/

+ 0 - 18
app/build.gradle

@@ -387,24 +387,6 @@ android.applicationVariants.all { variant ->
     }
 }
 
-tasks.register("combinedTestReport", JacocoReport) {
-
-    jacocoClasspath = configurations['jacocoAnt']
-
-    reports {
-        xml.enabled true
-        html.enabled true
-        csv.enabled false
-    }
-
-    additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
-    sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
-    classDirectories.setFrom files(subprojects.sourceSets.main.output)
-    executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
-        'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
-    ])
-}
-
 task installGitHooks(type: Copy, group: "development") {
     description = "Install git hooks"
     from("${project.rootDir}/scripts/hooks") {

+ 3 - 14
scripts/runCombinedTest.sh

@@ -7,35 +7,24 @@ LOG_USERNAME=$4
 LOG_PASSWORD=$5
 DRONE_BUILD_NUMBER=$6
 
-scripts/deleteOldComments.sh "master" "Unit" $DRONE_PULL_REQUEST $GIT_TOKEN
 scripts/deleteOldComments.sh "master" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN
 
-./gradlew assembleGplay
-./gradlew assembleGplayDebug
+./gradlew assembleGplayDebugAndroidTest
 
 scripts/wait_for_emulator.sh
-./gradlew jacocoTestGplayDebugUnitTestReport 
-stat=$?
-
-if [ ! $stat -eq 0 ]; then
-    bash scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "master" "Unit" $DRONE_PULL_REQUEST $GIT_TOKEN
-fi
 
 ./gradlew installGplayDebugAndroidTest
 scripts/wait_for_server.sh "server"
 ./gradlew createGplayDebugCoverageReport -Pcoverage -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest
-stat=$(( stat | $? ))
+stat=$?
 
 if [ ! $stat -eq 0 ]; then
     bash scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "master" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN
 fi
 
-./gradlew combinedTestReport
-stat=$(( stat | $? ))
-
 curl -Os https://uploader.codecov.io/latest/linux/codecov
 chmod +x codecov
-./codecov -t fc506ba4-33c3-43e4-a760-aada38c24fd5
+./codecov -t fc506ba4-33c3-43e4-a760-aada38c24fd5 -F integration
 
 echo "Exit with: " $stat
 exit $stat