bluto

Release package and announcement generator
Info | Log | Files | Refs | README | LICENSE

commit 5c2e9a9e1dad9b9045292246b1903db05120f6f6
parent d77e7de8320ef675bc2600e77724f981e18b5068
Author: lash <dev@holbrook.no>
Date:   Wed, 19 Jun 2024 15:56:56 +0100

Improve changelog search, reinstate announce generation in module

Diffstat:
MBluto.pm | 58++++++++++++++++++++++++++++++++++++++++++----------------
Mto_std.pl | 38+++++++++++++++++++++++++-------------
2 files changed, 67 insertions(+), 29 deletions(-)

diff --git a/Bluto.pm b/Bluto.pm @@ -22,7 +22,7 @@ my %m_main = ( summary => undef, license => undef, tag_prefix => VCS_TAG_PREFIX, - changelog => '', + changelog => undef, time => undef, tech_main => undef, tech => \@m_tech, @@ -36,13 +36,14 @@ my $have_version_match = undef; sub from_config { my $cfg = shift; - my $src_dir = shift; + my $env = shift; + my $version; if (defined $cfg->{version}) { $version = $cfg->{version}; } else { - $fn = File::Spec->catfile($src_dir, 'VERSION'); - open(my $f, "<$fn") or error("no version file found") && return undef; + $fn = File::Spec->catfile($env->{src_dir}, 'VERSION'); + open(my $f, "<$fn") or error('no version file found: ' . $fn) && return undef; $version = <$f>; close($f); $version = SemVer->new($version); @@ -93,8 +94,12 @@ sub from_config { } } - - my $targz = Bluto::Archive::create($m_main{slug}, $m_main{version}, $m_main{tag_prefix}, $src_dir); + if (!defined $have_version_match) { + error("no changelog found for version " . $m_main{version}); + return undef; + } + + my $targz = Bluto::Archive::create($m_main{slug}, $m_main{version}, $m_main{tag_prefix}, $env->{src_dir}); if (!defined $targz) { return undef; } @@ -108,32 +113,53 @@ sub from_config { # process changelog entry my $body = ''; - if (!defined $have_version_match) { - error("no changelog found for version " . $m_main{version}); - return undef; + my $version_src = $cfg->param('changelog.' . $have_version_match); + my @changelog_candidates; + + if ($version_src =~ '^sha256:(.*)$' ) { + push(@changelog_candidates, $1); + debug('found sha256 changelog entry ' . $1 . ' for ' . $have_version_match . ' from ' . $fp); } else { - # TODO: else should look for targz filename dot txt and include literal - if ($cfg->param('changelog.' . $have_version_match) =~ '^sha256:(.*)$' ) { - my $fp = File::Spec->catfile ( $content_dir, $1 ); - debug('resolve sha256 content ' . $1 . ' for ' . $have_version_match . ' from ' . $fp); - open(my $f, "<$fp") or die ('cannot open content read from: ' . $fp); + push(@changelog_candidates, $version_src); + } + + push(@changelog_candidates, "CHANGELOG." . $have_version_match); + push(@changelog_candidates, "CHANGELOG/" . $have_version_match); + push(@changelog_candidates, "CHANGELOG/CHANGELOG." . $have_version_match); + + # TODO: if have sha256, check against the contents + for my $fn (@changelog_candidates) { + my $fp = File::Spec->catfile ( $env->{content_dir}, $fn ); + if (open(my $f, "<$fp")) { + $m_main{changelog} = ''; while (<$f>) { $m_main{changelog} .= $_; } + close($f); + info('read changelog info from ' . $fp); + last; + } else { + debug('changelog candidate ' . $fp . ' not available: ' . $!); } } + if (!defined $m_main{changelog}) { + error('changelog content empty after exhausting all options'); + } return $have_version_match; } -sub get_announcement() { +sub get_announcement { + my $env = shift; my $tt = Template->new({ INCLUDE_PATH => '.', INTERPOLATE => 1, + ABSOLUTE => 1, }); my $out; - $tt->process('base.tt', \%m_main, \$out) or croak($tt->error()); + $tt->process($env->{template_path}, \%m_main, \$out) or error('error processing template: '. $tt->error()); + return $out; } 1; diff --git a/to_std.pl b/to_std.pl @@ -27,28 +27,40 @@ sub croak { # TODO: export to perl modules -my $src_dir = File::Spec->catfile(getcwd, '.bluto'); -my $out_dir = getcwd; -my $feed_dir = getcwd; -my $content_dir = getcwd; +my %env = ( + src_dir => File::Spec->catfile(getcwd, '.bluto'), + out_dir => getcwd, + feed_dir => getcwd, + content_dir => getcwd, + template_path => 'base.tt', +); +#my $src_dir = +#my $out_dir = getcwd; +#my $feed_dir = getcwd; +#my $content_dir = getcwd; GetOptions( - 'd:s', \$src_dir, - 'o:s', \$out_dir, - 'f:s', \$feed_dir, - 'c:s', \$content_dir, + 'd:s', \$env{src_dir}, + 'o:s', \$env{out_dir}, + 'f:s', \$env{feed_dir}, + 'c:s', \$env{content_dir}, ); -$src_dir = abs_path($src_dir); - -info("using ini dir " . $src_dir); +foreach my $k (keys %env ) { + $env{$k} = abs_path($env{$k}); + debug('environment "' . $k . '": ' . $env{$k}); +} -my $fn = File::Spec->catfile($src_dir, 'bluto.ini'); +my $fn = File::Spec->catfile($env{src_dir}, 'bluto.ini'); debug("import from " . $fn); my $cfg = new Config::Simple($fn); -my $version = Bluto::from_config($cfg, $src_dir); +my $version = Bluto::from_config($cfg, \%env); if (!defined $version) { die("config processing failed"); } +my $announcement = Bluto::get_announcement(\%env); + +print($announcement); + #my @change = $cfg->vars();