Skip to content

Commit 5555e0b

Browse files
examples/ -> cpp-example-collection, ci safety (#83)
1 parent ead2a60 commit 5555e0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+327
-7975
lines changed

.github/workflows/builds.yml

Lines changed: 98 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
paths:
77
- src/**
88
- include/**
9-
- examples/**
9+
- cpp-example-collection/**
1010
- bridge/**
1111
- client-sdk-rust/**
1212
- CMakeLists.txt
@@ -21,7 +21,7 @@ on:
2121
paths:
2222
- src/**
2323
- include/**
24-
- examples/**
24+
- cpp-example-collection/**
2525
- bridge/**
2626
- client-sdk-rust/**
2727
- CMakeLists.txt
@@ -38,12 +38,22 @@ permissions:
3838

3939
env:
4040
CARGO_TERM_COLOR: always
41+
# Pinned commit for cpp-example-collection smoke build (https://github.com/livekit-examples/cpp-example-collection)
42+
CPP_EXAMPLE_COLLECTION_REF: f231c0c75028d1dcf13edcecd369d030d2c7c8d4
4143
# vcpkg binary caching for Windows
4244
VCPKG_DEFAULT_TRIPLET: x64-windows-static-md
4345
VCPKG_DEFAULT_HOST_TRIPLET: x64-windows-static-md
4446
VCPKG_TARGET_TRIPLET: x64-windows-static-md
4547

4648
jobs:
49+
license-check:
50+
name: License Check
51+
uses: ./.github/workflows/license_check.yml
52+
53+
pin-check:
54+
name: Pin Check
55+
uses: ./.github/workflows/pin_check.yml
56+
4757
build:
4858
strategy:
4959
fail-fast: false
@@ -75,23 +85,23 @@ jobs:
7585

7686
steps:
7787
- name: Checkout (with submodules)
78-
uses: actions/checkout@v4
88+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
7989
with:
8090
submodules: recursive
8191
fetch-depth: 0
8292

8393
# ---------- vcpkg caching for Windows ----------
8494
- name: Export GitHub Actions cache environment variables
8595
if: runner.os == 'Windows'
86-
uses: actions/github-script@v7
96+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
8797
with:
8898
script: |
8999
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
90100
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
91101
92102
- name: Setup vcpkg (Windows only)
93103
if: runner.os == 'Windows'
94-
uses: lukka/run-vcpkg@v11
104+
uses: lukka/run-vcpkg@6fe69898af670ac05f4a8427cc5cff4fb361cee5 # v11.5
95105
with:
96106
vcpkgGitCommitId: 'fb87e2bb3fe69e16c224989acb5a61349166c782'
97107

@@ -123,15 +133,17 @@ jobs:
123133
124134
# ---------- Rust toolchain ----------
125135
- name: Install Rust (stable)
126-
uses: dtolnay/rust-toolchain@stable
136+
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
137+
with:
138+
toolchain: stable
127139

128140
- name: Install Rust cross-compilation target
129141
if: matrix.name == 'macos-x64'
130142
run: rustup target add x86_64-apple-darwin
131143

132144
# ---------- Cache Cargo ----------
133145
- name: Cache Cargo registry
134-
uses: actions/cache@v4
146+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
135147
with:
136148
path: |
137149
~/.cargo/registry
@@ -140,7 +152,7 @@ jobs:
140152
restore-keys: ${{ runner.os }}-${{ matrix.name }}-cargo-reg-
141153

142154
- name: Cache Cargo target
143-
uses: actions/cache@v4
155+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
144156
with:
145157
path: client-sdk-rust/target
146158
key: ${{ runner.os }}-${{ matrix.name }}-cargo-target-${{ hashFiles('**/Cargo.lock') }}
@@ -169,28 +181,46 @@ jobs:
169181
shell: pwsh
170182
run: ${{ matrix.build_cmd }}
171183

172-
# ---------- Smoke test examples ----------
184+
# ---------- Smoke test cpp-example-collection binaries ----------
185+
# Built under cpp-example-collection-build/ (not build-dir/bin). Visual Studio
186+
# multi-config places executables in per-target Release/ (or Debug/) subdirs.
173187
- name: Smoke test examples (Unix)
174188
if: runner.os != 'Windows'
175189
shell: bash
176190
run: |
177191
set -x
178192
failed=false
179-
for exe in SimpleRoom SimpleRpc SimpleDataStream; do
180-
exe_path="${{ matrix.build_dir }}/bin/${exe}"
181-
if [[ -x "${exe_path}" ]]; then
182-
echo "Testing ${exe}..."
183-
output=$("${exe_path}" --help 2>&1) || true
184-
if [[ -z "${output}" ]]; then
185-
echo "ERROR: ${exe} produced no output"
186-
failed=true
187-
else
188-
echo "${output}"
189-
echo "${exe} ran successfully"
190-
fi
191-
else
192-
echo "ERROR: ${exe_path} not found or not executable"
193+
examples_base="${{ matrix.build_dir }}/cpp-example-collection-build"
194+
resolve_exe() {
195+
local dir="$1" name="$2"
196+
local p="${examples_base}/${dir}/${name}"
197+
if [[ -x "${p}" ]]; then
198+
printf '%s' "${p}"
199+
return 0
200+
fi
201+
p="${examples_base}/${dir}/Release/${name}"
202+
if [[ -x "${p}" ]]; then
203+
printf '%s' "${p}"
204+
return 0
205+
fi
206+
return 1
207+
}
208+
for pair in "SimpleRoom:simple_room" "SimpleRpc:simple_rpc" "SimpleDataStream:simple_data_stream"; do
209+
exe="${pair%%:*}"
210+
dir="${pair#*:}"
211+
if ! exe_path="$(resolve_exe "${dir}" "${exe}")"; then
212+
echo "ERROR: ${exe} not found under ${examples_base}/${dir}/"
213+
failed=true
214+
continue
215+
fi
216+
echo "Testing ${exe}..."
217+
output=$("${exe_path}" --help 2>&1) || true
218+
if [[ -z "${output}" ]]; then
219+
echo "ERROR: ${exe} produced no output"
193220
failed=true
221+
else
222+
echo "${output}"
223+
echo "${exe} ran successfully"
194224
fi
195225
done
196226
if [[ "$failed" == "true" ]]; then exit 1; fi
@@ -200,12 +230,30 @@ jobs:
200230
shell: pwsh
201231
run: |
202232
$ErrorActionPreference = 'Continue'
203-
$examples = @('SimpleRoom', 'SimpleRpc', 'SimpleDataStream')
233+
$examplesBase = "${{ matrix.build_dir }}/cpp-example-collection-build"
234+
$examples = @(
235+
@{ Name = 'SimpleRoom'; Dir = 'simple_room' },
236+
@{ Name = 'SimpleRpc'; Dir = 'simple_rpc' },
237+
@{ Name = 'SimpleDataStream'; Dir = 'simple_data_stream' }
238+
)
204239
$failed = $false
205-
foreach ($exe in $examples) {
206-
$exePath = "${{ matrix.build_dir }}/bin/${exe}.exe"
207-
if (Test-Path $exePath) {
208-
Write-Host "Testing ${exe}..."
240+
foreach ($ex in $examples) {
241+
$name = $ex.Name
242+
$dir = $ex.Dir
243+
$inDir = Join-Path $examplesBase $dir
244+
$candidates = @(
245+
(Join-Path $inDir "$name.exe"),
246+
(Join-Path (Join-Path $inDir 'Release') "$name.exe")
247+
)
248+
$exePath = $null
249+
foreach ($p in $candidates) {
250+
if (Test-Path -LiteralPath $p) {
251+
$exePath = $p
252+
break
253+
}
254+
}
255+
if ($null -ne $exePath) {
256+
Write-Host "Testing ${name}..."
209257
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
210258
$pinfo.FileName = $exePath
211259
$pinfo.Arguments = "--help"
@@ -220,22 +268,22 @@ jobs:
220268
$p.WaitForExit()
221269
$output = $stdout + $stderr
222270
if ([string]::IsNullOrWhiteSpace($output)) {
223-
Write-Host "ERROR: ${exe} produced no output"
271+
Write-Host "ERROR: ${name} produced no output"
224272
$failed = $true
225273
} else {
226274
Write-Host $output
227-
Write-Host "${exe} ran successfully"
275+
Write-Host "${name} ran successfully"
228276
}
229277
} else {
230-
Write-Host "ERROR: ${exePath} not found"
278+
Write-Host "ERROR: ${name} not found under ${examplesBase}/${dir}/"
231279
$failed = $true
232280
}
233281
}
234282
if ($failed) { exit 1 } else { exit 0 }
235283
236284
# ---------- Upload artifacts ----------
237285
- name: Upload build artifacts
238-
uses: actions/upload-artifact@v4
286+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
239287
with:
240288
name: livekit-sdk-${{ matrix.name }}
241289
path: |
@@ -261,13 +309,13 @@ jobs:
261309

262310
steps:
263311
- name: Checkout (with submodules)
264-
uses: actions/checkout@v4
312+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
265313
with:
266314
submodules: recursive
267315
fetch-depth: 0
268316

269-
- name: Free disk space (GitHub-hosted runner)
270-
uses: jlumbroso/free-disk-space@v1.3.1
317+
- name: Free disk space
318+
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
271319
with:
272320
tool-cache: false
273321
android: true
@@ -278,7 +326,7 @@ jobs:
278326
swap-storage: true
279327

280328
- name: Set up Docker Buildx
281-
uses: docker/setup-buildx-action@v3
329+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
282330

283331
- name: Build Docker image
284332
run: |
@@ -299,7 +347,7 @@ jobs:
299347
docker save livekit-cpp-sdk-x64:${{ github.sha }} | gzip > livekit-cpp-sdk-x64-docker.tar.gz
300348
301349
- name: Upload Docker image artifact
302-
uses: actions/upload-artifact@v4
350+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
303351
with:
304352
name: livekit-cpp-sdk-docker-x64
305353
path: livekit-cpp-sdk-x64-docker.tar.gz
@@ -311,13 +359,13 @@ jobs:
311359

312360
steps:
313361
- name: Checkout (with submodules)
314-
uses: actions/checkout@v4
362+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
315363
with:
316364
submodules: recursive
317365
fetch-depth: 0
318366

319-
- name: Free disk space (GitHub-hosted runner)
320-
uses: jlumbroso/free-disk-space@v1.3.1
367+
- name: Free disk space
368+
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
321369
with:
322370
tool-cache: false
323371
android: true
@@ -328,7 +376,7 @@ jobs:
328376
swap-storage: true
329377

330378
- name: Set up Docker Buildx
331-
uses: docker/setup-buildx-action@v3
379+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
332380

333381
- name: Build Docker image
334382
run: |
@@ -349,7 +397,7 @@ jobs:
349397
docker save livekit-cpp-sdk:${{ github.sha }} | gzip > livekit-cpp-sdk-arm64-docker.tar.gz
350398
351399
- name: Upload Docker image artifact
352-
uses: actions/upload-artifact@v4
400+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
353401
with:
354402
name: livekit-cpp-sdk-docker-arm64
355403
path: livekit-cpp-sdk-arm64-docker.tar.gz
@@ -362,7 +410,7 @@ jobs:
362410

363411
steps:
364412
- name: Download Docker image artifact
365-
uses: actions/download-artifact@v4
413+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
366414
with:
367415
name: livekit-cpp-sdk-docker-arm64
368416

@@ -371,11 +419,12 @@ jobs:
371419

372420
- name: Build cpp-example-collection against installed SDK
373421
run: |
374-
docker run --rm livekit-cpp-sdk:${{ github.sha }} bash -lc '
422+
docker run -e CPP_EX_REF="${{ env.CPP_EXAMPLE_COLLECTION_REF }}" --rm livekit-cpp-sdk:${{ github.sha }} bash -lc '
375423
set -euxo pipefail
376424
git clone https://github.com/livekit-examples/cpp-example-collection.git /tmp/cpp-example-collection
377425
cd /tmp/cpp-example-collection
378-
git checkout f231c0c75028d1dcf13edcecd369d030d2c7c8d4
426+
git fetch --depth 1 origin "$CPP_EX_REF"
427+
git checkout "$CPP_EX_REF"
379428
cmake -S . -B build -DLIVEKIT_LOCAL_SDK_DIR=/opt/livekit-sdk
380429
cmake --build build --parallel
381430
'
@@ -387,7 +436,7 @@ jobs:
387436

388437
steps:
389438
- name: Download Docker image artifact
390-
uses: actions/download-artifact@v4
439+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
391440
with:
392441
name: livekit-cpp-sdk-docker-x64
393442

@@ -396,11 +445,12 @@ jobs:
396445

397446
- name: Build cpp-example-collection against installed SDK
398447
run: |
399-
docker run --rm livekit-cpp-sdk-x64:${{ github.sha }} bash -lc '
448+
docker run -e CPP_EX_REF="${{ env.CPP_EXAMPLE_COLLECTION_REF }}" --rm livekit-cpp-sdk-x64:${{ github.sha }} bash -lc '
400449
set -euxo pipefail
401450
git clone https://github.com/livekit-examples/cpp-example-collection.git /tmp/cpp-example-collection
402451
cd /tmp/cpp-example-collection
403-
git checkout f231c0c75028d1dcf13edcecd369d030d2c7c8d4
452+
git fetch --depth 1 origin "$CPP_EX_REF"
453+
git checkout "$CPP_EX_REF"
404454
cmake -S . -B build -DLIVEKIT_LOCAL_SDK_DIR=/opt/livekit-sdk
405455
cmake --build build --parallel
406456
'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: License Check
2+
on:
3+
workflow_call: {}
4+
workflow_dispatch: {}
5+
6+
jobs:
7+
license-check:
8+
name: License Check
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
15+
- name: Check License Headers
16+
shell: bash
17+
run: |
18+
set -euo pipefail
19+
20+
search_dirs=()
21+
for dir in src include bridge cpp-example-collection; do
22+
if [[ -d "$dir" ]]; then
23+
search_dirs+=("$dir")
24+
fi
25+
done
26+
27+
if [[ ${#search_dirs[@]} -eq 0 ]]; then
28+
echo "No source directories found to validate."
29+
exit 1
30+
fi
31+
32+
mapfile -t files < <(find "${search_dirs[@]}" -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) | LC_ALL=C sort)
33+
if [[ ${#files[@]} -eq 0 ]]; then
34+
echo "No source files found to validate."
35+
exit 1
36+
fi
37+
38+
failed=0
39+
for file in "${files[@]}"; do
40+
if ! grep -Eq 'Copyright [0-9]{4}(-[0-9]{4})? LiveKit(, Inc\.)?$' "$file"; then
41+
echo "Missing or unexpected copyright header in $file"
42+
failed=1
43+
fi
44+
if ! grep -Fq 'Licensed under the Apache License, Version 2.0' "$file"; then
45+
echo "Missing Apache 2.0 header in $file"
46+
failed=1
47+
fi
48+
done
49+
50+
exit "$failed"

0 commit comments

Comments
 (0)