name: Linux x86-64

on: [ push, pull_request ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      # download jdk
      - run: wget -q -O $RUNNER_TEMP/java_package.tar.gz https://cache-redirector.jetbrains.com/intellij-jbr/jbrsdk-21.0.7-linux-x64-b1034.51.tar.gz

      # appimagetool
      - run: sudo apt install libfuse2

      # install jdk
      - name: Installing Java
        uses: actions/setup-java@v4
        with:
          distribution: 'jdkfile'
          jdkFile: ${{ runner.temp }}/java_package.tar.gz
          java-version: '21.0.7'
          architecture: x64

      - uses: actions/cache@v4
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-${{ runner.arch }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
          restore-keys: |
            ${{ runner.os }}-${{ runner.arch }}-gradle-

      # test build
      - run: |
          ./gradlew classes -x test --no-daemon
          ./gradlew clean --no-daemon

      # dist
      - run: |
          ./gradlew dist --no-daemon

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: termora-linux-x86-64
          path: |
            build/distributions/*.tar.gz
            build/distributions/*.AppImage
