A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix: keep a comment already on a uses: line when pinning the tag (Fixes #1463) (#1479)
EllaSharakanskifbe815f54400
diff --git a/scripts/oss/pin_actions.py b/scripts/oss/pin_actions.pyindex f8bd32950..52cd97503 100755--- a/scripts/oss/pin_actions.py+++ b/scripts/oss/pin_actions.py@@ -3,7 +3,8 @@# dependencies = []# ///"""Pin every `uses: owner/repo@ref` in .github/workflows/*.yml to the ref's full commit SHA, keeping the ref as a-trailing comment. Resolves with a read-only `gh api` GET. A tag can be moved by its owner; a SHA cannot (no_human+trailing comment. Anything already after the ref on the line, such as a note of why that action is used, is kept+after the ref. Resolves with a read-only `gh api` GET. A tag can be moved by its owner; a SHA cannot (no_human5f99b7af3: unpinned third-party downloads in the release build).Usage: uv run scripts/oss/pin_actions.py"""@@ -34,7 +35,9 @@ def pin_text(text: str, resolve: Callable[[str, str], str]) -> str:m = USES.match(line.rstrip("\n"))if m and not re.fullmatch(r"[0-9a-f]{40}", m["ref"]):sha = resolve(m["action"], m["ref"])- line = f"{m['lead']}{m['action']}@{sha} # {m['ref']}\n"+ # Whatever already followed the ref is kept after it, so a note on the line survives the pin (#1463).+ kept = m["rest"].strip()+ line = f"{m['lead']}{m['action']}@{sha} # {m['ref']}{' ' + kept if kept else ''}\n"lines.append(line)return "".join(lines)diff --git a/scripts/oss/tests/test_pin_actions.py b/scripts/oss/tests/test_pin_actions.pyindex 42c0dd873..3502ab407 100644--- a/scripts/oss/tests/test_pin_actions.py+++ b/scripts/oss/tests/test_pin_actions.py@@ -13,3 +13,18 @@ def test_tags_are_replaced_by_sha_with_the_tag_kept_as_a_comment():def test_already_pinned_lines_are_left_alone():text = f" - uses: actions/checkout@{SHA} # v4\n"assert pin_actions.pin_text(text, lambda repo, ref: (_ for _ in ()).throw(AssertionError)) == text+++def test_a_comment_already_on_the_line_is_kept_with_the_ref():+ # #1463: pin_text rebuilt the line from the lead, action, SHA and ref, so a note already on the line was lost.+ # The ref stays where it has always been, right after the SHA, and the existing comment follows it unchanged.+ text = " - uses: actions/checkout@v4 # keep: checkout needs credentials\n"+ out = pin_actions.pin_text(text, lambda repo, ref: SHA)+ assert out == f" - uses: actions/checkout@{SHA} # v4 # keep: checkout needs credentials\n"+++def test_trailing_whitespace_after_the_ref_does_not_become_a_comment():+ # The no-comment line must still come out exactly as before, with no trailing space.+ text = " - uses: actions/checkout@v4 \n"+ out = pin_actions.pin_text(text, lambda repo, ref: SHA)+ assert out == f" - uses: actions/checkout@{SHA} # v4\n"