build #54
Workflow file for this run
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 | |
| on: | |
| workflow_dispatch: | |
| release: | |
| types: [published] | |
| env: | |
| GO_VERSION: "~1.26" | |
| MODULE: github.com/mapleafgo/singcast | |
| jobs: | |
| get-release: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag_name: ${{ steps.get-release.outputs.tag_name }} | |
| upload_url: ${{ steps.get-release.outputs.upload_url }} | |
| steps: | |
| - name: Get release info | |
| id: get-release | |
| run: | | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| echo "tag_name=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT" | |
| echo "upload_url=${{ github.event.release.upload_url }}" >> "$GITHUB_OUTPUT" | |
| else | |
| TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName') | |
| UPLOAD_URL=$(gh release view "$TAG" --json uploadUrl -q '.uploadUrl') | |
| echo "tag_name=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "upload_url=$UPLOAD_URL" >> "$GITHUB_OUTPUT" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # ── 测试 ──────────────────────────────────────────────── | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - run: go test -tags "with_clash_api,with_utls,with_quic,with_gvisor,with_v2ray_api" ./... | |
| # ── CLI 二进制 ────────────────────────────────────────── | |
| build-cli: | |
| needs: [get-release, test] | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| goos: linux | |
| goarch: amd64 | |
| ext: "" | |
| - os: ubuntu-latest | |
| goos: linux | |
| goarch: arm64 | |
| ext: "" | |
| - os: macos-latest | |
| goos: darwin | |
| goarch: amd64 | |
| ext: "" | |
| - os: macos-latest | |
| goos: darwin | |
| goarch: arm64 | |
| ext: "" | |
| - os: windows-latest | |
| goos: windows | |
| goarch: amd64 | |
| ext: ".exe" | |
| - os: windows-latest | |
| goos: windows | |
| goarch: arm64 | |
| ext: ".exe" | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Build | |
| shell: bash | |
| env: | |
| VERSION: ${{ needs.get-release.outputs.tag_name }} | |
| CGO_ENABLED: 0 | |
| run: | | |
| mkdir -p build | |
| go build -trimpath -tags "with_clash_api,with_utls,with_quic,with_gvisor,with_v2ray_api" \ | |
| -ldflags="-X ${{ env.MODULE }}/core.Version=${VERSION} -w -s" \ | |
| -o build/singcast-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }} \ | |
| ./cmd/singcast | |
| - name: Package | |
| shell: bash | |
| run: | | |
| cd build | |
| tar -czf singcast-${{ needs.get-release.outputs.tag_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz * | |
| - name: Upload | |
| uses: shogo82148/actions-upload-release-asset@v1 | |
| with: | |
| upload_url: ${{ needs.get-release.outputs.upload_url }} | |
| asset_path: build/*.tar.gz | |
| overwrite: true | |
| # ── FFI 共享库 (桌面) ─────────────────────────────────── | |
| build-ffi-desktop: | |
| needs: [get-release, test] | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| goos: linux | |
| goarch: amd64 | |
| ext: .so | |
| prefix: lib | |
| - os: ubuntu-latest | |
| goos: linux | |
| goarch: arm64 | |
| ext: .so | |
| prefix: lib | |
| - os: macos-latest | |
| goos: darwin | |
| goarch: amd64 | |
| ext: .dylib | |
| prefix: lib | |
| - os: macos-latest | |
| goos: darwin | |
| goarch: arm64 | |
| ext: .dylib | |
| prefix: lib | |
| - os: windows-latest | |
| goos: windows | |
| goarch: amd64 | |
| ext: .dll | |
| prefix: "" | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Install cross-compilation toolchain | |
| if: matrix.goarch == 'arm64' && matrix.goos == 'linux' | |
| run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu | |
| - name: Build | |
| shell: bash | |
| env: | |
| VERSION: ${{ needs.get-release.outputs.tag_name }} | |
| CGO_ENABLED: 1 | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| run: | | |
| mkdir -p build | |
| if [ "$GOOS" = "linux" ] && [ "$GOARCH" = "arm64" ]; then | |
| export CC=aarch64-linux-gnu-gcc | |
| fi | |
| go build -buildmode=c-shared -trimpath -tags "with_clash_api,with_utls,with_quic,with_gvisor,with_v2ray_api" \ | |
| -ldflags="-X ${{ env.MODULE }}/core.Version=${VERSION} -w -s" \ | |
| -o build/${{ matrix.prefix }}singcast-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }} \ | |
| ./cmd/lib | |
| - name: Package | |
| shell: bash | |
| run: | | |
| cd build | |
| tar -czf libsingcast-${{ needs.get-release.outputs.tag_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz * | |
| - name: Upload | |
| uses: shogo82148/actions-upload-release-asset@v1 | |
| with: | |
| upload_url: ${{ needs.get-release.outputs.upload_url }} | |
| asset_path: build/*.tar.gz | |
| overwrite: true | |
| # ── FFI 共享库 (Android) ──────────────────────────────── | |
| build-ffi-android: | |
| needs: [get-release, test] | |
| strategy: | |
| matrix: | |
| include: | |
| - target: android/arm64 | |
| goarch: arm64 | |
| - target: android/amd64 | |
| goarch: amd64 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - uses: nttld/setup-ndk@v1 | |
| with: | |
| ndk-version: r27 | |
| add-to-path: false | |
| local-cache: true | |
| - name: Build | |
| env: | |
| VERSION: ${{ needs.get-release.outputs.tag_name }} | |
| run: | | |
| go mod download | |
| go install golang.org/x/mobile/cmd/gomobile@latest | |
| gomobile init | |
| mkdir -p build | |
| gomobile bind -trimpath -tags "with_clash_api,with_utls,with_quic,with_gvisor,with_v2ray_api" \ | |
| -ldflags="-X ${{ env.MODULE }}/core.Version=${VERSION} -w -s -checklinkname=0" \ | |
| -o build/libsingcast-${{ matrix.goarch }}.aar \ | |
| -target=${{ matrix.target }} \ | |
| -androidapi 29 \ | |
| -javapkg cn.mapleafgo \ | |
| ./ffi | |
| - name: Package | |
| run: | | |
| cd build | |
| tar -czf libsingcast-${{ needs.get-release.outputs.tag_name }}-android-${{ matrix.goarch }}.tar.gz * | |
| - name: Upload | |
| uses: shogo82148/actions-upload-release-asset@v1 | |
| with: | |
| upload_url: ${{ needs.get-release.outputs.upload_url }} | |
| asset_path: build/*.tar.gz | |
| overwrite: true | |
| # ── FFI 共享库 (iOS) ─────────────────────────────────── | |
| build-ffi-ios: | |
| runs-on: macos-latest | |
| needs: [get-release, test] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Build | |
| env: | |
| VERSION: ${{ needs.get-release.outputs.tag_name }} | |
| run: | | |
| go mod download | |
| go install golang.org/x/mobile/cmd/gomobile@latest | |
| gomobile init | |
| mkdir -p build | |
| gomobile bind -trimpath -tags "with_clash_api,with_utls,with_quic,with_gvisor,with_v2ray_api" \ | |
| -ldflags="-X ${{ env.MODULE }}/core.Version=${VERSION} -w -s" \ | |
| -o build/singcast.xcframework \ | |
| -target=ios \ | |
| ./ffi | |
| - name: Package | |
| run: | | |
| cd build | |
| tar -czf libsingcast-${{ needs.get-release.outputs.tag_name }}-ios.tar.gz * | |
| - name: Upload | |
| uses: shogo82148/actions-upload-release-asset@v1 | |
| with: | |
| upload_url: ${{ needs.get-release.outputs.upload_url }} | |
| asset_path: build/*.tar.gz | |
| overwrite: true |