# .woodpecker.yaml
steps:
  # Шаг 1: Сборка ассетов темы
  - name: build-assets
    image: node:20-alpine
    commands:
      - cd wp-content/themes/xkater
      - if [ -f package.json ]; then npm ci && npm run build; fi
    when:
      branch: main

  # Шаг 2: Деплой на боевой сервер
  - name: deploy-production
    image: drillster/drone-rsync
    settings:
      user: ${PROD_SSH_USER}
      host:
        - ${PROD_SSH_HOST}
      port: 22
      key: ${PROD_SSH_KEY}
      source: ./wp-content/
      target: ${REMOTE_PATH}/wp-content/
      recursive: true
      delete: false
      args: >
        --exclude=uploads/
        --exclude=plugins/akismet/
        --exclude=plugins/index.php
        --exclude=.git/
        --exclude=node_modules/
        --exclude=.DS_Store
        --exclude=mu-plugins/local-dev-performance.php
    when:
      branch: main

  # Шаг 3: Очистка кэша на сервере
  - name: flush-cache
    image: appleboy/drone-ssh
    settings:
      host: ${PROD_SSH_HOST}
      username: ${PROD_SSH_USER}
      key: ${PROD_SSH_KEY}
      script:
        - cd ${REMOTE_PATH}
        - if command -v wp &> /dev/null; then wp cache flush; fi
        - touch wp-config.php
    when:
      branch: main
      # Убрали status - он не нужен для этого шага
