kind: pipeline
type: docker
name: bogazici-api

trigger:
  branch:
    - develop
    - test
    - main

steps:
  - name: laravel-check
    image: php:8.4-cli
    when:
      branch:
        - develop
    commands:
      - apt-get update && apt-get install -y git unzip curl libzip-dev libicu-dev default-mysql-client
      - docker-php-ext-install pdo_mysql zip intl
      - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
      - cp .env.example .env || true
      - composer install --no-interaction --prefer-dist --optimize-autoloader
      - php artisan key:generate --force || true
      - php artisan optimize:clear || true
      - php artisan test || true

  - name: deploy-test
    image: appleboy/drone-ssh
    when:
      branch:
        - test
    settings:
      host:
        from_secret: SERVER_HOST
      username:
        from_secret: SERVER_USER
      key:
        from_secret: SERVER_SSH_KEY
      port: 22
      script:
        - cd /opt/projects/bogazici/corporate-api/test/api
        - bash scripts/deploy-test.sh

  - name: deploy-prod
    image: appleboy/drone-ssh
    when:
      branch:
        - main
    settings:
      host:
        from_secret: SERVER_HOST
      username:
        from_secret: SERVER_USER
      key:
        from_secret: SERVER_SSH_KEY
      port: 22
      script:
        - cd /opt/projects/bogazici/corporate-api/prod/api
        - bash scripts/deploy-prod.sh
