name: Build

on:
    push:
        branches:
            - "*"
        paths-ignore:
            - ".gitignore"
    pull_request:
        branches:
            - "*"
        paths-ignore:
            - ".gitignore"
    workflow_dispatch:
permissions: write-all
jobs:
    build:
        runs-on: ubuntu-latest
        name: "Build and test"
        steps:
            -   uses: actions/checkout@v3
            -   name: Set up JDK 21
                uses: actions/setup-java@v3
                with:
                    java-version: 21
                    distribution: temurin
                    cache: gradle
            -   name: Setup gradle
                uses: gradle/gradle-build-action@v2
            -   name: Build with Gradle
                run: ./gradlew assemble -x test --stacktrace
            -   uses: actions/upload-artifact@v3
                name: Upload development build
                with:
                    name: "Development Build"
                    path: build/libs/*.jar
            -   name: Test with Gradle
                run: ./gradlew test
            -   uses: actions/upload-artifact@v3
                name: "Upload test report"
                if: ${{ !cancelled() }}
                with:
                    name: "Test Results"
                    path: versions/1.8.9/build/reports/tests/test/
    preprocess:
        runs-on: ubuntu-latest
        name: "Build multi version"
        steps:
            -   uses: actions/checkout@v3
            -   name: Set up JDK 21
                uses: actions/setup-java@v3
                with:
                    java-version: 21
                    distribution: temurin
                    cache: gradle
            -   name: Setup gradle
                uses: gradle/gradle-build-action@v2
            -   name: Enable preprocessor
                run: |
                    mkdir -p .gradle
                    echo skyhanni.multi-version=preprocess-only > .gradle/private.properties
            -   name: Build with Gradle
                run: ./gradlew build --stacktrace
