Skip to content

build: update for test macos #2

build: update for test macos

build: update for test macos #2

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
- name: 安装依赖 (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install portaudio
- name: 安装依赖 (Windows)
if: matrix.os == 'windows-latest'
run: |
# 使用MSYS2安装PortAudio
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"
# 设置CGO环境变量
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "C:/msys64/mingw64/bin" >> $GITHUB_PATH
- name: 获取依赖
run: go mod download
- 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
shell: bash
- 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