bluto

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

commit 7ed4da0449182876aad5e79f6ba8ed1e06766c12
parent 318443a32dc3c5a9628e24d943c87e5ebcc69e2f
Author: lash <dev@holbrook.no>
Date:   Thu, 20 Jun 2024 03:42:25 +0100

Include txt version of announce in output

Diffstat:
MBluto.pm | 48+++++++++++++++++++++++++++++++++++++++++++++---
MBluto/Archive.pm | 4++--
MBluto/RSS.pm | 2+-
Mbase.tt | 3++-
Mto_std.pl | 35++++++++++++++++++++++++++++++++++-
5 files changed, 84 insertions(+), 8 deletions(-)

diff --git a/Bluto.pm b/Bluto.pm @@ -111,7 +111,7 @@ sub _check_ini { error('ini file not found: ' . $fp); return 1; } - info('using ini file: ' . $fp); + debug('using ini file: ' . $fp); return 0; } @@ -123,7 +123,7 @@ sub _check_readme { for my $fn (('README', 'README.txt', 'README.adoc', 'README.rst', 'README.md')) { $fp = File::Spec->catfile($env->{src_dir}, $fn); if ( -f $fp ) { - info('using readme file: ' . $fp); + debug('using readme file: ' . $fp); $env{readme} = $fp; return 0; } @@ -133,6 +133,26 @@ sub _check_readme { return 1; } +sub _check_version { + my $env = shift; + my $f; + my $fp; + + $fp = File::Spec->catfile($env->{src_dir}, 'VERSION'); + if ($env->{version}) { + info('writing new explicit version ' . $env->{version} . ' to file: ' . $fp); + open($f, '>', $fp); + print $f $env->{version}; + close($f); + } + if (! -f $fp ) { + error('no version file'); + return 1; + } + debug('using version file: ' . $fp); + return 0; +} + sub _prepare_out { my $release = shift; my $env = shift; @@ -146,6 +166,7 @@ sub check_sanity { $r += _check_readme($env); $r += _check_ini($env); + $r += _check_version($env); return $r; } @@ -306,10 +327,31 @@ sub from_config { return $have_version_match; } -sub create_rss { +sub create_announce { my $env = shift; + my $f; my $out = Bluto::Announce::get_asciidoc(\%m_main, $env); + if (!defined $out) { + return undef; + } + + my $fp = File::Spec->catfile(Bluto::Tree->announce_path, $m_main{slug} . '.bluto.txt'); + open($f, '>', $fp) or (error('cannot open announce file: ' . $!) && return undef); + print $f $out; + close($f); + debug('stored announce text file: ' . $fp); + + return $fp; +} + +sub create_rss { + my $env = shift; + my $out = shift; + + if (!defined $out) { + $out = Bluto::Announce::get_asciidoc(\%m_main, $env); + } #return Bluto::RSS::to_string(\%m_main, $env, $out); return Bluto::RSS::to_file(\%m_main, $env, $out); diff --git a/Bluto/Archive.pm b/Bluto/Archive.pm @@ -1,11 +1,11 @@ package Bluto::Archive; use Cwd; -use File::Basename qw/ basename fileparse /; +use File::Basename qw/basename fileparse/; use Digest::SHA; use Log::Term::Ansi qw/error info debug warn trace/; -use Bluto::Tree; +use Bluto::Tree qw/release_path/; sub seal { diff --git a/Bluto/RSS.pm b/Bluto/RSS.pm @@ -7,7 +7,7 @@ use XML::RSS; use Template; use Log::Term::Ansi qw/error info debug warn trace/; -use Bluto::Tree qw /announce_path/; +use Bluto::Tree qw/announce_path/; sub get_feed_filepath { diff --git a/base.tt b/base.tt @@ -2,6 +2,7 @@ Release announcement: [% name %] === Version release: [% version %] + License: [% license %] Source bundles @@ -29,6 +30,6 @@ CHANGELOG ----- -Release generator: [% engine %] +Generated by [% engine %] at [% time %]Z ----- diff --git a/to_std.pl b/to_std.pl @@ -11,12 +11,15 @@ use File::Basename qw/ dirname /; use File::Spec qw/ catfile /; use File::Path qw/ make_path /; use Cwd qw/ getcwd abs_path /; +use lib (dirname(abs_path($0))); # external imports use Config::Simple; +# bundled external imports +use SemVer; + # local imports -use lib dirname(abs_path($0)); use Log::Term::Ansi qw/error info debug warn trace/; use Bluto; use Bluto::RSS; @@ -25,8 +28,16 @@ sub croak { die(shift); } +sub help() { + print("$0\n\nwould have shown help...\n"); + exit 0; +} + # TODO: export to perl modules +my $force_version = undef; +my $loglevel = 0; +my $force_help = 0; my %env = ( src_dir => File::Spec->catfile(getcwd, '.bluto'), out_dir => File::Spec->catfile(getcwd, 'bluto_build'), @@ -35,13 +46,24 @@ my %env = ( template_path => 'base.tt', engine => undef, readme => undef, + version => undef, + loglevel => undef, ); GetOptions( 'd:s', \$env{src_dir}, 'o:s', \$env{out_dir}, 'f:s', \$env{feed_dir}, 'c:s', \$env{content_dir}, + 'v+', \$loglevel, + 'h+', \$force_help, + 'help+', \$force_help, + 'version=s', \$force_version, ); + +if ($force_help > 0) { + help; +} + foreach my $k (keys %env ) { if (defined $env{$k}) { $env{$k} = abs_path($env{$k}); @@ -52,6 +74,12 @@ if (!defined $env{feed_dir}) { $env{feed_dir} = $env{out_dir}; } +if (defined $force_version) { + $env{version} = SemVer->new($force_version); +} + +$env{loglevel} = $loglevel; + $env{engine} = 'bluto v' . SemVer->new(Bluto::VERSION). " (perl $^V)"; foreach my $k (keys %env ) { if (defined $env{$k}) { @@ -72,6 +100,11 @@ if (!defined $version) { die("config processing failed"); } +my $announce = Bluto::create_announce(\%env); +if (!defined $announce) { + die("announce processing failed"); +} + my $rss = Bluto::create_rss(\%env); if (!defined $rss) { die("rss processing failed");