|
| 1 | +# Copyright 2026 LiveKit, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Test one selective capture bundle |
| 16 | +description: Restore, build, verify, cache, and release one source variant's Cargo output. |
| 17 | +inputs: |
| 18 | + preset: |
| 19 | + description: SDK build preset without tests or examples (debug or release). |
| 20 | + default: release |
| 21 | + sources: |
| 22 | + description: Comma-separated capture sources for this variant. |
| 23 | + required: true |
| 24 | + verify-pixel-sources: |
| 25 | + description: Require successful GPU source creation on a prepared runner. |
| 26 | + default: 'false' |
| 27 | + macos-arch: |
| 28 | + description: Optional macOS architecture override. |
| 29 | + default: '' |
| 30 | +runs: |
| 31 | + using: composite |
| 32 | + steps: |
| 33 | + - name: Identify feature-specific Cargo cache |
| 34 | + id: variant |
| 35 | + shell: bash |
| 36 | + env: |
| 37 | + VARIANT_SOURCES: ${{ inputs.sources }} |
| 38 | + VARIANT_PRESET: ${{ inputs.preset }} |
| 39 | + VARIANT_ARCH: ${{ inputs.macos-arch }} |
| 40 | + VARIANT_CONFIG_HASH: ${{ hashFiles('CMakeLists.txt', 'build.sh', 'build.cmd', '.github/actions/setup-capture/action.yml', '.github/actions/test-capture-variant/action.yml') }} |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | + variant_python=python |
| 44 | + if ! command -v "$variant_python" >/dev/null 2>&1; then variant_python=python3; fi |
| 45 | + "$variant_python" - <<'PYCODE' |
| 46 | + import hashlib |
| 47 | + import os |
| 48 | + import pathlib |
| 49 | + import subprocess |
| 50 | + import time |
| 51 | + sources = sorted(set(os.environ["VARIANT_SOURCES"].split(","))) |
| 52 | + if not sources or any(source not in {"clock", "gstreamer", "pattern"} for source in sources): |
| 53 | + raise SystemExit("Invalid selective capture source set") |
| 54 | + features = ",".join("capture-" + source for source in sources) |
| 55 | + feature_hash = hashlib.sha256(features.encode()).hexdigest()[:16] |
| 56 | + root = pathlib.Path(os.environ["CARGO_TARGET_DIR"]).resolve() |
| 57 | + cargo_dir = root / ("cpp-" + feature_hash) |
| 58 | + rust_sha = subprocess.check_output(["git", "-C", "client-sdk-rust", "rev-parse", "HEAD"], text=True).strip() |
| 59 | + key = "-".join(["capture-variant", os.environ["RUNNER_OS"], os.environ.get("ImageOS", os.environ["RUNNER_OS"]), |
| 60 | + os.environ["RUNNER_ARCH"], os.environ["VARIANT_ARCH"] or "native", |
| 61 | + os.environ["VARIANT_PRESET"], feature_hash, |
| 62 | + os.environ["VARIANT_CONFIG_HASH"], rust_sha]) |
| 63 | + with open(os.environ["GITHUB_OUTPUT"], "a") as output: |
| 64 | + output.write(f"cargo-dir={cargo_dir.as_posix()}\nkey={key}\n") |
| 65 | + output.write(f"started-at={time.monotonic()}\n") |
| 66 | + output.write("bundle-dir=sdk-out/capture-" + "-".join(sources) + "\n") |
| 67 | + PYCODE |
| 68 | + - name: Restore variant Cargo cache |
| 69 | + id: cache |
| 70 | + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
| 71 | + with: |
| 72 | + path: ${{ steps.variant.outputs.cargo-dir }} |
| 73 | + key: ${{ steps.variant.outputs.key }} |
| 74 | + - name: Build variant |
| 75 | + uses: ./.github/actions/build-sdk |
| 76 | + with: |
| 77 | + preset: ${{ inputs.preset }} |
| 78 | + capture: ${{ inputs.sources }} |
| 79 | + bundle-dir: ${{ steps.variant.outputs.bundle-dir }} |
| 80 | + macos-arch: ${{ inputs.macos-arch }} |
| 81 | + - name: Test installed variant |
| 82 | + uses: ./.github/actions/test-sdk-bundle |
| 83 | + with: |
| 84 | + bundle-dir: ${{ steps.variant.outputs.bundle-dir }} |
| 85 | + expected-sources: ${{ inputs.sources }} |
| 86 | + verify-pixel-sources: ${{ inputs.verify-pixel-sources }} |
| 87 | + build-type: ${{ inputs.preset == 'debug' && 'Debug' || 'Release' }} |
| 88 | + macos-arch: ${{ inputs.macos-arch }} |
| 89 | + - name: Save verified variant Cargo cache |
| 90 | + if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && steps.cache.outputs.cache-hit != 'true' |
| 91 | + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
| 92 | + with: |
| 93 | + path: ${{ steps.variant.outputs.cargo-dir }} |
| 94 | + key: ${{ steps.variant.outputs.key }} |
| 95 | + # The installed bundle owns copies of the libraries. Releasing the Rust |
| 96 | + # build tree bounds disk use across the sequence of feature configurations. |
| 97 | + - name: Release temporary Cargo output |
| 98 | + if: always() && steps.variant.outputs.cargo-dir != '' |
| 99 | + shell: bash |
| 100 | + env: |
| 101 | + VARIANT_CARGO_DIR: ${{ steps.variant.outputs.cargo-dir }} |
| 102 | + VARIANT_SOURCES: ${{ inputs.sources }} |
| 103 | + VARIANT_STARTED_AT: ${{ steps.variant.outputs.started-at }} |
| 104 | + VARIANT_CACHE_HIT: ${{ steps.cache.outputs.cache-hit }} |
| 105 | + run: | |
| 106 | + set -euo pipefail |
| 107 | + variant_python=python |
| 108 | + if ! command -v "$variant_python" >/dev/null 2>&1; then variant_python=python3; fi |
| 109 | + "$variant_python" - <<'PYCODE' |
| 110 | + import os |
| 111 | + import pathlib |
| 112 | + import shutil |
| 113 | + import time |
| 114 | + path = pathlib.Path(os.environ["VARIANT_CARGO_DIR"]).resolve() |
| 115 | + root = pathlib.Path(os.environ["CARGO_TARGET_DIR"]).resolve() |
| 116 | + if path.parent != root or not path.name.startswith("cpp-"): |
| 117 | + raise SystemExit("Refusing to remove a path outside the feature-specific Cargo root") |
| 118 | + if path.exists(): |
| 119 | + shutil.rmtree(path) |
| 120 | + elapsed = time.monotonic() - float(os.environ["VARIANT_STARTED_AT"]) |
| 121 | + cache = "hit" if os.environ["VARIANT_CACHE_HIT"] == "true" else "miss" |
| 122 | + with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as summary: |
| 123 | + summary.write(f"Capture `{os.environ['VARIANT_SOURCES']}`: {elapsed:.0f}s; Cargo cache {cache}.\n\n") |
| 124 | + PYCODE |
0 commit comments