name: Eagler Build System

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
        - name: Checkout
          uses: actions/checkout@v2
        - name: 'Setup Python'
          uses: actions/setup-python@v2
          with:
            python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
            architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
        - name: 'Run Optimization'
          run: |
            pip install -r resources/requirements.txt
            python resources/optimize.py     
        - name: 'Setup Java'
          uses: actions/setup-java@v4
          with:
            distribution: 'temurin'
            java-version: '21'
        - name: 'Compile EPK'
          run: 'java -jar "resources/CompileEPK.jar" "resources/optimizedResources" "javascript/assets.epk"'
        - name: 'Compile Javascript'
          run: /usr/bin/env sh ./gradlew generateJavascript --no-daemon
        - name: 'Make Offline Download'
          run: 'java -cp "resources/MakeOfflineDownload.jar:resources/CompileEPK.jar" net.lax1dude.eaglercraft.v1_8.buildtools.workspace.MakeOfflineDownload "javascript/OfflineDownloadTemplate.txt" "javascript/classes.js" "javascript/assets.epk" "javascript/EaglercraftL_1.9_Offline_en_US.html" "javascript/EaglercraftX_1.8_Offline_International.html" "javascript/lang"'
        - name: 'Zip Web Files'
          run: 'zip web.zip javascript/classes.js javascript/assets.epk javascript/index.html'
        - name: 'Output Offline Download'
          uses: actions/upload-artifact@v3
          with:
            name: lambda
            path: |
              javascript/EaglercraftL_1.9_Offline_en_US.html
              web.zip