RunCommand: calculate all the commands to run against before starting

[?]
Dec 8, 2021, 7:36 PM
7FJKVZANSG7N3PCMISLNGVDSPNQ6UWNGNJWUNLVBQBFJW33UGIIQC

Dependencies

  • [2] OAGCZHK6 Allow for precisely one instance of RunCommand plugin
  • [3] 6FVDCTUH RunCommand: test isEnabled, configSectionMatches, and eventMatches
  • [4] 354QHWZ7 RunCommand: move JSON generation to its own function
  • [5] 6ZXL5UOP Add a plugin to execute arbitrary commands when a build finishes
  • [6] GD2WBYPT RunCommand: Return metrics as a float

Change contents

  • edit in src/lib/Hydra/Plugin/RunCommand.pm at line 41
    [4.3]
    [4.3]
    sub fanoutToCommands {
    my ($config, $event, $project, $jobset, $job) = @_;
    my @commands;
    my $cfg = $config->{runcommand};
    my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
    foreach my $conf (@config) {
    my $matcher = $conf->{job} // "*:*:*";
    next unless eventMatches($conf, $event);
    next unless configSectionMatches(
    $matcher,
    $project,
    $jobset,
    $job);
    if (!defined($conf->{command})) {
    warn "<runcommand> section for '$matcher' lacks a 'command' option";
    next;
    }
    push(@commands, {
    matcher => $matcher,
    command => $conf->{command},
    })
    }
    return \@commands;
    }
  • edit in src/lib/Hydra/Plugin/RunCommand.pm at line 133
    [5.846][5.846:847](),[5.847][2.96:216]()
    my $cfg = $self->{config}->{runcommand};
    my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
  • replacement in src/lib/Hydra/Plugin/RunCommand.pm at line 134
    [5.902][5.902:915]()
    my $tmp;
    [5.902]
    [5.915]
    my $commandsToRun = fanoutToCommands(
    $self->{config},
    $event,
    $build->get_column('project'),
    $build->get_column('jobset'),
    $build->get_column('job')
    );
  • replacement in src/lib/Hydra/Plugin/RunCommand.pm at line 142
    [5.916][2.217:299](),[2.299][5.997:1039](),[5.997][5.997:1039](),[5.1039][2.300:337](),[2.337][5.1075:1201](),[5.1075][5.1075:1201](),[5.1201][2.338:433](),[2.433][5.1295:1383](),[5.1295][5.1295:1383](),[5.1383][4.1844:1920](),[4.1920][5.3319:3329](),[5.3319][5.3319:3329]()
    foreach my $conf (@config) {
    next unless eventMatches($conf, $event);
    next unless configSectionMatches(
    $conf->{job} // "*:*:*",
    $build->get_column('project'),
    $build->get_column('jobset'),
    $build->get_column('job'));
    my $command = $conf->{command} // die "<runcommand> section lacks a 'command' option";
    unless (defined $tmp) {
    $tmp = File::Temp->new(SUFFIX => '.json');
    print $tmp encode_json(makeJsonPayload($event, $build)) or die;
    }
    [5.916]
    [5.3329]
    if (@$commandsToRun == 0) {
    # No matching jobs, don't bother generating the JSON
    return;
    }
  • replacement in src/lib/Hydra/Plugin/RunCommand.pm at line 147
    [5.3330][5.3330:3375]()
    $ENV{"HYDRA_JSON"} = $tmp->filename;
    [5.3330]
    [5.3375]
    my $tmp = File::Temp->new(SUFFIX => '.json');
    print $tmp encode_json(makeJsonPayload($event, $build)) or die;
    $ENV{"HYDRA_JSON"} = $tmp->filename;
  • edit in src/lib/Hydra/Plugin/RunCommand.pm at line 151
    [5.3376]
    [5.3376]
    foreach my $commandToRun (@{$commandsToRun}) {
    my $command = $commandToRun->{command};
  • edit in t/plugins/RunCommand/matcher.t at line 134
    [3.4241]
    [3.4241]
    );
    };
    subtest "fanoutToCommands" => sub {
    my $config = {
    runcommand => [
    {
    job => "",
    command => "foo"
    },
    {
    job => "project:*:*",
    command => "bar"
    },
    {
    job => "project:jobset:nomatch",
    command => "baz"
    }
    ]
    };
    is(
    Hydra::Plugin::RunCommand::fanoutToCommands(
    $config,
    "buildFinished",
    "project",
    "jobset",
    "job"
    ),
    [
    {
    matcher => "",
    command => "foo"
    },
    {
    matcher => "project:*:*",
    command => "bar"
    }
    ],
    "fanoutToCommands returns a command per matching job"