From 5e88dbd7a1796e1a6ac7c5d5b3980744f5b27fff Mon Sep 17 00:00:00 2001 From: Crsi <47722349+CrsiX@users.noreply.github.com> Date: Wed, 8 Mar 2023 15:39:32 +0100 Subject: [PATCH] Extended CI with various extra tests, added Java 17 support in unit tests (fixes #8835) (#8839) * Added a pure build stage with various versions * Added build artifacts from GitHub CI * Upgrade mocking and testing libraries * Extended GitHub CI test stages, added Windows tests * Fixed job name * Split some jobs for increased speed due to better parallelism --- .github/workflows/buildAndDeploy.yml | 2 +- .github/workflows/buildAndTest.yml | 136 +++++++++++++++++++++++++++ build.gradle.kts | 14 +-- 3 files changed, 144 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/buildAndTest.yml diff --git a/.github/workflows/buildAndDeploy.yml b/.github/workflows/buildAndDeploy.yml index 9ad391c071..a4393003c3 100644 --- a/.github/workflows/buildAndDeploy.yml +++ b/.github/workflows/buildAndDeploy.yml @@ -36,7 +36,7 @@ jobs: java-version: '11' - name: Setup Gradle - uses: gradle/gradle-build-action@v2.3.3 + uses: gradle/gradle-build-action@v2.4.0 - name: Compile kotlin and build classes run: ./gradlew classes diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml new file mode 100644 index 0000000000..82036d3c1b --- /dev/null +++ b/.github/workflows/buildAndTest.yml @@ -0,0 +1,136 @@ +# Jobs to test the code base and build the client and server app +name: Build and test + +on: + # Triggers the workflow on any push or pull request + push: + pull_request: + +jobs: + + # Job to execute code checks and unit tests on the project source + code-checks: + name: Check code and run unit tests (Java ${{ matrix.java_version }}) + strategy: + matrix: + java_version: + - 11 + - 17 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-java@v3 + with: + cache: 'gradle' + distribution: 'temurin' + java-version: ${{ matrix.java_version }} + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2.4.0 + + - name: Compile kotlin and build classes + run: ./gradlew classes + + - name: Run code checks + run: ./gradlew check + + - name: Run unit tests + run: ./gradlew --no-build-cache cleanTest test tests:test + + # Job to build the android files on a Ubuntu host + build-android: + strategy: + matrix: + java_version: + - 11 + - 17 + runs-on: ubuntu-latest + name: Build Android (Java ${{ matrix.java_version }}) + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-java@v3 + with: + cache: 'gradle' + distribution: 'temurin' + java-version: ${{ matrix.java_version }} + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2.4.0 + + - name: Build Android debug and release files + run: | + mkdir whatsNewDirectory + echo "Nothing changed so far" > whatsNewDirectory/whatsnew-en-US + set -x + ./gradlew :android:bundleDebug + ./gradlew :android:assembleDebug + ./gradlew :android:bundleRelease + ./gradlew :android:assembleRelease + + - name: Upload Android artifacts + uses: actions/upload-artifact@v3 + with: + name: Android (built with Java ${{ matrix.java_version }}) + path: | + android/build/outputs/apk/*/*.apk + android/build/outputs/bundle/*/*.aab + retention-days: 1 + continue-on-error: true + + # Job to build the desktop and server JAR files on all available platforms + build-desktop: + defaults: + run: + # Ensures that a UNIX-like shell is available (default would be Powershell on Windows) + shell: sh + name: Build Desktop for ${{ matrix.os }} (Java ${{ matrix.java_version }}) + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + java_version: + - 11 + - 17 + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-java@v3 + with: + cache: 'gradle' + distribution: 'temurin' + java-version: ${{ matrix.java_version }} + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2.4.0 + + - name: Build the Desktop app + run: ./gradlew desktop:dist + + - name: Build the Java server + run: ./gradlew server:dist + + - name: Upload Desktop artifacts + uses: actions/upload-artifact@v3 + with: + name: Desktop (built with Java ${{ matrix.java_version }}) + path: desktop/build/libs/*.jar + retention-days: 1 + # Only run this step on ubuntu-latest, since Java is cross-platform anyways + if: ${{ matrix.os == 'ubuntu-latest' }} + continue-on-error: true + + - name: Upload Java server artifacts + uses: actions/upload-artifact@v3 + with: + name: Server (built with Java ${{ matrix.java_version }}) + path: server/build/libs/*.jar + retention-days: 1 + # Only run this step on ubuntu-latest, since Java is cross-platform anyways + if: ${{ matrix.os == 'ubuntu-latest' }} + continue-on-error: true diff --git a/build.gradle.kts b/build.gradle.kts index 075d6cc6c7..3649a46733 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -89,7 +89,7 @@ project(":android") { dependencies { "implementation"(project(":core")) "implementation"("com.badlogicgames.gdx:gdx-backend-android:$gdxVersion") - "implementation"("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1") + "implementation"("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") natives("com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a") natives("com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a") natives("com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86") @@ -116,7 +116,7 @@ project(":core") { dependencies { "implementation"("com.badlogicgames.gdx:gdx:$gdxVersion") - "implementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1") + "implementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") "implementation"("org.jetbrains.kotlin:kotlin-reflect:${com.unciv.build.BuildConfig.kotlinVersion}") } @@ -129,18 +129,18 @@ project(":core") { dependencies { "implementation"(project(":core")) - "implementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1") + "implementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") - "implementation"("junit:junit:4.13.1") - "implementation"("org.mockito:mockito-all:1.10.19") + "implementation"("junit:junit:4.13.2") + "implementation"("org.mockito:mockito-core:5.1.1") "implementation"("com.badlogicgames.gdx:gdx-backend-lwjgl3:${gdxVersion}") "implementation"("com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop") "implementation"("com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion") "implementation"("com.badlogicgames.gdx:gdx:$gdxVersion") - "testImplementation"("junit:junit:4.13.1") - "testImplementation"("org.mockito:mockito-all:1.10.19") + "testImplementation"("junit:junit:4.13.2") + "testImplementation"("org.mockito:mockito-core:5.1.1") "testImplementation"("io.mockk:mockk:1.9.3") "testImplementation"("com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion")