kind: pipeline
type: docker
name: test

steps:
  # Step 1: build project
  - name: build
    image: node:18-alpine
    commands:
      - rm -rf node_modules
      - npm ci
      - npm run build

  # Step 2: prepare server
  - name: clear-server-cache
    image: appleboy/drone-ssh
    settings:
      host:
        from_secret: server_host
      username:
        from_secret: server_username
      password:
        from_secret: server_password
      port: 22
      script:
        - rm -rf /www/wwwroot/doc.zguiy.com/*
        - mkdir -p /www/wwwroot/doc.zguiy.com/
        - chmod 755 /www/wwwroot/doc.zguiy.com/
    when:
      branch:
        - main
        - master
        - dev

  # Step 3: upload build to server
  - name: upload-build
    image: appleboy/drone-scp
    settings:
      host:
        from_secret: server_host
      username:
        from_secret: server_username
      password:
        from_secret: server_password
      port: 22
      source: dist/*
      target: /www/wwwroot/doc.zguiy.com/
      strip_components: 1
    when:
      branch:
        - main
        - master
        - dev

trigger:
  branch:
    - main
    - master
    - dev
  event:
    - push
    - pull_request
