Repository navigation
tool: update-rust-sdk.sh script, update rust hash #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stephen-derosa
wants to merge
2
commits into
main
Choose a base branch
from
sderosa/update-commit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Copyright 2026 LiveKit | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" | ||
| repo_root="$(cd "${script_dir}/.." && pwd -P)" | ||
| examples_repo="livekit-examples/cpp-example-collection" | ||
| examples_remote="https://github.com/${examples_repo}.git" | ||
| default_branch="main" | ||
|
|
||
| usage() { | ||
| cat <<'EOF' | ||
| Usage: ./scripts/update-cpp-example-collection.sh [--hash HASH] | ||
|
|
||
| Update the cpp-example-collection submodule used by the C++ SDK. | ||
|
|
||
| Options: | ||
| --hash HASH | ||
| Use the specified examples commit. You can use a short or full SHA-1 | ||
| hash. | ||
| -h, --help | ||
| Show this help and exit. | ||
|
|
||
| When --hash is omitted, the script uses the most recent commit on the main | ||
| branch of livekit-examples/cpp-example-collection. | ||
| EOF | ||
| } | ||
|
|
||
| requested_hash="" | ||
| hash_provided=false | ||
|
|
||
| while (($#)); do | ||
| case "$1" in | ||
| --hash) | ||
| shift | ||
| if (($# == 0)); then | ||
| echo "ERROR: --hash requires a value" >&2 | ||
| exit 2 | ||
| fi | ||
| requested_hash="$1" | ||
| hash_provided=true | ||
| shift | ||
| ;; | ||
| --hash=*) | ||
| requested_hash="${1#--hash=}" | ||
| hash_provided=true | ||
| shift | ||
| ;; | ||
| -h|--help) | ||
| usage | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| echo "ERROR: unknown argument: $1" >&2 | ||
| usage >&2 | ||
| exit 2 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [[ "$hash_provided" == true && ! "$requested_hash" =~ ^[0-9a-fA-F]{7,40}$ ]]; then | ||
| echo "ERROR: --hash must be a 7- to 40-character hexadecimal Git SHA-1 hash" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| # Shared checkout logic keeps the two dependency updaters consistent. | ||
| source "${script_dir}/update-submodule-common.sh" | ||
| check_update_prerequisites | ||
|
|
||
| fetch_ref="" | ||
| if [[ "$hash_provided" == false ]]; then | ||
| fetch_ref="refs/heads/${default_branch}" | ||
| fi | ||
| update_submodule cpp-example-collection "$examples_remote" "$fetch_ref" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Copyright 2026 LiveKit | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" | ||
| repo_root="$(cd "${script_dir}/.." && pwd -P)" | ||
| rust_repo="livekit/client-sdk-rust" | ||
| rust_remote="https://github.com/${rust_repo}.git" | ||
|
|
||
| usage() { | ||
| cat <<'EOF' | ||
| Usage: ./scripts/update-rust-sdk.sh [--hash HASH] | ||
|
|
||
| Update the client-sdk-rust submodule used by the C++ SDK. | ||
|
|
||
| Options: | ||
| --hash HASH | ||
| Use the specified Rust SDK commit. You can use a short or full SHA-1 | ||
| hash. | ||
| -h, --help | ||
| Show this help and exit. | ||
|
|
||
| When --hash is omitted, the script uses the commit tagged by the most recently | ||
| published, non-draft GitHub release (including prereleases) in | ||
| livekit/client-sdk-rust (requires gh). | ||
| EOF | ||
| } | ||
|
|
||
| requested_hash="" | ||
| hash_provided=false | ||
|
|
||
| while (($#)); do | ||
| case "$1" in | ||
| --hash) | ||
| shift | ||
| if (($# == 0)); then | ||
| echo "ERROR: --hash requires a value" >&2 | ||
| exit 2 | ||
| fi | ||
| requested_hash="$1" | ||
| hash_provided=true | ||
| shift | ||
| ;; | ||
| --hash=*) | ||
| requested_hash="${1#--hash=}" | ||
| hash_provided=true | ||
| shift | ||
| ;; | ||
| -h|--help) | ||
| usage | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| echo "ERROR: unknown argument: $1" >&2 | ||
| usage >&2 | ||
| exit 2 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [[ "$hash_provided" == true && ! "$requested_hash" =~ ^[0-9a-fA-F]{7,40}$ ]]; then | ||
| echo "ERROR: --hash must be a 7- to 40-character hexadecimal Git SHA-1 hash" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| # Shared checkout logic keeps the two dependency updaters consistent. | ||
| source "${script_dir}/update-submodule-common.sh" | ||
| check_update_prerequisites | ||
|
|
||
| if [[ "$hash_provided" == false ]]; then | ||
| if ! command -v gh >/dev/null 2>&1; then | ||
| echo "ERROR: gh not found in PATH; install GitHub CLI or provide --hash" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "==> Finding the most recently published Rust SDK release" | ||
| # Sort across every page by publication time, including prereleases. API | ||
| # list order and GitHub's designated "latest" release are different concepts. | ||
| release_tag="$(gh api --hostname github.com --paginate --slurp \ | ||
| "repos/${rust_repo}/releases?per_page=100" \ | ||
| --jq '[.[][] | select(.draft == false and .published_at != null)] | | ||
| sort_by(.published_at, .id) | last | .tag_name // empty')" | ||
| if [[ -z "$release_tag" ]]; then | ||
| echo "ERROR: no published release found for ${rust_repo}" >&2 | ||
| exit 1 | ||
| fi | ||
| git check-ref-format "refs/tags/${release_tag}" >/dev/null | ||
| fetch_ref="refs/tags/${release_tag}" | ||
| echo "==> Selected release: ${release_tag}" | ||
| else | ||
| fetch_ref="" | ||
| fi | ||
|
|
||
| update_submodule client-sdk-rust "$rust_remote" "$fetch_ref" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Copyright 2026 LiveKit | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Internal helpers sourced by update-rust-sdk.sh and | ||
| # update-cpp-example-collection.sh. Requires Bash 3.2 or newer. | ||
|
|
||
| check_update_prerequisites() { | ||
| if ! command -v git >/dev/null 2>&1; then | ||
| echo "ERROR: git not found in PATH" >&2 | ||
| exit 1 | ||
| fi | ||
| local top_level | ||
| top_level="$(git -C "$repo_root" rev-parse --show-toplevel)" | ||
| if [[ "$(cd "$top_level" && pwd -P)" != "$repo_root" ]]; then | ||
| echo "ERROR: ${repo_root} is not the SDK Git worktree root" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| require_clean_submodule() { | ||
| local directory="$1" | ||
| local changes | ||
| # Explicitly override submodule.*.ignore and diff.ignoreSubmodules. This | ||
| # includes nested HEAD changes, staged edits, and untracked files. | ||
| changes="$(git -C "$directory" status --porcelain --untracked-files=all \ | ||
| --ignore-submodules=none)" | ||
| if [[ -n "$changes" ]]; then | ||
| echo "ERROR: ${directory} has local changes (possibly in nested submodules)." >&2 | ||
| echo "Commit, stash, or move them before updating:" >&2 | ||
| printf '%s\n' "$changes" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| update_submodule() { | ||
| local name="$1" remote="$2" fetch_ref="$3" | ||
| local directory="${repo_root}/${name}" | ||
| local resolved_hash current_hash | ||
| local fetch_options=(--no-tags) | ||
|
|
||
| if [[ -e "${directory}/.git" ]]; then | ||
| require_clean_submodule "$directory" | ||
| else | ||
| echo "==> Initializing ${name}" | ||
| git -C "$repo_root" submodule update --init --checkout -- "$name" | ||
| require_clean_submodule "$directory" | ||
| fi | ||
|
|
||
| echo "==> Fetching ${name} from ${remote}" | ||
| # Use the same authoritative repository for resolution and fetching, even | ||
| # when a developer's origin points to a fork. Leave their remotes unchanged. | ||
| if [[ "$hash_provided" == false ]]; then | ||
| git -C "$directory" fetch --quiet --no-tags "$remote" "$fetch_ref" | ||
| resolved_hash="$(git -C "$directory" rev-parse --verify 'FETCH_HEAD^{commit}')" | ||
| else | ||
| requested_hash="$(printf '%s' "$requested_hash" | tr '[:upper:]' '[:lower:]')" | ||
| if [[ ${#requested_hash} -lt 40 ]] || | ||
| ! git -C "$directory" fetch --quiet --no-tags "$remote" "$requested_hash"; then | ||
| # Abbreviated hashes cannot be fetched directly. Fetch all branch/tag | ||
| # objects without updating local branches or overwriting local tags. | ||
| if [[ "$(git -C "$directory" rev-parse --is-shallow-repository)" == true ]]; then | ||
| fetch_options+=(--unshallow) | ||
| fi | ||
| git -C "$directory" fetch --quiet "${fetch_options[@]}" "$remote" \ | ||
| '+refs/heads/*:refs/sdk-update/heads/*' '+refs/tags/*:refs/sdk-update/tags/*' | ||
| fi | ||
| if ! resolved_hash="$(git -C "$directory" rev-parse --verify "${requested_hash}^{commit}" 2>/dev/null)" || | ||
| [[ "$resolved_hash" != "$requested_hash"* ]]; then | ||
| echo "ERROR: '${requested_hash}' does not unambiguously identify a ${name} commit" >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| current_hash="$(git -C "$directory" rev-parse HEAD)" | ||
| echo "==> Selected ${name}: ${current_hash} -> ${resolved_hash}" | ||
| # Failures here can leave a partial update. Do not attempt a destructive | ||
| # rollback; show the developer exactly what needs inspection and retrying. | ||
| trap 'echo "ERROR: Update incomplete. Inspect git status and git submodule status --recursive; fix the error and rerun the updater. No changes were staged or committed." >&2' ERR | ||
| git -C "$directory" checkout --quiet --no-overwrite-ignore --detach "$resolved_hash" | ||
| git -C "$directory" submodule sync --recursive | ||
| git -C "$directory" submodule update --init --recursive --checkout | ||
| trap - ERR | ||
|
|
||
| echo "==> Done. Review with: git diff --submodule=log -- ${name}" | ||
| echo "==> Stage when ready: git add -- ${name}" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
git add -- <submodule>is proper