variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false"

cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches

stages:
  - build

build_mod:
  stage: build
  script:
    - |
      declare -a versions=("1.20.1" "1.20.2" "1.20.3" "1.20.4" "1.20.5" "1.20.6")
      declare -a mappings=("1.20.1+build.10" "1.20.2+build.4" "1.20.3+build.1" "1.20.4+build.3" "1.20.5+build.1" "1.20.6+build.1")
      declare -a fabric_versions=("0.92.1+1.20.1" "0.91.6+1.20.2" "0.91.1+1.20.3" "0.97.0+1.20.4" "0.97.8+1.20.5" "0.97.8+1.20.6")

      for i in "${!versions[@]}"; do
        minecraft_version="${versions[$i]}"
        yarn_mappings="${mappings[$i]}"
        fabric_version="${fabric_versions[$i]}"

        echo "Building for Minecraft Version $minecraft_version with Fabric $fabric_version"
        sed -i "s/minecraft_version=.*/minecraft_version=$minecraft_version/" gradle.properties
        sed -i "s/yarn_mappings=.*/yarn_mappings=$yarn_mappings/" gradle.properties
        sed -i "s/loader_version=.*/loader_version=0.15.11/" gradle.properties
        sed -i "s/fabric_version=.*/fabric_version=$fabric_version/" gradle.properties

        ./gradlew build
        find build/libs -type f -name '*sources*.jar' -exec rm {} \;
        mv build/libs/creaturechat-*.jar .

        FABRIC_API_JAR="fabric-api-${fabric_version}.jar"
        DOWNLOAD_URL="https://github.com/FabricMC/fabric/releases/download/${fabric_version//+/%2B}/${FABRIC_API_JAR}"
        wget -q -O "${FABRIC_API_JAR}" $DOWNLOAD_URL
        ls . -la
      done
  artifacts:
    paths:
      - creaturechat-*.jar
      - fabric-api-*.jar
  only:
    - multi-version-build-pipeline
  tags:
    - minecraft
