image: eclipse-temurin:21.0.1_12-jdk-ubi9-minimal

definitions:
   caches:
      game-server: /opt/atlassian/pipelines/agent/build/l2j-server-game
pipelines:
   branches:
      develop:
      -  step:
            caches:
            - maven
            - game-server
            script:
            - microdnf update -y
            - microdnf install -y git
            - |
               if [ -d "l2j-server-game" ]; then
                 echo "Directory exists, pulling changes..."
                 cd l2j-server-game
                 git pull
               else
                 echo "Directory does not exist, cloning repository..."
                 git clone --depth=1 https://bitbucket.org/l2jserver/l2j-server-game.git
                 cd l2j-server-game
               fi
            - /bin/sh mvnw clean install -DskipTests -Ddependency-check.skip=true
            - cd ..
      -  step:
            caches:
            - maven
            - game-server
            script:
            - /bin/sh mvnw clean install
            artifacts:
            - target/*.zip
      -  step:
            deployment: Production
            script:
            -  pipe: atlassian/ftp-deploy:0.6.0
               variables:
                  USER: $FTP_USER
                  PASSWORD: $FTP_PASSWORD
                  SERVER: $FTP_HOST
                  REMOTE_PATH: $FTP_REMOTE_PATH
                  LOCAL_PATH: target/