|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use Test::More; |
| 4 | +use Data::Dump qw/dump/; |
| 5 | +use YAML; |
| 6 | +use File::Path; |
| 7 | + |
| 8 | +my $local = YAML::LoadFile('./.github/workflows/mirror.yml'); |
| 9 | +my %tags = map {$_ => 1} @{$local->{jobs}{'pull-and-push'}{strategy}{matrix}{tag} // []}; |
| 10 | +$tags{centos6} = 1; # special case |
| 11 | + |
| 12 | +my @branches = qw(develop support-8.8.x support-8.4.x support-8.0.x support-7.x); |
| 13 | +my @repos = qw(movabletype movabletype-addons movabletype-plugins); |
| 14 | + |
| 15 | +my %used; |
| 16 | +for my $repo (@repos) { |
| 17 | + for my $branch (@branches) { |
| 18 | + my $tmpdir = "./tmp/$repo/$branch"; |
| 19 | + rmtree $tmpdir if -d $tmpdir; |
| 20 | + system("git", "clone", "git\@github.com:movabletype/$repo", "-b", $branch, "--depth", 1, $tmpdir); |
| 21 | + my $yml = "$tmpdir/.github/workflows/movabletype.yml"; |
| 22 | + if (!-f $yml) { |
| 23 | + note "$yml is not found"; |
| 24 | + next; |
| 25 | + } |
| 26 | + my $workflow = YAML::LoadFile($yml); |
| 27 | + for my $key (keys %{$workflow->{jobs}}) { |
| 28 | + if (my $image = $workflow->{jobs}{$key}{env}{TEST_IMAGE_NAME}) { |
| 29 | + ok $tags{$image}, "$image is used in $repo/$branch (by env)"; |
| 30 | + $used{$image} = 1; |
| 31 | + } |
| 32 | + if (my $config = $workflow->{jobs}{$key}{strategy}{matrix}{config}) { |
| 33 | + for my $c (@$config) { |
| 34 | + my $image = $c->{image} or next; |
| 35 | + ok $tags{$image}, "$image is used in $repo/$branch (by matrix config)"; |
| 36 | + $used{$image} = 1; |
| 37 | + } |
| 38 | + } |
| 39 | + if (my $config = $workflow->{jobs}{$key}{strategy}{matrix}{include}) { |
| 40 | + for my $c (@$config) { |
| 41 | + my $image = $c->{config}{image} or next; |
| 42 | + ok $tags{$image}, "$image is used in $repo/$branch (by matrix include)"; |
| 43 | + $used{$image} = 1; |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | +for my $tag (keys %tags) { |
| 50 | + next if $used{$tag}; |
| 51 | + fail "$tag is not used anywhere"; |
| 52 | +} |
| 53 | + |
| 54 | +done_testing; |
0 commit comments