build: 统一go版本 #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, macos-latest, windows-latest] | |
| include: | |
| - os: ubuntu-latest | |
| output_name: xiaozhi-client-linux | |
| asset_name: xiaozhi-client-linux | |
| - os: macos-latest | |
| output_name: xiaozhi-client-macos | |
| asset_name: xiaozhi-client-macos | |
| - os: windows-latest | |
| output_name: xiaozhi-client-windows.exe | |
| asset_name: xiaozhi-client-windows | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: 设置Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| 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 | |
| env: | |
| DEBIAN_FRONTEND: noninteractive | |
| - name: 安装依赖 (macOS) | |
| if: matrix.os == 'macos-latest' | |
| run: brew install portaudio opus opusfile pkg-config | |
| - name: 设置macOS环境变量 | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| echo "PKG_CONFIG_PATH=$(brew --prefix)/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV | |
| 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: choco install portaudio opus opusfile pkgconfig | |
| - 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 | |
| go build -v -o ${{ matrix.output_name }} -ldflags "-X main.Version=${VERSION}" ./cmd/client | |
| env: | |
| CGO_ENABLED: 1 | |
| - name: 压缩构建产物 | |
| run: tar -czvf ${{ matrix.asset_name }}.tar.gz ${{ matrix.output_name }} | |
| - name: 压缩构建产物 (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: Compress-Archive -Path ${{ matrix.output_name }} -DestinationPath ${{ matrix.asset_name }}.zip | |
| - name: 拷贝 opus.dll (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: Copy-Item -Path ./cmd/client/opus.dll -Destination . | |
| - name: 上传构建产物 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.asset_name }} | |
| path: ${{ matrix.asset_name }}.tar.gz | |
| 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 | |
| - name: 检查标签信息 | |
| run: | | |
| echo "处理的标签: ${{ github.ref }}" | |
| echo "标签名称: ${{ github.ref_name }}" | |
| echo "触发事件: ${{ github.event_name }}" | |
| - name: 创建发布 | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: 发布 ${{ github.ref_name }} | |
| files: | | |
| xiaozhi-client-linux/xiaozhi-client-linux.tar.gz | |
| xiaozhi-client-macos/xiaozhi-client-macos.tar.gz | |
| xiaozhi-client-windows/xiaozhi-client-windows.zip | |
| draft: false | |
| prerelease: false | |
| token: ${{ secrets.GITHUB_TOKEN }} |