when:
  - event: tag

clone:
  git:
    image: docker.m.daocloud.io/woodpeckerci/plugin-git
    settings:
      depth: 1

steps:
  # 构建多架构二进制文件
  build:
    image: docker.m.daocloud.io/golang:1.26-trixie
    environment:
      GOPROXY: https://goproxy.cn
    commands:
      - sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources
      # 启用多架构支持并安装交叉编译工具
      - dpkg --add-architecture arm64
      - apt-get update
      - apt-get install -y gcc-aarch64-linux-gnu pkg-config
      - apt-get install -y libasound2-dev libvlc-dev
      - apt-get install -y libasound2-dev:arm64 libvlc-dev:arm64
      - mkdir -p release
      # 构建 amd64 (native)
      - PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig go build -ldflags="-w -s -X main.Version=${CI_COMMIT_TAG} -X main.Commit=${CI_COMMIT_SHA}" -o release/game-driver-linux-amd64 .
      # 构建 arm64 (cross-compile)
      - PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc go build -ldflags="-w -s -X main.Version=${CI_COMMIT_TAG} -X main.Commit=${CI_COMMIT_SHA}" -o release/game-driver-linux-arm64 .
      - ls -lh release/

  # 发布构建产物（可选）
  release:
    image: docker.m.daocloud.io/woodpeckerci/plugin-release
    settings:
      base-url: https://gitea.tides.top
      title: ${CI_COMMIT_TAG}
      api-key:
        from_secret: gitea_token
      files:
        - release/game-driver-linux-amd64
        - release/game-driver-linux-arm64
    depends_on:
      - build
