mirror of
https://github.com/debpalash/VoiceStudio.git
synced 2026-12-04 01:18:16 +00:00
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.
This commit is contained in:
1 parent
0d675f2efb
commit
0d82aee14b
5 files changed
+159
-1
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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 <old-sha> <new-sha> <gallery-git-dir>
|
||||
|
||||
``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))
|
||||
@@ -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
|
||||
+1
-1
Submodule omnivoice-gallery updated: 22e8e6da80...5908cff554.
@@ -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")
|
||||
Reference in new issue
Block a user