Spaces:
Running on T4
Running on T4
| # Sync tools/validation/ from the upstream GitLab branch. | |
| # | |
| # Run from the repo root: | |
| # bash tools/validation/_sync.sh | |
| # | |
| # After running, review the diff, bump the pin block in | |
| # tools/validation/UPSTREAM.md, and commit. | |
| set -euo pipefail | |
| UPSTREAM_URL="https://gitlab-master.nvidia.com/omniverse/kit-extensions/simready-explorer.git" | |
| UPSTREAM_BRANCH="dev/dloginowski/validation-reporting" | |
| UPSTREAM_PATH="validation" | |
| LOCAL_PATH="tools/validation" | |
| KEEP=(UPSTREAM.md _sync.sh) | |
| if [[ ! -d "${LOCAL_PATH}" ]]; then | |
| echo "expected ${LOCAL_PATH} to exist; are you in the repo root?" >&2 | |
| exit 1 | |
| fi | |
| # Compare current pin to upstream HEAD. | |
| current_pin="$(grep -oE 'upstream_sha:\s*[0-9a-f]+' "${LOCAL_PATH}/UPSTREAM.md" \ | |
| | awk '{print $2}' | head -n1 || true)" | |
| upstream_sha="$(git ls-remote "${UPSTREAM_URL}" "refs/heads/${UPSTREAM_BRANCH}" \ | |
| | awk '{print $1}')" | |
| if [[ -z "${upstream_sha}" ]]; then | |
| echo "could not resolve upstream branch SHA — check network / auth" >&2 | |
| exit 2 | |
| fi | |
| echo "current pin: ${current_pin:-(unset)}" | |
| echo "upstream HEAD: ${upstream_sha}" | |
| if [[ "${current_pin}" == "${upstream_sha}" ]]; then | |
| echo "already in sync — nothing to do" | |
| exit 0 | |
| fi | |
| tmpdir="$(mktemp -d)" | |
| trap 'rm -rf "${tmpdir}"' EXIT | |
| echo ">> shallow-clone upstream" | |
| git clone --depth 50 --branch "${UPSTREAM_BRANCH}" --single-branch \ | |
| "${UPSTREAM_URL}" "${tmpdir}/upstream" >/dev/null | |
| # How many commits ahead of the current pin (best-effort; falls back to "?") | |
| ahead="?" | |
| if [[ -n "${current_pin}" ]]; then | |
| if git -C "${tmpdir}/upstream" cat-file -e "${current_pin}" 2>/dev/null; then | |
| ahead="$(git -C "${tmpdir}/upstream" rev-list --count "${current_pin}..HEAD")" | |
| fi | |
| fi | |
| echo "commits ahead of pin: ${ahead}" | |
| upstream_dir="${tmpdir}/upstream/${UPSTREAM_PATH}" | |
| if [[ ! -d "${upstream_dir}" ]]; then | |
| echo "upstream ${UPSTREAM_PATH}/ missing in branch ${UPSTREAM_BRANCH}" >&2 | |
| exit 3 | |
| fi | |
| echo ">> rsync upstream → ${LOCAL_PATH}" | |
| # Stash KEEP files so rsync --delete doesn't remove them. | |
| keep_stash="$(mktemp -d)" | |
| for f in "${KEEP[@]}"; do | |
| if [[ -f "${LOCAL_PATH}/${f}" ]]; then | |
| cp -p "${LOCAL_PATH}/${f}" "${keep_stash}/${f}" | |
| fi | |
| done | |
| rsync -a --delete "${upstream_dir}/" "${LOCAL_PATH}/" | |
| for f in "${KEEP[@]}"; do | |
| if [[ -f "${keep_stash}/${f}" ]]; then | |
| cp -p "${keep_stash}/${f}" "${LOCAL_PATH}/${f}" | |
| fi | |
| done | |
| rm -rf "${keep_stash}" | |
| echo | |
| echo ">> changes:" | |
| git -c color.ui=always diff --stat -- "${LOCAL_PATH}" | tail -20 || true | |
| cat <<EOF | |
| Sync staged. Next steps: | |
| 1. Bump the pin block in ${LOCAL_PATH}/UPSTREAM.md: | |
| upstream_sha: ${upstream_sha} | |
| synced_at: $(date -u +%Y-%m-%d) | |
| synced_by: \$(git config user.name) | |
| 2. Review the diff: git diff -- ${LOCAL_PATH} | |
| 3. Commit: git add ${LOCAL_PATH} && git commit -m "Sync tools/validation/ from upstream ${upstream_sha:0:12}" | |
| EOF | |