---
kind: pipeline
name: 构建 Docker Nightly 镜像
type: docker

trigger:
  event:
    - push
  branch:
    - master

steps:
  - name: submodules
    image: alpine/git
    commands:
      - git submodule update --init --recursive
  - name: 构建 Docker 镜像
    image: plugins/docker:latest
    privileged: true
    settings:
      username: kagami-ci
      password:
        from_secret: KAGAMI-CI-PASSWORD
      repo: gitea.service.jazzwhom.top/mttu-developers/konabot
      registry: gitea.service.jazzwhom.top
      tags:
        - nightly
        - nightly-${DRONE_COMMIT_SHA}
      dockerfile: Dockerfile
    volumes:
      - name: docker-socket
        path: /var/run/docker.sock
  - name: 在容器中进行若干测试
    image: docker:dind
    privileged: true
    volumes:
      - name: docker-socket
        path: /var/run/docker.sock
    commands:
      - docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python scripts/test_plugin_load.py
      - docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python scripts/test_playwright.py
      - docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python -m pytest --cov=./konabot/ --cov-report term-missing:skip-covered
  - name: 发送构建结果到 ntfy
    image: parrazam/drone-ntfy
    when:
      status: [success, failure]
    settings:
      url: https://ntfy.service.jazzwhom.top
      topic: drone_ci
      tags:
        - drone-ci
      token:
        from_secret: NTFY_TOKEN

volumes:
  - name: docker-socket
    host:
      path: /var/run/docker.sock

---
kind: pipeline
name: 构建 Docker Release 镜像
type: docker

trigger:
  event:
    - tag

steps:
  - name: submodules
    image: alpine/git
    commands:
      - git submodule update --init --recursive
  - name: 构建并推送 Release Docker 镜像
    image: plugins/docker:latest
    privileged: true
    settings:
      username: kagami-ci
      password:
        from_secret: KAGAMI-CI-PASSWORD
      repo: gitea.service.jazzwhom.top/mttu-developers/konabot
      registry: gitea.service.jazzwhom.top
      tags:
        - ${DRONE_TAG}
        - latest
      dockerfile: Dockerfile
    volumes:
      - name: docker-socket
        path: /var/run/docker.sock
  - name: 发送构建结果到 ntfy
    image: parrazam/drone-ntfy
    when:
      status: [success, failure]
    settings:
      url: https://ntfy.service.jazzwhom.top
      topic: drone_ci
      tags:
        - drone-ci
      token:
        from_secret: NTFY_TOKEN

volumes:
  - name: docker-socket
    host:
      path: /var/run/docker.sock
