RunCommand: calculate all the commands to run against before starting
[?]
Dec 8, 2021, 7:36 PM
7FJKVZANSG7N3PCMISLNGVDSPNQ6UWNGNJWUNLVBQBFJW33UGIIQCDependencies
- [2]
OAGCZHK6Allow for precisely one instance of RunCommand plugin - [3]
6FVDCTUHRunCommand: test isEnabled, configSectionMatches, and eventMatches - [4]
354QHWZ7RunCommand: move JSON generation to its own function - [5]
6ZXL5UOPAdd a plugin to execute arbitrary commands when a build finishes - [6]
GD2WBYPTRunCommand: Return metrics as a float
Change contents
- edit in src/lib/Hydra/Plugin/RunCommand.pm at line 41
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
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
my $tmp;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;}if (@$commandsToRun == 0) {# No matching jobs, don't bother generating the JSONreturn;} - replacement in src/lib/Hydra/Plugin/RunCommand.pm at line 147
$ENV{"HYDRA_JSON"} = $tmp->filename;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
foreach my $commandToRun (@{$commandsToRun}) {my $command = $commandToRun->{command}; - edit in t/plugins/RunCommand/matcher.t at line 134
);};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"