image: php:8.2-cli

pipelines:
  default:
    - step:
        name: Lint + testes (PHPUnit)
        caches:
          - composer
        script:
          - apt-get update -qq && apt-get install -y -qq unzip libsqlite3-dev libonig-dev libcurl4-openssl-dev >/dev/null
          - docker-php-ext-install -j$(nproc) mbstring curl >/dev/null
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer install --no-interaction --no-progress --prefer-dist
          - find src bin -name '*.php' -print0 | xargs -0 -n1 php -l
          - php -l webhook.php && php -l link_discord.php && php -l index.php
          - vendor/bin/phpunit --colors=never

  branches:
    main:
      - step:
          name: Lint + testes (PHPUnit)
          caches:
            - composer
          script:
            - apt-get update -qq && apt-get install -y -qq unzip libsqlite3-dev libonig-dev libcurl4-openssl-dev >/dev/null
            - docker-php-ext-install -j$(nproc) mbstring curl >/dev/null
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer install --no-interaction --no-progress --prefer-dist
            - find src bin -name '*.php' -print0 | xargs -0 -n1 php -l          
            - php -l webhook.php && php -l link_discord.php && php -l index.php
            - vendor/bin/phpunit --colors=never

      - step:
          name: Deploy para vertiads (rsync via SSH)
          deployment: production
          caches:
            - composer
          script:
            - apt-get update -qq && apt-get install -y -qq unzip rsync openssh-client >/dev/null
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer install --no-interaction --no-progress --prefer-dist --no-dev --optimize-autoloader
            - >
              rsync -avz --delete
              -e "ssh -p ${SSH_PORT:-22}"
              --exclude='.git*'
              --exclude='tests'
              --exclude='phpunit.xml'
              --exclude='.env'
              --exclude='storage/'
              ./ ${SSH_USER}@${SSH_HOST}:${DEPLOY_PATH}

definitions:
  caches:
    composer: ~/.composer/cache
