# SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Unit tests

on:
    pull_request:
        branches: [ master, main, stable-* ]
    push:
        branches: [ master, main, stable-* ]

permissions:
    contents: read
    pull-requests: write

concurrency:
    group: unit-tests-${{ github.head_ref || github.run_id }}
    cancel-in-progress: true

jobs:
    test:
        runs-on: ubuntu-latest
        steps:
            -   name: Checkout
                uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
                with:
                    persist-credentials: false

            -   name: Set up JDK 17
                uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
                with:
                    distribution: "temurin"
                    java-version: 17

            -   name: Setup Gradle
                uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0

            -   name: Run unit tests with coverage
                run: ./gradlew --no-daemon testGplayDebugUnit

            -   name: Upload test artifacts
                if: ${{ failure() }}
                uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
                with:
                    name: test-results
                    path: app/build/reports/tests/testGplayDebugUnitTest/
