# 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:
            -   uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
            -   name: Set up JDK 17
                uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
                with:
                    distribution: "temurin"
                    java-version: 17
            -   name: Setup Gradle
                uses: gradle/actions/setup-gradle@94baf225fe0a508e581a564467443d0e2379123b # v4.3.0
            -   name: Run unit tests with coverage
                run: ./gradlew testGplayDebugUnit
            -   name: Upload test artifacts
                if: ${{ failure() }}
                uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
                with:
                    name: test-results
                    path: app/build/reports/tests/testGplayDebugUnitTest/
