build: test #46
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: Build and Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| go-version: [1.23] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| cache: true | |
| - name: Install audio libraries (Ubuntu only) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: sudo apt-get update && sudo apt-get install -y libasound2-dev libopus-dev libpulse-dev | |
| - name: Install audio libraries (macOS only) | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| arch -x86_64 /usr/local/bin/brew install portaudio opus opusfile pkg-config | |
| - name: Set macOS env for CGO | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| echo "PKG_CONFIG_PATH=$(arch -x86_64 /usr/local/bin/brew --prefix)/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV | |
| echo "CGO_CFLAGS=-I$(arch -x86_64 /usr/local/bin/brew --prefix)/include -I$(arch -x86_64 /usr/local/bin/brew --prefix)/include/opus" >> $GITHUB_ENV | |
| echo "CGO_LDFLAGS=-L$(arch -x86_64 /usr/local/bin/brew --prefix)/lib -lopus" >> $GITHUB_ENV | |
| - name: Install dependencies | |
| run: | | |
| go mod download | |
| go mod verify | |
| - name: Install zip (Windows only) | |
| if: matrix.os == 'windows-latest' | |
| run: choco install zip -y | |
| - name: Build | |
| shell: bash | |
| run: | | |
| if [ "${{ matrix.os }}" = "windows-latest" ]; then | |
| GOOS=windows | |
| OUTPUT="xiaozhi-client.exe" | |
| elif [ "${{ matrix.os }}" = "macos-latest" ]; then | |
| GOOS=darwin | |
| OUTPUT="xiaozhi-client" | |
| export GOARCH=amd64 | |
| export CGO_ENABLED=1 | |
| arch -x86_64 go build -x -v -o $OUTPUT ./cmd/client | |
| exit 0 | |
| else | |
| GOOS=linux | |
| OUTPUT="xiaozhi-client" | |
| fi | |
| GOARCH=amd64 \ | |
| CGO_ENABLED=1 \ | |
| go build -x -v -o $OUTPUT ./cmd/client | |
| - name: Prepare Windows artifacts | |
| if: matrix.os == 'windows-latest' | |
| shell: bash | |
| run: | | |
| mkdir -p dist | |
| cp xiaozhi-client.exe dist/ | |
| cp cmd/client/opus.dll dist/ | |
| cd dist | |
| zip -r ../xiaozhi-client-windows.zip * | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: xiaozhi-client-${{ matrix.os }} | |
| path: ${{ matrix.os == 'windows-latest' && 'xiaozhi-client-windows.zip' || matrix.os == 'macos-latest' && 'xiaozhi-client' || 'xiaozhi-client' }} | |
| release: | |
| name: Release | |
| needs: build | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| artifacts/xiaozhi-client-ubuntu-latest | |
| artifacts/xiaozhi-client-macos-latest | |
| artifacts/xiaozhi-client-windows-latest | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true |