Skip to content

build: test

build: test #5

Workflow file for this run

name: 构建跨平台应用
on:
push:
branches: [ main, master ]
tags: [ 'v*' ]
pull_request:
branches: [ main, master ]
workflow_dispatch:
jobs:
build:
name: 构建 ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
output_name: xiaozhi-client-linux
asset_name: xiaozhi-client-linux
- os: windows-latest
output_name: xiaozhi-client-windows.exe
asset_name: xiaozhi-client-windows
- os: macos-latest
output_name: xiaozhi-client-macos
asset_name: xiaozhi-client-macos
steps:
- uses: actions/checkout@v4
- name: 设置 Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
cache: true
- name: 安装依赖 (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y portaudio19-dev libasound2-dev libopus-dev pkg-config libopusfile-dev
# 验证opus库是否可用
pkg-config --libs --cflags opus || true
pkg-config --libs --cflags opusfile || true
# 输出安装的库信息
dpkg -l | grep opus
env:
DEBIAN_FRONTEND: noninteractive
- name: 安装依赖 (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install portaudio
brew install opus
brew install opusfile
brew install pkg-config
# 设置PKG_CONFIG_PATH确保能找到opus和opusfile
echo "PKG_CONFIG_PATH=$(brew --prefix)/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV
# 验证opus和opusfile库是否可用
echo "====== Opus库信息 ======"
pkg-config --libs --cflags opus || true
echo "====== OpusFile库信息 ======"
pkg-config --libs --cflags opusfile || true
# 显示库位置
echo "====== Opus库位置 ======"
brew list opus || true
echo "====== OpusFile库位置 ======"
brew list opusfile || true
# 手动创建opus.pc文件(如果pkg-config找不到)
mkdir -p $HOME/pkgconfig
if ! pkg-config --exists opus; then
cat > $HOME/pkgconfig/opus.pc << EOF
Name: opus
Description: Opus IETF audio codec
Version: 1.3.1
Libs: -L$(brew --prefix)/lib -lopus
Cflags: -I$(brew --prefix)/include/opus
EOF

Check failure on line 85 in .github/workflows/build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build.yml

Invalid workflow file

You have an error in your yaml syntax on line 85
echo "PKG_CONFIG_PATH=$HOME/pkgconfig:$(brew --prefix)/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV
fi
# 尝试直接指定opus头文件和库文件位置
echo "CGO_CFLAGS=-I$(brew --prefix)/include -I$(brew --prefix)/include/opus" >> $GITHUB_ENV
echo "CGO_LDFLAGS=-L$(brew --prefix)/lib -lopus" >> $GITHUB_ENV
- name: 安装依赖 (Windows)
if: matrix.os == 'windows-latest'
run: |
# 使用MSYS2安装PortAudio和Opus
choco install -y msys2
choco install -y mingw
C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-x86_64-portaudio mingw-w64-x86_64-pkg-config mingw-w64-x86_64-opus mingw-w64-x86_64-opusfile"
# 设置CGO环境变量和路径
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "C:/msys64/mingw64/bin" >> $GITHUB_PATH
echo "PKG_CONFIG_PATH=C:/msys64/mingw64/lib/pkgconfig" >> $GITHUB_ENV
# 验证opus库是否可用
C:\msys64\usr\bin\bash -lc "pkg-config --libs --cflags opus || true"
C:\msys64\usr\bin\bash -lc "pkg-config --libs --cflags opusfile || true"
# 列出已安装的包
C:\msys64\usr\bin\bash -lc "pacman -Q | grep opus"
- name: 获取依赖
run: go mod tidy
- name: 构建应用
run: |
VERSION=$(echo $GITHUB_REF | sed -e 's/refs\/tags\/v//' -e 's/refs\/heads\///')
if [ -z "$VERSION" ]; then
VERSION="dev"
fi
# 设置CGO_ENABLED环境变量
export CGO_ENABLED=1
# 调试输出Go环境
go env
# 针对macOS的特殊构建设置
if [[ "$RUNNER_OS" == "macOS" ]]; then
# 尝试使用特定标志构建
go build -v -x -o ${{ matrix.output_name }} -ldflags "-X main.Version=${VERSION}" -tags=dynamic ./cmd/client
else
# 其他平台正常构建
go build -v -o ${{ matrix.output_name }} -ldflags "-X main.Version=${VERSION}" ./cmd/client
fi
shell: bash
env:
CGO_ENABLED: 1
- name: 压缩构建产物 (Unix-like)
if: matrix.os != 'windows-latest'
run: |
tar -czvf ${{ matrix.asset_name }}.tar.gz ${{ matrix.output_name }}
shell: bash
- name: 压缩构建产物 (Windows)
if: matrix.os == 'windows-latest'
run: |
7z a ${{ matrix.asset_name }}.zip ${{ matrix.output_name }}
shell: bash
- name: 上传构建产物
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: |
${{ matrix.asset_name }}.tar.gz
${{ matrix.asset_name }}.zip
if-no-files-found: warn
retention-days: 5
release:
name: 创建发布
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: 下载所有构建产物
uses: actions/download-artifact@v4
- name: 展示下载的文件
run: ls -R
shell: bash
- name: 创建发布
uses: softprops/action-gh-release@v2
with:
files: |
xiaozhi-client-linux/xiaozhi-client-linux.tar.gz
xiaozhi-client-windows/xiaozhi-client-windows.zip
xiaozhi-client-macos/xiaozhi-client-macos.tar.gz
draft: false
prerelease: false