|
20 | 20 | pull_request: |
21 | 21 | branches: [ main ] |
22 | 22 |
|
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + |
23 | 26 | jobs: |
24 | | - build: |
| 27 | + build-no-console: |
| 28 | + name: Build (no console, no CGO) |
25 | 29 | runs-on: ubuntu-latest |
26 | 30 | steps: |
27 | 31 | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
28 | | - - uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5 |
29 | | - with: |
30 | | - path: | |
31 | | - ~/go/pkg/mod |
32 | | - ~/go/bin |
33 | | - ~/.cache |
34 | | - key: livekit-cli |
35 | 32 |
|
36 | 33 | - name: Set up Go |
37 | 34 | uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 |
38 | 35 | with: |
39 | | - go-version: "1.25" |
| 36 | + go-version-file: go.mod |
| 37 | + |
| 38 | + - name: Build without console tag |
| 39 | + env: |
| 40 | + CGO_ENABLED: "0" |
| 41 | + run: go build -o bin/lk ./cmd/lk |
| 42 | + |
| 43 | + - name: Verify binary |
| 44 | + run: bin/lk --help > /dev/null |
| 45 | + |
| 46 | + lint-and-test: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 50 | + with: |
| 51 | + submodules: true |
40 | 52 |
|
41 | | - - name: Download Go modules |
42 | | - run: go mod download |
| 53 | + - name: Set up Go |
| 54 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 |
| 55 | + with: |
| 56 | + go-version-file: go.mod |
43 | 57 |
|
44 | | - - name: Lint |
45 | | - uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9 |
| 58 | + - name: Static Check |
| 59 | + uses: dominikh/staticcheck-action@288b4e28bae83c59f35f73651aeb5cab746a06fc # v1.4.0 |
46 | 60 | with: |
47 | | - version: v2.11.4 |
| 61 | + version: "latest" |
| 62 | + install-go: false |
48 | 63 |
|
49 | | - - name: Run Go tests |
| 64 | + - name: Test |
50 | 65 | run: go test -v ./... |
| 66 | + |
| 67 | + build: |
| 68 | + strategy: |
| 69 | + fail-fast: false |
| 70 | + matrix: |
| 71 | + include: |
| 72 | + - os: macos-latest |
| 73 | + suffix: darwin_arm64 |
| 74 | + - os: ubuntu-latest |
| 75 | + suffix: linux_amd64 |
| 76 | + zig_target: x86_64-linux-gnu.2.28 |
| 77 | + alsa_arch: amd64 |
| 78 | + alsa_triple: x86_64-linux-gnu |
| 79 | + - os: ubuntu-latest |
| 80 | + suffix: linux_arm64 |
| 81 | + zig_target: aarch64-linux-gnu.2.28 |
| 82 | + alsa_arch: arm64 |
| 83 | + alsa_triple: aarch64-linux-gnu |
| 84 | + goarch: arm64 |
| 85 | + - os: ubuntu-latest |
| 86 | + suffix: linux_arm |
| 87 | + zig_target: arm-linux-gnueabihf.2.28 |
| 88 | + alsa_arch: armhf |
| 89 | + alsa_triple: arm-linux-gnueabihf |
| 90 | + goarch: arm |
| 91 | + goarm: "7" |
| 92 | + - os: ubuntu-latest |
| 93 | + suffix: windows_amd64 |
| 94 | + zig_target: x86_64-windows-gnu |
| 95 | + goos: windows |
| 96 | + goarch: amd64 |
| 97 | + - os: ubuntu-latest |
| 98 | + suffix: windows_arm64 |
| 99 | + zig_target: aarch64-windows-gnu |
| 100 | + goos: windows |
| 101 | + goarch: arm64 |
| 102 | + runs-on: ${{ matrix.os }} |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 105 | + with: |
| 106 | + submodules: true |
| 107 | + |
| 108 | + - name: Set up Go |
| 109 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 |
| 110 | + with: |
| 111 | + go-version-file: go.mod |
| 112 | + |
| 113 | + - name: Install Zig |
| 114 | + if: matrix.zig_target |
| 115 | + uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2 |
| 116 | + with: |
| 117 | + version: 0.14.1 |
| 118 | + |
| 119 | + - name: Install ALSA headers |
| 120 | + if: matrix.alsa_arch |
| 121 | + run: | |
| 122 | + sudo dpkg --add-architecture ${{ matrix.alsa_arch }} |
| 123 | + if [ "${{ matrix.alsa_arch }}" != "amd64" ]; then |
| 124 | + CODENAME=$(lsb_release -cs) |
| 125 | + # Restrict existing sources to amd64 to avoid 404s for foreign arch |
| 126 | + for f in /etc/apt/sources.list.d/*.sources; do |
| 127 | + grep -q '^Architectures:' "$f" || sudo sed -i '/^Types:/a Architectures: amd64 i386' "$f" |
| 128 | + done |
| 129 | + # Add ports.ubuntu.com for the foreign architecture |
| 130 | + printf 'Types: deb\nURIs: http://ports.ubuntu.com/ubuntu-ports\nSuites: %s %s-updates\nComponents: main universe\nArchitectures: %s\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg\n' \ |
| 131 | + "$CODENAME" "$CODENAME" "${{ matrix.alsa_arch }}" | sudo tee /etc/apt/sources.list.d/ports.sources |
| 132 | + fi |
| 133 | + sudo apt-get update |
| 134 | + sudo apt-get install -y libasound2-dev:${{ matrix.alsa_arch }} |
| 135 | +
|
| 136 | + - name: Generate Windows import libraries |
| 137 | + if: matrix.goos == 'windows' && matrix.zig_target |
| 138 | + run: | |
| 139 | + ZIG_LIB=$(zig env | jq -r '.lib_dir') |
| 140 | + echo "ZIG_LIB=${ZIG_LIB}" >> "$GITHUB_ENV" |
| 141 | + LIB_DIR="${ZIG_LIB}/libc/mingw/lib-common" |
| 142 | + # Zig bundles MinGW .def files but lld needs .a import libraries. |
| 143 | + # Go's compiled objects embed COFF /DEFAULTLIB directives (e.g. dbghelp, |
| 144 | + # bcrypt) that lld resolves directly, bypassing Zig's lazy .def→.a |
| 145 | + # generation. Pre-generate all import libraries so lld can find them. |
| 146 | + MACHINE=${{ matrix.goarch == 'amd64' && 'i386:x86-64' || 'arm64' }} |
| 147 | + for def in "${LIB_DIR}"/*.def; do |
| 148 | + lib=$(basename "$def" .def) |
| 149 | + [ -f "${LIB_DIR}/lib${lib}.a" ] && continue |
| 150 | + zig dlltool -d "$def" -l "${LIB_DIR}/lib${lib}.a" -m "$MACHINE" 2>/dev/null || true |
| 151 | + done |
| 152 | +
|
| 153 | + - name: Build |
| 154 | + env: |
| 155 | + CGO_ENABLED: ${{ (matrix.goos && !matrix.zig_target) && '0' || '1' }} |
| 156 | + CC: ${{ matrix.zig_target && format('zig cc -target {0}', matrix.zig_target) || '' }} |
| 157 | + CXX: ${{ matrix.zig_target && format('zig c++ -target {0}', matrix.zig_target) || '' }} |
| 158 | + # Zig uses its own sysroot; point it at the system ALSA headers and libraries |
| 159 | + CGO_CFLAGS: ${{ matrix.alsa_triple && format('-isystem /usr/include -isystem /usr/include/{0}', matrix.alsa_triple) || '' }} |
| 160 | + CGO_LDFLAGS: ${{ matrix.alsa_triple && format('-L/usr/lib/{0}', matrix.alsa_triple) || '' }} |
| 161 | + # -fms-extensions: enable __try/__except (SEH) used by WebRTC |
| 162 | + # -DNTDDI_VERSION: target Windows 10 base to skip WinRT includes absent from MinGW |
| 163 | + CGO_CXXFLAGS: ${{ matrix.goos == 'windows' && '-fms-extensions -DNTDDI_VERSION=0x0A000000' || '' }} |
| 164 | + GOOS: ${{ matrix.goos || '' }} |
| 165 | + GOARCH: ${{ matrix.goarch || '' }} |
| 166 | + GOARM: ${{ matrix.goarm || '' }} |
| 167 | + shell: bash |
| 168 | + run: | |
| 169 | + EXT=""; if [ "${GOOS:-}" = "windows" ]; then EXT=".exe"; fi |
| 170 | + TAGS="" |
| 171 | + if [ "$CGO_ENABLED" = "1" ]; then TAGS="-tags console"; fi |
| 172 | + # Force external linking for Windows so Go uses zig cc (CC) as the linker, |
| 173 | + # and add Zig's MinGW lib path so lld can find the generated import libraries. |
| 174 | + EXTLD="" |
| 175 | + if [ "${GOOS:-}" = "windows" ] && [ "$CGO_ENABLED" = "1" ]; then |
| 176 | + EXTLD="-linkmode=external -extldflags '-L${ZIG_LIB}/libc/mingw/lib-common'" |
| 177 | + fi |
| 178 | + go build $TAGS -ldflags "-w -s $EXTLD" -o "bin/lk${EXT}" ./cmd/lk |
| 179 | +
|
| 180 | + - name: Verify binary |
| 181 | + if: "!matrix.goos && !matrix.goarch" |
| 182 | + run: bin/lk --help > /dev/null |
0 commit comments