Skip to content

Commit

Permalink
Fix finding branch name to just use Azure Pipelines env var
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Mar 17, 2023
1 parent e5cb365 commit 1051184
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
6 changes: 6 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.3.1 2023-03-17

* Same as 0.3.0, but the Docker image creation for that tag failed. This fixes
that.


## 0.3.0 2023-03-16

* Images are now stored in the GitHub Container registry rather than Docker
Expand Down
26 changes: 11 additions & 15 deletions deploy/lib/R/Tagger.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use warnings 'FATAL' => 'all';
use autodie qw( :all );
use namespace::autoclean;

use Git::Sub qw( describe ls_remote rev_parse );
use Git::Sub qw( describe );
use Specio::Library::Builtins;

use Moose::Role;
Expand All @@ -26,22 +26,18 @@ has image_versions => (
);

sub _build_image_versions {
my %remote_heads;
for my $head ( git::ls_remote( '--heads', 'origin' ) ) {
my ( $c, $ref ) = split /\s+/, $head;
$ref =~ s{^refs/heads/}{};
$remote_heads{$c} = $ref;
}
my $commit = git::rev_parse('HEAD');

my $version = $remote_heads{$commit}
or die
"Current commit ($commit) does not correspond to any remote HEAD!";
my @versions = $version;
die "The BUILD_SOURCEBRANCHNAME env var must be set when building images"
unless $ENV{BUILD_SOURCEBRANCHNAME};
my @versions = $ENV{BUILD_SOURCEBRANCHNAME};

my $tag = git::describe('--tags');
unshift @versions, $tag
if $tag =~ /\Av\d+\.\d+\.\d+\z/;
if ($tag eq $ENV{BUILD_SOURCEBRANCHNAME}) {
# We should not be tagging any other branches.
push @versions, 'master';
} else {
unshift @versions, $tag
if $tag =~ /\Av\d+\.\d+\.\d+\z/;
}

return [ sort @versions ];
}
Expand Down
15 changes: 2 additions & 13 deletions t/deploy/matrix.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,12 @@ my $client = qstrict( release => qmeth { return $release } );
)
);

# These are used in R::Tagger.
my @remote_heads = (
"ed6ab1c5c282ca4607756e1d35d8da91eb3d77cb\trefs/heads/better-junit\n",
"f53dbd18aec72c4d5278d5949ac3cd6cdfb948db\trefs/heads/fix-branch-name\n",
"6f19ea49ea83b3cd30200237d69df3cab3ee29ae\trefs/heads/fix-set-image-version\n",
"f99d5afca40b4b3f34e49230a5803a09d006b0b0\trefs/heads/install-xt-tools\n",
"4760b89ce18de3cbf3be5c51f0f0a7cb17d17c18\trefs/heads/master\n",
);
my $commit = '4760b89ce18de3cbf3be5c51f0f0a7cb17d17c18';
my $branch = 'test-branch';
my $tag = 'v1.1.1';

local *git::ls_remote = sub {@remote_heads};
local *git::rev_parse = sub {$commit};
local $ENV{BUILD_SOURCEBRANCHNAME} = $branch;
local *git::describe = sub {$tag};

my $branch = 'master';

my $ppm = D::PrintPerlsMatrix->new( _client => $client );

my $matrix = $ppm->_create_matrix;
Expand Down

0 comments on commit 1051184

Please sign in to comment.