#!/usr/bin/env nu # install-rollback.nu — compensation for install-crate. # Removes the installed binary if it was placed during a now-failed pipeline. def main []: nothing -> nothing { let run_id = ($env | get --ignore-errors PIPELINE_RUN_ID | default "unknown") print $"Compensating install for pipeline run [$run_id]" # The binary name must be deterministic — read from env or derive from cargo metadata let crate_name = ($env | get --ignore-errors STRATUM_CRATE_NAME | default "") if ($crate_name | is-empty) { print "STRATUM_CRATE_NAME not set — skipping install rollback" return } let target = ($nu.home-dir | path join ".local" "bin" $crate_name) if ($target | path exists) { let rm_result = (do { ^rm $target } | complete) if ($rm_result.exit_code != 0) { print $"WARNING: failed to remove ($target): ($rm_result.stderr)" } else { print $"Removed ($target)" } } else { print $"($target) not present — nothing to remove" } }