From: Graham Knop Date: Thu, 21 Aug 2014 16:55:55 +0000 (-0400) Subject: include git commit hash in metadata X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Finclude-git-commit;p=p5sagit%2FDistar.git include git commit hash in metadata --- diff --git a/helpers/add-git-commit b/helpers/add-git-commit new file mode 100755 index 0000000..0050e1a --- /dev/null +++ b/helpers/add-git-commit @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +use strict; +use warnings FATAL => 'all'; + +use CPAN::Meta; +use Parse::CPAN::Meta; + +my $file = shift || die "need a file"; +my $meta = Parse::CPAN::Meta->load_file($file); + +my $commit = `git rev-parse HEAD`; +chomp $commit; +$meta->{x_vcs_commit} = $commit; + +my $tag = `git describe`; +chomp $tag; +$meta->{x_vcs_tag} = $tag; + +CPAN::Meta->new($meta)->save($file, { version => ($file =~ /\.yml$/ ? 1 : 2) }); diff --git a/lib/Distar.pm b/lib/Distar.pm index e283189..be125f3 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -190,6 +190,16 @@ END_FRAG $out; } + sub metafile_target { + my $self = shift; + my $metafile_target = $self->SUPER::metafile_target(@_); + for (qw(META.yml META.json)) { + my $add = "\t\$(NOECHO) \$(ABSPERLRUN) $(HELPERS)/add-git-commit \$(DISTVNAME)/$_\n"; + $metafile_target =~ s{(.*\b\Q$_\E\b[^\n]*\n)}{$1$add}s; + } + $metafile_target; + } + sub dist_test { my $self = shift;