kind: pipeline # 定义一个管道
type: docker # 当前管道的类型
name: test # 当前管道的名称

steps:

  # 第一步：构建项目
  - name: 构建项目
    image: node:18-alpine
    commands:
      - rm -rf node_modules
      - npm ci
      - npm run build

  # 第二步：部署到服务器
  - name: 清理部署目录
    image: appleboy/drone-ssh
    settings:
      host:
        from_secret: server_host
      username:
        from_secret: server_username  
      password:
        from_secret: server_password
      # 或者使用SSH密钥
      # key:
      #   from_secret: server_ssh_key
      port: 22
      script:
        - rm -rf /www/wwwroot/sdk.zguiy.com/zt/*
        - mkdir -p /www/wwwroot/sdk.zguiy.com/zt/
        - mkdir -p /www/wwwroot/sdk.zguiy.com/zt/bblcdn/
        - chmod 755 /www/wwwroot/sdk.zguiy.com/zt/
    when:
      branch: 
        - main
        - master
        - dev
  # 第三步：上传构建文件
  - name: 上传构建文件
    image: appleboy/drone-scp
    settings:
      host:
        from_secret: server_host
      username:
        from_secret: server_username
      password:
        from_secret: server_password
      # 或者使用SSH密钥
      # key:
      #   from_secret: server_ssh_key
      port: 22
      source:
        - dist/**
        - vite.config.js
      target: /www/wwwroot/sdk.zguiy.com/zt/
      strip_components: 1
    when:
      branch:
        - main
        - master  
        - dev


# 触发条件
trigger:
  branch:
    - main
    - master
    - dev
  event:
    - push
    - pull_request
