name: Java CI with Gradle

on: [push, pull_request, workflow_dispatch]

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'temurin'
      - name: Validate Gradle wrapper
        uses: gradle/wrapper-validation-action@v1
      - uses: actions/cache@v2
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
          restore-keys: ${{ runner.os }}-gradle-
      - name: Build with Gradle
        run: ./gradlew build
        env:
          GPR_USER: ${{ secrets.GPR_USER }}
          GPR_KEY: ${{ secrets.GPR_KEY }}
      - name: Archive artifacts
        uses: actions/upload-artifact@v3
        with:
          name: BuildCraft
          path: build/libs/*.jar
      - name: Archive artifacts
        uses: actions/upload-artifact@v3
        with:
          name: BuildCraft (modular)
          path: modules/*.jar
