From 0d82aee14bbd8a911246d17a6a9ad84b8a02cb5b Mon Sep 17 00:00:00 2001 From: debpalash <4178343+debpalash@users.noreply.github.com> Date: Mon, 26 Oct 2026 03:56:54 +0530 Subject: [PATCH] fix(gallery): restore the gallery pin and stop stale submodules reverting it #3447 committed a stale omnivoice-gallery pointer and moved the pin back from the #3438 bump to the seed commit. Pin the gallery's current main (World Voices, community voices, added_at) and fail any PR that moves the pin backwards or onto a commit that is not on the gallery's main. --- .github/CONTRIBUTING.md | 5 +++ .github/scripts/gallery_pin.py | 55 +++++++++++++++++++++++++++ .github/workflows/gallery-pin.yml | 36 ++++++++++++++++++ omnivoice-gallery | 2 +- tests/test_gallery_pin.py | 62 +++++++++++++++++++++++++++++++ 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/gallery_pin.py create mode 100644 .github/workflows/gallery-pin.yml create mode 100644 tests/test_gallery_pin.py diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 1f791031d..5783fc0ae 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -411,6 +411,11 @@ hard rules from the first prompt. ## Quality gates your PR must pass +- **Gallery pin:** a PR that changes the `omnivoice-gallery` submodule must + move it forward along the gallery's `main` (`.github/workflows/gallery-pin.yml`). + If it fails on a PR that never meant to touch the gallery, the checkout had a + stale submodule: run `git submodule update omnivoice-gallery` and drop that + change from the commit. - **First CI run from a fork:** a pull request from a fork waits for a maintainer to approve it (the `external-pr` environment) before CI starts. Branches in this repository start at once. diff --git a/.github/scripts/gallery_pin.py b/.github/scripts/gallery_pin.py new file mode 100644 index 000000000..be05598c5 --- /dev/null +++ b/.github/scripts/gallery_pin.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +"""Refuse a pull request that moves the ``omnivoice-gallery`` pin backwards. + +A commit made in a checkout whose submodule was never updated records the +stale commit as the new pin: #3447, a docs-only change, silently reverted the +gallery from the #3438 bump to the original seed commit. Nothing failed, because +nothing looked. This looks: + +- the new pin must be on the gallery's ``main`` (no unmerged branch commits); +- it must descend from the old pin (forward only — a deliberate rollback is a + revert in the gallery repo, not a stale pointer here). + + python .github/scripts/gallery_pin.py + +``gallery-git-dir`` is a clone of the gallery with ``main`` fetched. +""" +from __future__ import annotations + +import subprocess +import sys + + +def _git(repo: str, *args: str) -> int: + return subprocess.run(["git", "-C", repo, *args], capture_output=True).returncode + + +def check(old: str, new: str, repo: str, main_ref: str = "origin/main") -> str | None: + """Return why the move is refused, or ``None`` when it is fine.""" + if old == new: + return None + if _git(repo, "cat-file", "-e", f"{new}^{{commit}}") != 0: + return f"the new pin {new} is not a commit in the gallery repository" + if _git(repo, "merge-base", "--is-ancestor", new, main_ref) != 0: + return f"the new pin {new} is not on the gallery's main branch" + if _git(repo, "merge-base", "--is-ancestor", old, new) != 0: + return ( + f"the pin moves backwards ({old[:9]} -> {new[:9]}). This is usually a stale " + "submodule committed by accident: run `git submodule update omnivoice-gallery` " + "and drop the pointer change, or bump it to the gallery's current main." + ) + return None + + +def main(argv: list[str]) -> int: + old, new, repo = argv[1:4] + problem = check(old, new, repo) + if problem: + print(f"::error file=omnivoice-gallery::{problem}") + return 1 + print(f"omnivoice-gallery pin {old[:9]} -> {new[:9]}: ok") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main(sys.argv)) diff --git a/.github/workflows/gallery-pin.yml b/.github/workflows/gallery-pin.yml new file mode 100644 index 000000000..7f7057c2c --- /dev/null +++ b/.github/workflows/gallery-pin.yml @@ -0,0 +1,36 @@ +name: Gallery pin + +# Fails a PR that moves the omnivoice-gallery submodule backwards or onto a +# commit that is not on the gallery's main — the stale-submodule accident that +# reverted the pin in #3447 (.github/scripts/gallery_pin.py). +on: + pull_request: + paths: + - "omnivoice-gallery" + - ".gitmodules" + - ".github/scripts/gallery_pin.py" + - ".github/workflows/gallery-pin.yml" + +permissions: + contents: read + +jobs: + pin: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + - name: Pin only moves forward along gallery main + env: + BASE: ${{ github.event.pull_request.base.sha }} + run: | + old=$(git rev-parse "$BASE:omnivoice-gallery") + new=$(git rev-parse "HEAD:omnivoice-gallery") + url=$(git config -f .gitmodules submodule.omnivoice-gallery.url) + git clone -q --bare --filter=blob:none "$url" gallery.git + git -C gallery.git fetch -q origin '+refs/heads/main:refs/remotes/origin/main' 2>/dev/null \ + || git -C gallery.git update-ref refs/remotes/origin/main refs/heads/main + python3 .github/scripts/gallery_pin.py "$old" "$new" gallery.git diff --git a/omnivoice-gallery b/omnivoice-gallery index 22e8e6da8..5908cff55 160000 --- a/omnivoice-gallery +++ b/omnivoice-gallery @@ -1 +1 @@ -Subproject commit 22e8e6da806fb1904a75db99adb1759832b6ebd0 +Subproject commit 5908cff55421b17ab585dd8873c8b16bd09b9359 diff --git a/tests/test_gallery_pin.py b/tests/test_gallery_pin.py new file mode 100644 index 000000000..df5bda60c --- /dev/null +++ b/tests/test_gallery_pin.py @@ -0,0 +1,62 @@ +"""The gallery submodule pin may only move forward along the gallery's main. + +#3447 committed a stale submodule and reverted the pin from the #3438 bump to +the seed commit; these build a tiny gallery history and replay that move. +""" +import importlib.util +import subprocess +from pathlib import Path + +_SPEC = importlib.util.spec_from_file_location( + "gallery_pin", Path(__file__).resolve().parents[1] / ".github" / "scripts" / "gallery_pin.py" +) +gallery_pin = importlib.util.module_from_spec(_SPEC) +_SPEC.loader.exec_module(gallery_pin) + + +def _git(repo, *args): + return subprocess.run( + ["git", "-C", str(repo), "-c", "user.name=t", "-c", "user.email=t@t", *args], + check=True, capture_output=True, text=True, + ).stdout.strip() + + +def _repo(tmp_path): + repo = tmp_path / "gallery" + repo.mkdir() + _git(repo, "init", "-q", "-b", "main") + shas = [] + for n in range(3): + (repo / "manifest.json").write_text(str(n)) + _git(repo, "add", ".") + _git(repo, "commit", "-q", "-m", f"c{n}") + shas.append(_git(repo, "rev-parse", "HEAD")) + _git(repo, "checkout", "-q", "-b", "side", shas[1]) + (repo / "x").write_text("x") + _git(repo, "add", ".") + _git(repo, "commit", "-q", "-m", "side") + side = _git(repo, "rev-parse", "HEAD") + _git(repo, "checkout", "-q", "main") + return repo, shas, side + + +def test_forward_move_on_main_passes(tmp_path): + repo, (seed, mid, tip), _ = _repo(tmp_path) + assert gallery_pin.check(seed, tip, str(repo), "main") is None + assert gallery_pin.check(tip, tip, str(repo), "main") is None + + +def test_stale_pointer_moving_backwards_is_refused(tmp_path): + repo, (seed, mid, tip), _ = _repo(tmp_path) + problem = gallery_pin.check(tip, seed, str(repo), "main") + assert problem and "backwards" in problem + + +def test_unmerged_branch_commit_is_refused(tmp_path): + repo, (seed, mid, tip), side = _repo(tmp_path) + assert "not on the gallery's main" in gallery_pin.check(seed, side, str(repo), "main") + + +def test_unknown_commit_is_refused(tmp_path): + repo, (seed, mid, tip), _ = _repo(tmp_path) + assert "not a commit" in gallery_pin.check(seed, "f" * 40, str(repo), "main")