---
kind: pipeline
type: docker
name: default
when:               # Only run the pipeline when it's a push to master
  event: [push]

workspace:
# path: /src

steps:
  - name: versioncheck
    image: klakegg/hugo:latest-ext
    commands:
      - hugo version

  - name: build-draft
    image: klakegg/hugo:latest-ext
    commands:
      - hugo -D -E -F -b https://draft.donharper.org/
    when:
      branch: [draft]

  - name: rsync-draft
    image: drillster/drone-rsync
    settings:
      hosts:
        from_secret: deploy_draft
      port:
        from_secret: deploy_port
      target:
        from_secret: deploy_target
      key:
        from_secret: deploy_key
      user:
        from_secret: deploy_user
      password:
        from_secret: deploy_secret
      source: ./public/*
      recursive: true
      delete: true
      script:
        - chmod -R a+rX www
        - cd docker
        - doas docker-compose stop www.donharper.org
        - doas docker-compose up -d www.donharper.org
      secrets: [deploy_key]
    when:
      branch: [draft]

  - name: build-prod
    image: klakegg/hugo:latest-ext
    commands:
      - hugo
    when:
      branch: [main]

  - name: rsync-prod
    image: drillster/drone-rsync
    settings:
      hosts:
        from_secret: deploy_host
      port:
        from_secret: deploy_port
      target:
        from_secret: deploy_target
      key:
        from_secret: deploy_key
      user:
        from_secret: deploy_user
      password:
        from_secret: deploy_secret
      source: ./public/*
      recursive: true
      delete: true
      script:
        - chmod -R a+rX www
        - cd docker
        - doas docker-compose stop www.donharper.org
        - doas docker-compose up -d www.donharper.org
      secrets: [deploy_key]
    when:
      branch: [main]
