build: 构建正常,linux/macos tar.gz压缩包,windows zipba包 #50
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: | | ||
| brew install --build-from-source portaudio opus opusfile pkg-config | ||
| arch -x86_64 brew install --build-from-source opus opusfile pkg-config | ||
| - name: Set macOS env for CGO | ||
| 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: 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 | ||
| GOARCH=amd64 | ||
| OUTPUT="xiaozhi-client" | ||
| else | ||
| GOOS=linux | ||
| GOARCH=amd64 | ||
| OUTPUT="xiaozhi-client" | ||
| fi | ||
| CGO_ENABLED=1 \ | ||
| go build -x -v -o $OUTPUT ./cmd/client | ||
| - name: Package Linux/macOS artifacts | ||
| if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' | ||
| shell: bash | ||
| run: | | ||
| tar -czvf xiaozhi-client-${{ matrix.os }}.tar.gz xiaozhi-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' || 'xiaozhi-client-' + matrix.os + '.tar.gz' }} | ||
|
Check failure on line 96 in .github/workflows/build.yml
|
||
| 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/xiaozhi-client-ubuntu-latest.tar.gz | ||
| artifacts/xiaozhi-client-macos-latest/xiaozhi-client-macos-latest.tar.gz | ||
| artifacts/xiaozhi-client-windows-latest/xiaozhi-client-windows.zip | ||
| draft: false | ||
| prerelease: false | ||
| generate_release_notes: true | ||