Skip to content

test-runner-on-vm: allow for hooks - #18

Open
rjbs wants to merge 1 commit into
fastmail:mainfrom
rjbs:generic-hooks
Open

test-runner-on-vm: allow for hooks#18
rjbs wants to merge 1 commit into
fastmail:mainfrom
rjbs:generic-hooks

Conversation

@rjbs

@rjbs rjbs commented Jul 3, 2026

Copy link
Copy Markdown
Member

If you want to do something special in your MR for a given step, you can make one of these programs:

  • hook-before-{stepname}: run this program before, continue no matter what

  • hook-instead-{stepname}: run this program instead of the normal implementation of the step, fail if it exits nonzero

  • hook-before-{stepname}: run this program after the step, continue no matter what

If you want to do something special in your MR for a given step, you can
make one of these programs:

* hook-before-{stepname}: run this program before, continue no matter
  what

* hook-instead-{stepname}: run this program instead of the normal
  implementation of the step, fail if it exits nonzero

* hook-before-{stepname}: run this program after the step, continue no
  matter what
@rjbs
rjbs requested a review from lerlacher-fm July 3, 2026 20:56
@lerlacher-fm

Copy link
Copy Markdown
Contributor

I would have appreciated this being marked as draft as this doesn't even compile. Here's a patch to make it work:

diff --git a/misc/test-runner-on-vm b/misc/test-runner-on-vm
index 71b4e6f..7aa7685 100755
--- a/misc/test-runner-on-vm
+++ b/misc/test-runner-on-vm
@@ -154,21 +154,17 @@ sub run_cmd ($self, $cmd, $desc = $cmd, $arg = undef) {
 }
 
 sub hook_before ($self, $name) {
-  my $name = "/home/mod_perl/hm/bin/ci/hook-before-$name";
+  $name = "/home/mod_perl/hm/bin/ci/hook-before-$name";
   return unless -e $name;
 
-  if (-e $name) {
-    my $rc = $self->run_cmd($cmd, "hook-before-$name", { on_fail => 'ignore' });
-  }
+  my $rc = $self->run_cmd($name, "hook-before-$name", { on_fail => 'ignore' });
 }
 
 sub hook_after ($self, $name) {
-  my $name = "/home/mod_perl/hm/bin/ci/hook-after-$name";
-  return unless -e $name;
+  my $hook_cmd = "/home/mod_perl/hm/bin/ci/hook-after-$name";
+  return unless -e $hook_cmd;
 
-  if (-e $name) {
-    my $rc = $self->run_cmd($cmd, "hook-after-$name", { on_fail => 'ignore' });
-  }
+  my $rc = $self->run_cmd($hook_cmd, "hook-after-$name", { on_fail => 'ignore' });
 }
 
 sub STEP_boot_up ($self) {
@@ -518,10 +514,10 @@ for my $instruction (@instructions) {
   $testproc->hook_before($name);
 
   {
-    my $name = "/home/mod_perl/hm/bin/ci/hook-instead-$name";
+    my $hook_cmd = "/home/mod_perl/hm/bin/ci/hook-instead-$name";
 
     if (-e $name) {
-      $self->run_cmd($cmd, "hook-instead-$name");
+      $testproc->run_cmd($hook_cmd, "hook-instead-$name");
     } else {
       $testproc->$method(@args);
     }

This works but I'd also like to note the number of steps I had to do go through to make this testable locally:

  • symlink misc/test-runner-on-vm into my hm checkout
  • set the CI env vars (export CI_MERGE_REQUEST_SOURCE_PROJECT_PATH=lerlacher/hm and CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=le-plat-3406-oauthrefreshd-crypt-hsm)
  • special box ci-create invocation to use my SSH key (box ci-create -K lerlacher)
  • run rm -rf /tmp/ci* on the test vm to "reset" it enough to allow box ci-run to run again without creating a new box

This is not very ergonomic and took me a bunch of trial and error to figure out. I'd appreciate some documentation for a local test setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants