
trigger:
  branches:
    include:
    - none
stages:
- stage: __default
  jobs:
  - job: Job
    pool:
      vmImage: ubuntu-latest
    steps:
    - task: SSH@0
      inputs:
        sshEndpoint: 'HomecutNew'
        runOptions: 'inline'
        inline: |
          cd $(PATH)
              
                    # Turn on maintenance mode
                    php artisan down 
                    
                    # Add ssh key 
                    eval `ssh-agent -s`
                    ssh-add ~/.ssh/mm_rsa
                    
                    # Pull the latest changes 
                    git fetch --all
                    git reset --hard
                    git checkout $(BRANCH)
                    git pull
                                        
                    # Install/update 
                    composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev 
                    
                    # Set Production Environment on server
                    sed -i 's/#server_env_key$/SetEnv APP_ENV "prod"/' public/.htaccess
                    cat /public/.htaccess

                    # Clear caches
                    php artisan cache:clear && php artisan config:clear && php artisan route:clear && php artisan config:cache && composer dump-autoload
                          
                    # Turn off maintenance mode
                    php artisan up
          
                    echo "tag version"
          
                    NOW=`date '+%d.%m.%y-%H.%M.%S'`;
                    git tag -a "v$NOW" -m "$NOW"
                    git push origin --tags
        failOnStdErr: false
        readyTimeout: '20000'
