Skip to content

Commit d6da545

Browse files
fix(ci): keep the ExecuTorch pin out of the workflow files (#4748)
Co-authored-by: PyTorch Bot <pytorchbot@users.noreply.github.com>
1 parent bed4401 commit d6da545

8 files changed

Lines changed: 132 additions & 15 deletions

File tree

‎.github/scripts/update_executorch_pin.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
# would leave the version stale while the commit moves. That split is the whole thing these two pins
3737
# exist to prevent, so each site declares what it must contain and each is verified on its own.
3838
_SITE_COORDINATES: dict[str, frozenset[str]] = {
39-
".github/workflows/build_linux.yml": frozenset({"version"}),
40-
".github/workflows/executorch-test-linux.yml": frozenset({"version"}),
39+
# The workflows read the version from these files instead of naming it, so a bump rewrites
40+
# no file under .github/workflows. GitHub refuses a workflow-file push from a credential
41+
# without workflow permission, which is why the daily job could never publish one.
42+
"packaging/executorch_pin.txt": frozenset({"version"}),
43+
"packaging/executorch_range.txt": frozenset({"version"}),
4144
"MODULE.bazel": frozenset({"version", "commit"}),
4245
"docker/MODULE.bazel.docker": frozenset({"version", "commit"}),
4346
"docker/MODULE.bazel.ngc": frozenset({"version", "commit"}),

‎.github/workflows/build_linux.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,11 @@ jobs:
437437
# there. What refuses that is the delegate's own build, which reads the installed
438438
# ExecuTorch's local label and stops unless it names a CUDA build, so the failure is a clear
439439
# message rather than a configure error about a missing extension.
440+
# The version itself comes from the requirement file, so moving the pin to a newer
441+
# nightly changes no file in this directory.
440442
${CONDA_RUN} python -m pip install pyyaml patchelf "wheel>=0.40" \
441443
--extra-index-url "https://download.pytorch.org/whl/nightly/${CU_VERSION}" \
442-
"executorch==1.6.0.dev20260925"
444+
-r packaging/executorch_pin.txt
443445
# Give the companion wheel the same channel/date and CUDA local-version
444446
# suffix as torch-tensorrt, while retaining its independent base version.
445447
main_version="$(sed 's/a0$//' version.txt)"

‎.github/workflows/executorch-test-linux.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ jobs:
6565
6666
# ExecuTorch's CUDA wheels live only on the PyTorch nightly index, so the channel is
6767
# needed. No --pre: a specifier naming a prerelease admits prereleases by itself, and
68-
# --pre would apply to every other requirement in the same command too.
68+
# --pre would apply to every other requirement in the same command too. The version
69+
# comes from the requirement file so a bump changes no file in this directory.
6970
python -m pip install pyyaml "wheel>=0.40" \
7071
--extra-index-url "https://download.pytorch.org/whl/nightly/${CU_VERSION}" \
71-
"executorch==1.6.0.dev20260925"
72+
-r packaging/executorch_pin.txt
7273
7374
# The shared artifact carries the matching core and companion wheels.
7475
shopt -s nullglob
@@ -107,7 +108,7 @@ jobs:
107108
# Resolve the user-facing range without reusing the build's installed pin.
108109
python -m venv "${RUNNER_TEMP}/range-check-venv"
109110
# pin-check: range-ok
110-
"${RUNNER_TEMP}/range-check-venv/bin/python" -m pip install --no-deps --extra-index-url "https://download.pytorch.org/whl/nightly/${CU_VERSION}" "executorch>=1.6.0.dev20260925,<1.7"
111+
"${RUNNER_TEMP}/range-check-venv/bin/python" -m pip install --no-deps --extra-index-url "https://download.pytorch.org/whl/nightly/${CU_VERSION}" -r packaging/executorch_range.txt
111112
112113
source tests/py/utils/ci_helpers.sh
113114
trt_tier_executorch

‎packaging/executorch_pin.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# The pinned ExecuTorch build. This file holds the version so that moving the pin to a newer
4+
# nightly changes no file under .github/workflows: GitHub refuses a workflow-file push from a
5+
# credential without workflow permission, which is why the daily pin update could never publish
6+
# a bump. The workflows pass this with -r and keep their own pip flags, so the index they install
7+
# from stays visible where they call pip.
8+
executorch==1.6.0.dev20260925

‎packaging/executorch_range.txt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# The user-facing ExecuTorch requirement, whose lower bound is the pin. One job resolves this in
4+
# a fresh environment to check the published wheel's own requirement is satisfiable. It lives here
5+
# for the same reason as the exact pin: a bump must not touch a workflow file.
6+
# pin-check: range-ok
7+
executorch>=1.6.0.dev20260925,<1.7

‎tests/py/dynamo/executorch/test_executorch_pin.py‎

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ def _requirement_disagrees(actual: str, expected: str, version: str) -> str:
9090
# Minimum live pin sites, independent of the writer: a removed version no longer matches
9191
# discovery. Additional documentation matches cannot replace these required sites.
9292
_EXPECTED_REQUIREMENT_SITES = {
93-
".github/workflows/build_linux.yml": 1,
94-
".github/workflows/executorch-test-linux.yml": 2,
93+
# The workflows read the version from these files rather than naming it: the exact pin, and
94+
# the user-facing range whose lower bound is the pin.
95+
"packaging/executorch_pin.txt": 1,
96+
"packaging/executorch_range.txt": 1,
9597
"MODULE.bazel": 1,
9698
"docker/MODULE.bazel.docker": 1,
9799
"docker/MODULE.bazel.ngc": 1,
@@ -277,6 +279,22 @@ def _without_trailing_comment(path: str, text: str) -> str:
277279
return text
278280

279281

282+
def _pip_command_around(path: str, number: int) -> str:
283+
"""The whole pip invocation containing line ``number``, following backslash continuations.
284+
285+
A pip command in a workflow is wrapped across lines, so the index flag and the ``-r`` flag
286+
usually sit on different ones. Reading a single line would miss the index.
287+
"""
288+
lines = (REPO_ROOT / path).read_text().splitlines()
289+
start = number - 1
290+
while start > 0 and lines[start - 1].rstrip().endswith("\\"):
291+
start -= 1
292+
end = number - 1
293+
while end + 1 < len(lines) and lines[end].rstrip().endswith("\\"):
294+
end += 1
295+
return "\n".join(lines[start : end + 1])
296+
297+
280298
def _counts_toward_minimum(path: str, number: int) -> bool:
281299
"""Whether a requirement at this line counts toward the per-file minimum.
282300
@@ -382,7 +400,9 @@ def test_runtime_callers_use_the_shared_pinned_build(caller, job):
382400
if s.get("name") == "Build the ExecuTorch runtime wheel"
383401
)
384402
assert step["if"].startswith("${{ inputs.build-executorch-runtime")
385-
assert f'executorch=={_versions()["__executorch_version__"]}' in step["run"]
403+
# The version arrives through the requirement file, so the pin moves without touching this
404+
# workflow. Everything else about the install is still asserted here.
405+
assert "-r packaging/executorch_pin.txt" in step["run"]
386406
assert "${CONDA_RUN} python -m pip install pyyaml" in step["run"]
387407
assert "nightly/${CU_VERSION}" in step["run"]
388408
assert "release-executorch-runtime-wheel-artifacts" not in workflow["jobs"]
@@ -1820,6 +1840,7 @@ def test_the_range_install_runs_in_a_fresh_venv():
18201840
install = next(line for line in after.splitlines() if line.strip())
18211841
argv = shlex.split(install, comments=True)
18221842
assert argv[:5] == [venv + "/bin/python", "-m", "pip", "install", "--no-deps"], argv
1843+
assert "-r" in argv and "packaging/executorch_range.txt" in argv, argv
18231844

18241845

18251846
@pytest.mark.unit
@@ -1963,12 +1984,13 @@ def test_review_cuda_export_is_required(monkeypatch, workflow_name):
19631984

19641985

19651986
@pytest.mark.unit
1966-
def test_review_venv_name_in_comment_does_not_count(monkeypatch):
1987+
def test_the_range_install_must_name_the_fresh_venv(monkeypatch):
19671988
path = REPO_ROOT / ".github/workflows/executorch-test-linux.yml"
19681989
text = path.read_text().replace(
1969-
'"${RUNNER_TEMP}/range-check-venv/bin/python" -m pip install --no-deps',
1970-
"python -m pip install --no-deps # range-check-venv",
1990+
'"${RUNNER_TEMP}/range-check-venv/bin/python" -m pip install',
1991+
"python -m pip install",
19711992
)
1993+
assert text != path.read_text(), "the decoy changed nothing, so this proves nothing"
19721994
original = Path.read_text
19731995
monkeypatch.setattr(
19741996
Path,
@@ -2716,3 +2738,31 @@ def test_the_install_script_leaves_the_companion_out(tmp_path, branch):
27162738
assert not any("executorch_runtime" in name for name in selected), selected
27172739
# Both of the others, including the variant a prefix match would have missed.
27182740
assert len(selected) == 2, selected
2741+
2742+
2743+
@pytest.mark.unit
2744+
def test_every_requirement_file_install_names_the_nightly_channel():
2745+
"""A ``-r`` install carries no requirement literal, so the channel scan cannot see it.
2746+
2747+
That scan walks requirement literals inside pip commands, which is how it checks the index.
2748+
Passing the pin through a file removes the literal from the command, so without this the
2749+
nightly channel could be dropped or pointed at another index and every other guard here
2750+
would still pass. ExecuTorch's CUDA wheels exist only on the nightly index, so an install
2751+
that names another one resolves to a processor-only build.
2752+
"""
2753+
wrong = []
2754+
for line in _git("grep", "-nI", "-e", "-r packaging/executorch_").splitlines():
2755+
path, number, text = line.split(":", 2)
2756+
if _is_source_test(path):
2757+
continue
2758+
command = _pip_command_around(path, int(number))
2759+
if not re.search(
2760+
r"download\.pytorch\.org/whl/nightly/\$\{CU_VERSION\}", command
2761+
):
2762+
wrong.append(
2763+
f"{path}:{number} installs a pinned requirement file without the nightly channel"
2764+
)
2765+
assert not wrong, wrong
2766+
assert _git(
2767+
"grep", "-lI", "-e", "-r packaging/executorch_"
2768+
).strip(), "no requirement-file install found, so this test is not looking"

‎tests/py/dynamo/executorch/test_shared_runtime_workflow.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ def test_shared_build_provisions_tensorrt_metadata(tmp_path, arch, cuda, release
227227
(runtime / "version.txt").write_text("7.4.1\n")
228228
scripts = tmp_path / ".github/scripts"
229229
scripts.mkdir(parents=True)
230+
# pip reads the pinned requirement from this file, so the sandbox needs the real one: a stub
231+
# would let a wrong or missing pin pass here.
232+
packaging = tmp_path / "packaging"
233+
packaging.mkdir(parents=True)
234+
shutil.copy2(
235+
ROOT / "packaging/executorch_pin.txt", packaging / "executorch_pin.txt"
236+
)
230237
step = next(
231238
s
232239
for s in _workflow("build_linux.yml")["jobs"]["build"]["steps"]
@@ -346,6 +353,12 @@ def _assert_device_commands(tmp_path, workflow, failure=""):
346353
helpers = tmp_path / "tests/py/utils/ci_helpers.sh"
347354
helpers.parent.mkdir(parents=True)
348355
helpers.write_text("trt_tier_executorch() { :; }\n")
356+
# Copy the real requirement files rather than stubs, so a wrong or missing pin fails here
357+
# instead of being mocked away. This script installs both the exact pin and the range.
358+
packaging = tmp_path / "packaging"
359+
packaging.mkdir(parents=True)
360+
for name in ("executorch_pin.txt", "executorch_range.txt"):
361+
shutil.copy2(ROOT / "packaging" / name, packaging / name)
349362
dispatcher = bin_dir / "dispatch"
350363
dispatcher.write_text(
351364
f"#!{sys.executable}\n"

‎tests/py/dynamo/executorch/test_update_executorch_pin.py‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,15 @@ def test_write_pins_updates_real_sites_and_is_idempotent(pin_repo):
312312
assert updater.write_pins(new, _COMMIT)
313313
assert updater.read_pin("__executorch_version__") == new
314314
assert updater.read_pin("__executorch_commit__") == _COMMIT
315-
workflow = (pin_repo / ".github/workflows/executorch-test-linux.yml").read_text()
316-
assert f"executorch=={new}" in workflow
317-
assert f"executorch>={new},<{Version(new).major}.1" in workflow
315+
# The pin lives in the requirement files the workflows pass to pip, not in the workflows
316+
# themselves, so a bump rewrites no file under .github/workflows.
317+
assert (
318+
f"executorch=={new}" in (pin_repo / "packaging/executorch_pin.txt").read_text()
319+
)
320+
assert (
321+
f"executorch>={new},<{Version(new).major}.1"
322+
in (pin_repo / "packaging/executorch_range.txt").read_text()
323+
)
318324
before = _contents(pin_repo)
319325
assert not updater.write_pins(new, _COMMIT)
320326
assert _contents(pin_repo) == before
@@ -703,3 +709,30 @@ def test_the_stable_track_warns_that_its_pin_will_not_build(monkeypatch, capsys)
703709
monkeypatch.setattr(updater, "write_pins", lambda version, commit: True)
704710
updater.main(["--track", "stable"])
705711
assert "no CUDA build of ExecuTorch" in capsys.readouterr().err
712+
713+
714+
@pytest.mark.unit
715+
def test_a_bump_rewrites_no_workflow_file(pin_repo):
716+
"""The reason this indirection exists at all.
717+
718+
GitHub refuses a workflow-file push from a credential without workflow permission, and the
719+
token the daily bump runs with does not have it. So a bump that touches any file under
720+
.github/workflows cannot be published, however correct its contents are. Naming the sites
721+
is not enough: a later edit could move the pin back into a workflow and every other test
722+
here would still pass.
723+
"""
724+
assert not [
725+
site for site in updater._PIN_SITES if site.startswith(".github/workflows/")
726+
]
727+
old = updater.read_pin("__executorch_version__")
728+
new = f"{Version(old).major + 1}.0.0.dev1"
729+
assert updater.write_pins(new, _COMMIT)
730+
rewritten = [
731+
str(path.relative_to(pin_repo))
732+
for path in pin_repo.rglob("*")
733+
if path.is_file() and new in path.read_text(errors="ignore")
734+
]
735+
assert rewritten, "the bump wrote nothing, so this proves nothing"
736+
assert not [
737+
path for path in rewritten if path.startswith(".github/workflows/")
738+
], rewritten

0 commit comments

Comments
 (0)