# .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
    secrets:
      - source: prod_ssh_user
        target: RSYNC_USER
      - source: prod_ssh_host
        target: RSYNC_HOSTS
      - source: prod_ssh_key
        target: RSYNC_KEY
      - source: remote_path
        target: REMOTE_PATH
    settings:
      port: 22
      source: ./wp-content/
      recursive: true
      delete: false
      args: '--exclude=uploads/ --exclude=plugins/akismet/ --exclude=.git/ --exclude=node_modules/ --exclude=.DS_Store'
    when:
      branch: main

  # Шаг 3: Очистка кэша
  - name: flush-cache
    image: appleboy/drone-ssh
    secrets:
      - source: prod_ssh_host
        target: SSH_HOST
      - source: prod_ssh_user
        target: SSH_USERNAME
      - source: prod_ssh_key
        target: SSH_KEY
      - source: remote_path
        target: REMOTE_PATH
    settings:
      script:
        - cd $REMOTE_PATH
        - if command -v wp > /dev/null 2>&1; then wp cache flush; fi
        - touch wp-config.php
    when:
      branch: main
