kind: pipeline
type: docker
name: default

platform:
  os: linux
  arch: amd64

steps:
  - name: 测试服-依赖安装&&编译打包&&上传微信小程序平台
    pull: if-not-exists
    image: node:20-alpine
    when:
      branch:
        - test
    commands:
      - npm config set registry https://registry.npmmirror.com/
      - npm install -g pnpm
      - pnpm install
      - pnpm build:weapp:test:upload
      - rm -rf dist.tar
      - rm -rf node_modules

  - name: 正式服-依赖安装&&编译打包&&上传微信小程序平台
    pull: if-not-exists
    image: node:20-alpine
    when:
      branch:
        - master
    commands:
      - npm config set registry https://registry.npmmirror.com/
      - npm install -g pnpm
      - pnpm install
      - pnpm build:weapp:prod:upload
      - rm -rf dist.tar
      - rm -rf node_modules

  - name: 企业微信通知
    pull: if-not-exists
    image: plugins/webhook
    when:
      branch:
        - test
        - master
      status:
        - success
        - failure
    settings:
      urls: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a2065e21-4f92-4f5b-a432-2c0cd1d965b5
      content_type: application/json
      template: |
        {
          "msgtype": "markdown",
          "markdown": {
              "content": "{{#success build.status}}✅{{else}}❌{{/success}}**{{ repo.owner }}/{{ repo.name }}** (Build #{{build.number}})\n
                          >**构建结果**: {{ build.status }}
                          >**构建详情**: [点击查看]({{ build.link }})
                          >**代码分支**: {{ build.branch }}
                          >**提交标识**: {{ build.commit }}
                          >**提交发起**: {{ build.author }}
                          >**提交信息**: {{ build.message }}
        "
          }
        }
