version: '1.0'
name: pipeline-go
displayName: pipeline-go
triggers:
  trigger: auto
  push:
    branches:
      prefix:
        - dev
stages:
  - name: stage-fb64cace
    displayName: go打包
    strategy: naturally
    trigger: auto
    executor: []
    steps:
      - step: build@golang
        name: build_golang
        displayName: Golang 构建
        golangVersion: '1.22'
        commands:
          - '# 默认使用goproxy.cn'
          - export GOPROXY=https://goproxy.cn
          - ''
          - '# 输入你的构建命令'
          - cd server
          - go mod tidy
          - go build -o ./x_admin
        artifacts:
          - name: BUILD_Go
            path:
              - ./server/x_admin
        caches:
          - /go/pkg/mod
        notify: []
        strategy:
          retry: '0'
      - step: deploy@agent
        name: deploy_go
        displayName: 主机部署-go
        hostGroupID:
          ID: tengxun_qingliang
          hostID:
            - fee90b81-14b8-4170-915d-3da3f413a812
        deployArtifact:
          - source: build
            name: x_admin
            target: ~/gitee_go/deploy
            dependArtifact: BUILD_Go
        script:
          - '# 功能：部署脚本会在部署主机组的每台机器上执行'
          - '# 使用场景：先将制品包解压缩到指定目录中，再执行启动脚本deploy.sh，脚本示例地址：https://gitee.com/gitee-go/spring-boot-maven-deploy-case/blob/master/deploy.sh'
          - mkdir -p /www/wwwroot/likeadmin
          - tar zxvf ~/gitee_go/deploy/x_admin.tar.gz -C /www/wwwroot/likeadmin
          - '# sh /home/admin/app/deploy.sh restart'
          - pm2 reload x_admin
          - echo 'Go部署完成'
        notify: []
        strategy:
          retry: '0'
        dependsOn: build_golang
