---
kind: pipeline
type: docker
name: linux-amd64

platform:
  arch: amd64
  os: linux

steps:
  - name: build
    image: mcr.microsoft.com/dotnet/sdk:6.0
    privileged: true
    commands:
      - cd ./build
      - chmod 755 ./build.sh
      - ./build.sh
      - 'git --no-pager log --date=format:"%Y-%m-%d %H:%M:%S" --pretty=format:"%h - %ad %cn: %s %b" --invert-grep --grep="CI SKIP" --grep="drone" >./publish/log.txt'
      - echo "${DRONE_BUILD_NUMBER}-${DRONE_COMMIT_AUTHOR}-${DRONE_REPO_BRANCH}-${DRONE_COMMIT_SHA:0:8}\n">./publish/version.txt
      - echo ${DRONE_COMMIT_MESSAGE}>>./publish/version.txt
      - dotnet nuget locals global-packages --list

  - name: publish
    image: plugins/s3
    settings:
      endpoint: http://dev.ccwin-in.com:3008
      path_style: true
      bucket: default
      access_key: O222sbIaMKeGfeX18t8K
      secret_key: 0LEOWfXSDnaLbIYGZfdKUxyi2kYIayx4YvdLTgcR
      source: build/publish/**/*
      strip_prefix: build/publish/
      target: /jie-suan/bei-qi/${DRONE_BUILD_NUMBER}-${DRONE_COMMIT_AUTHOR}-${DRONE_REPO_BRANCH}-${DRONE_COMMIT_SHA:0:8}

  - name: stop
    image: appleboy/drone-ssh
    settings:
      host: dev.ccwin-in.com
      port: 16085
      username: Administrator
      password: Microsoft@2022
      command_timeout: 10m
      script:
        - mkdir -p /d/publish/jie-suan/bei-qi
        - cd /d/publish/jie-suan/bei-qi
        - ./stop.cmd
        - sleep 3
        - cd ..
        - rm -rf publish
        - mkdir -p publish

  - name: deploy-ftp
    image: cschlosser/drone-ftps
    environment:
      PLUGIN_HOSTNAME: dev.ccwin-in.com:16022
      FTP_USERNAME:
        from_secret: username
      FTP_PASSWORD:
        from_secret: password
      PLUGIN_SRC_DIR: /build/publish
      PLUGIN_DEST_DIR: /jie-suan/bei-qi
      PLUGIN_SECURE: false
      PLUGIN_CHMOD: false

  - name: start
    image: appleboy/drone-ssh
    settings:
      host: dev.ccwin-in.com
      port: 16085
      username: Administrator
      password: Microsoft@2022
      command_timeout: 10m
      script:
        - cd /d/publish/jie-suan/bei-qi
        - ./start.cmd