Skip to content

Commit f97eb43

Browse files
committed
fix(release): prefer rustup run for pinned lockfile sync
1 parent b666509 commit f97eb43

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ YAML_FIXTURES := $(shell find tests/fixtures -type f \( -name '*.yaml' -o -name
2020
SCHEMA_ARTIFACT_VERSION := $(shell tr -d '\r\n' < SCHEMA_VERSION)
2121
SCHEMA_FILE := schemas/envgen.schema.v$(SCHEMA_ARTIFACT_VERSION).json
2222
VERSION_BUMP_SCRIPT := scripts/version_bump.py
23+
RUST_TOOLCHAIN_PIN ?= 1.88.0
2324
HOMEBREW_TAP_SCRIPT := scripts/homebrew/tap_release.py
2425
HOMEBREW_SOURCE_REPO ?= smorinlabs/envgen
2526
HOMEBREW_TAP_REPO ?= smorinlabs/homebrew-tap
@@ -180,11 +181,19 @@ check-security: check-tools-security ## Security/dependency checks
180181

181182
.PHONY: sync-lockfile
182183
sync-lockfile: ## Regenerate Cargo.lock using pinned Rust toolchain (1.88.0)
183-
cargo +1.88.0 generate-lockfile
184+
@if command -v rustup >/dev/null 2>&1; then \
185+
rustup run $(RUST_TOOLCHAIN_PIN) cargo generate-lockfile && exit 0; \
186+
echo "WARN: rustup run $(RUST_TOOLCHAIN_PIN) cargo generate-lockfile failed; retrying with cargo +$(RUST_TOOLCHAIN_PIN)." >&2; \
187+
fi; \
188+
cargo +$(RUST_TOOLCHAIN_PIN) generate-lockfile
184189

185190
.PHONY: check-lockfile
186191
check-lockfile: ## Validate lockfile parity using pinned Rust toolchain (1.88.0)
187-
cargo +1.88.0 check --locked
192+
@if command -v rustup >/dev/null 2>&1; then \
193+
rustup run $(RUST_TOOLCHAIN_PIN) cargo check --locked && exit 0; \
194+
echo "WARN: rustup run $(RUST_TOOLCHAIN_PIN) cargo check --locked failed; retrying with cargo +$(RUST_TOOLCHAIN_PIN)." >&2; \
195+
fi; \
196+
cargo +$(RUST_TOOLCHAIN_PIN) check --locked
188197

189198
.PHONY: check-release
190199
check-release: ## Release readiness checks

scripts/version_bump.py

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import re
1414
import shlex
15+
import shutil
1516
import subprocess
1617
import sys
1718
import tomllib
@@ -54,7 +55,7 @@
5455
RELEASE_WORKFLOW_URL = (
5556
"https://github.com/smorinlabs/envgen/actions/workflows/release.yml"
5657
)
57-
LOCKFILE_SYNC_ARGS = ["cargo", "+1.88.0", "generate-lockfile"]
58+
PINNED_RUST_TOOLCHAIN = "1.88.0"
5859

5960

6061
class BumpError(RuntimeError):
@@ -441,18 +442,62 @@ def run_git_command(args: list[str], dry_run: bool) -> None:
441442
fail(f"Command failed: {quoted}")
442443

443444

445+
def lockfile_sync_command_candidates() -> list[list[str]]:
446+
commands: list[list[str]] = []
447+
if shutil.which("rustup"):
448+
commands.append(
449+
["rustup", "run", PINNED_RUST_TOOLCHAIN, "cargo", "generate-lockfile"]
450+
)
451+
452+
if shutil.which("cargo"):
453+
commands.append(["cargo", f"+{PINNED_RUST_TOOLCHAIN}", "generate-lockfile"])
454+
455+
if not commands:
456+
fail(
457+
"Could not find rustup or cargo to synchronize Cargo.lock.\n"
458+
"Install Rust and rerun: make sync-lockfile"
459+
)
460+
461+
# Keep deterministic attempt order while removing accidental duplicates.
462+
deduped: list[list[str]] = []
463+
seen: set[tuple[str, ...]] = set()
464+
for command in commands:
465+
key = tuple(command)
466+
if key in seen:
467+
continue
468+
seen.add(key)
469+
deduped.append(command)
470+
return deduped
471+
472+
444473
def sync_cargo_lockfile(dry_run: bool) -> None:
445-
command = shlex.join(LOCKFILE_SYNC_ARGS)
474+
commands = lockfile_sync_command_candidates()
475+
command = shlex.join(commands[0])
446476
if dry_run:
447477
print(f"[dry-run] would run: {command}")
478+
if len(commands) > 1:
479+
print(f"[dry-run] fallback command: {shlex.join(commands[1])}")
448480
return
449481

450-
result = subprocess.run(LOCKFILE_SYNC_ARGS, cwd=ROOT, check=False)
451-
if result.returncode != 0:
452-
fail(
453-
"Failed to synchronize Cargo.lock after crate version bump.\n"
454-
"Run: make sync-lockfile"
455-
)
482+
failures: list[str] = []
483+
for index, args in enumerate(commands):
484+
quoted = shlex.join(args)
485+
if index > 0:
486+
print(
487+
f"WARNING: lockfile sync failed; retrying with fallback: {quoted}",
488+
file=sys.stderr,
489+
)
490+
491+
result = subprocess.run(args, cwd=ROOT, check=False)
492+
if result.returncode == 0:
493+
return
494+
failures.append(f"{quoted} (exit {result.returncode})")
495+
496+
fail(
497+
"Failed to synchronize Cargo.lock after crate version bump.\n"
498+
f"Tried:\n - {'\n - '.join(failures)}\n"
499+
"Run: make sync-lockfile"
500+
)
456501

457502

458503
def create_tag(tag_name: str, message: str, dry_run: bool) -> None:

0 commit comments

Comments
 (0)