---
kind: pipeline
name: default

clone:
    git:
        image: plugins/git
        recursive: true

steps:
  - name: Initilizing submodules
    image: alpine/git
    commands:
        # Fetching submodules
        - git submodule init
        - git submodule update --init --recursive

  # - name: Build dev.apps.ad5001.eu
  #   image: xdevbase/hugo-builder:latest
  #   commands:
  #       - hugo --config ci/dev.config.yml --minify
  #   when:
  #       event: [push, tag]
  #       branch: [master]
  # 
  # - name: Remove old dev.apps.ad5001.eu
  #   image: appleboy/drone-ssh
  #   settings:
  #       host:
  #           from_secret: SSH_HOST
  #       username:
  #           from_secret: SSH_USERNAME
  #       password:
  #           from_secret: SSH_PASSWORD
  #       envs:
  #           - DEV_WWW_PATH
  #       script:
  #           - export DEV_WWW_PATH=$DEV_WWW_PATH
  #           - cd "$DEV_WWW_PATH"
  #           - rm -rf *
  #   when:
  #       event: [push, tag]
  #       branch: [master]
  # 
  # - name: Deploy dev.apps.ad5001.eu
  #   image: appleboy/drone-scp
  #   settings:
  #       host:
  #           from_secret: SSH_HOST
  #       username:
  #           from_secret: SSH_USERNAME
  #       password:
  #           from_secret: SSH_PASSWORD
  #       target:
  #           from_secret: DEV_WWW_PATH
  #       source: public/*
  #   when:
  #       event: [push, tag]
  #       branch: [master]

  - name: Build apps.ad5001.eu
    image: xdevbase/hugo-builder
    commands:
        - hugo --minify
    when:
        event: [push, tag]
        branch: [master]

  - name: Remove old apps.ad5001.eu
    image: appleboy/drone-ssh
    environment:
        PROD_WWW_PATH:
            from_secret: PROD_WWW_PATH
    settings:
        host:
            from_secret: SSH_HOST
        username:
            from_secret: SSH_USERNAME
        password:
            from_secret: SSH_PASSWORD
        port:
            from_secret: SSH_PORT
        envs:
            - PROD_WWW_PATH
        script:
            - export PROD_WWW_PATH=$PROD_WWW_PATH
            - cd "$PROD_WWW_PATH"
            - rm -rf *
    when:
        event: [push, tag]
        branch: [master]

  - name: Deploy apps.ad5001.eu
    image: appleboy/drone-scp
    settings:
        host:
            from_secret: SSH_HOST
        username:
            from_secret: SSH_USERNAME
        password:
            from_secret: SSH_PASSWORD
        port:
            from_secret: SSH_PORT
        target:
            from_secret: PROD_WWW_PATH
        source: public/*
    when:
        event: [push, tag]
        branch: [master]
