commit 15a30ca951e1a022703cb7163180c6cdee1dda90
parent 5414968a06d9edba0866659e7b6dbd99f9753ee1
Author: lash <dev@holbrook.no>
Date: Tue, 1 Oct 2024 03:08:18 +0100
WIP implement bluto publish with refactored args, envs
Diffstat:
6 files changed, 137 insertions(+), 106 deletions(-)
diff --git a/Bluto.pm b/Bluto.pm
@@ -1,5 +1,6 @@
package Bluto;
+use DateTime;
use File::Basename qw/ basename /;
use File::Path qw / make_path /;
@@ -8,6 +9,7 @@ use Bluto::Archive;
use Bluto::Announce;
use Bluto::Tree;
use Bluto::SemVer;
+use Bluto::RSS;
use constant { VCS_TAG_PREFIX => 'v' };
#use constant { VERSION => '0.0.1' };
@@ -302,7 +304,7 @@ sub from_yaml {
}
my @targz_stat = stat ( $targz );
$m_main{time} = DateTime->from_epoch( epoch => $targz_stat[9] )->stringify();
- foreach my $v ( $cfg->{locate}->{tgzbase}) {
+ foreach my $v ( @{$cfg_m->{locate}->{tgzbase}}) {
warn('not checking targz base formatting for ' . $v);
my $src = $m_main{slug} . '/' . basename($targz);
push(@m_src, $v . '/' . $src);
diff --git a/Bluto/Announce.pm b/Bluto/Announce.pm
@@ -18,7 +18,7 @@ sub _adapt_headings {
$this = undef;
if (defined $last) {
if ($_ =~ /^===/) {
- $this = '=' x length($last);
+ $this = '=' x (length($last) - 1);
} elsif ($_ =~ /^---/) {
if ($last !~ /^\W+$/) {
$this = '-' x (length($last) - 1);
diff --git a/Bluto/Cmd.pm b/Bluto/Cmd.pm
@@ -8,9 +8,10 @@ use File::Copy;
use Digest::SHA;
use Bluto::SemVer;
+use Bluto;
use YAML::Tiny;
-use Bluto::Log qw/debug error/;
+use Bluto::Log qw/debug info error/;
my $force_version = undef;
@@ -19,13 +20,10 @@ my %env = (
src_dir => File::Spec->catfile(getcwd, '.bluto'),
version => undef,
loglevel => undef,
+ engine => undef,
);
my @opts_x;
-sub croak {
- die(shift);
-}
-
sub help {
print("$0\n\nwould have shown help...\n");
exit 0;
@@ -74,6 +72,13 @@ sub process_param {
make_path($env{src_dir});
}
+ $env{engine} = 'bluto v' . SemVer->new(Bluto::version()). " (perl $^V)";
+ foreach my $k (keys %env ) {
+ if (defined $env{$k}) {
+ debug('environment "' . $k . '": ' . $env{$k});
+ }
+ }
+
foreach my $k (keys %env) {
my $v = $env{$k};
if (defined $v) {
@@ -102,7 +107,7 @@ sub base_config_path {
sub release_config_path {
if (!defined $env{version}) {
- croak("release config path does not exist, version not set");
+ die("release config path does not exist, version not set");
}
return File::Spec->catfile($env{src_dir}, $env{version} . '.yml');
}
@@ -113,11 +118,24 @@ sub base_config {
return $yi->[0];
}
+sub release_config {
+ my $fn = release_config_path();
+ my $yi = YAML::Tiny->read($fn);
+ return $yi->[0];
+}
+
+sub params {
+ if (_check_sanity()) {
+ return undef;
+ }
+ return \%env;
+}
+
sub process_changelog {
my $copy = shift;
if (!defined $env{changelog_file}) {
- croak("changelog file missing");
+ die("changelog file missing");
}
my $h = Digest::SHA->new('sha256');
@@ -131,4 +149,67 @@ sub process_changelog {
return $z;
}
+sub _check_yml {
+ my $env = shift;
+
+ #my $fp = File::Spec->catfile($env->{src_dir}, 'bluto.ini');
+ my $fp = File::Spec->catfile($env{src_dir}, 'bluto.yml');
+ if ( ! -f $fp ) {
+ error('yml file not found: ' . $fp);
+ return 1;
+ }
+ debug('using yml file: ' . $fp);
+ return 0;
+}
+
+sub _check_readme {
+ my $env = shift;
+ my $f;
+ my $fp;
+
+ for my $fn (('README', 'README.txt', 'README.adoc', 'README.rst', 'README.md')) {
+ $fp = File::Spec->catfile($env{content_dir}, $fn);
+ if ( -f $fp ) {
+ debug('using readme file: ' . $fp);
+ $env{readme} = $fp;
+ return 0;
+ }
+ }
+
+ warn('no readme file found');
+ 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 _check_sanity {
+ my $r = 0;
+
+ $r += _check_readme($env);
+ $r += _check_yml($env);
+ $r += _check_version($env);
+
+ return $r;
+}
+
+
1;
diff --git a/Bluto/RSS.pm b/Bluto/RSS.pm
@@ -14,7 +14,6 @@ sub get_feed_filepath {
my $env = shift;
my $fn = $release->{slug} . '.bluto.rss';
- #my $fp = File::Spec->catfile($env->{feed_dir}, $fn);
my $fp = File::Spec->catfile(Bluto::Tree->announce_path, $fn);
return $fp;
}
diff --git a/bluto-pub b/bluto-pub
@@ -4,111 +4,46 @@ use v5.10.1;
use warnings;
use strict;
-# standard imports
-use Getopt::Long qw/ :config auto_help /;
-#use File::Temp qw/ tempdir /;
-use File::Basename qw/ dirname /;
use File::Spec;
+use File::Basename qw/ dirname /;
use Cwd qw/ getcwd abs_path /;
use lib (dirname(abs_path($0)));
-# external imports
-use Config::Simple;
-use YAML::Tiny;
-
-# local imports
use Bluto::Log qw/debug/;
+use Bluto::Cmd;
use Bluto;
-use Bluto::RSS;
-use Bluto::SemVer;
-
-sub croak {
- die(shift);
-}
-sub help() {
- print("$0\n\nwould have shown help...\n");
- exit 0;
-}
-
-# TODO: export to perl modules
+Bluto::Cmd::register_param("version", undef, "version", undef);
+Bluto::Cmd::register_param("out_dir", File::Spec->catfile(getcwd, 'bluto_build'), undef, "o");
+Bluto::Cmd::register_param("feed_dir", undef, "feed-dir", undef);
+Bluto::Cmd::register_param("content_dir", undef, "code-dir", "c");
+Bluto::Cmd::register_param("readme", undef, undef, undef);
-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'),
- feed_dir => undef,
- content_dir => getcwd,
- template_path => undef,
- 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,
-);
+Bluto::Cmd::process_param();
-if ($force_help > 0) {
- help;
-}
-
-foreach my $k (keys %env ) {
- if (defined $env{$k}) {
- $env{$k} = abs_path($env{$k});
- }
-}
-
-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}) {
- debug('environment "' . $k . '": ' . $env{$k});
- }
+my $version = Bluto::Cmd::get_version();
+if (!defined $version) {
+ Bluto::Cmd::croak("version missing");
}
-if (Bluto::check_sanity(\%env)) {
- croak('sanity check fail');
+my $ym = Bluto::Cmd::base_config();
+my $yv = Bluto::Cmd::release_config();
+my $env = Bluto::Cmd::params();
+if (!defined $env) {
+ die("not sane");
}
-my $fn = File::Spec->catfile($env{src_dir}, 'bluto.yml');
-my $yi = YAML::Tiny->read($fn);
-my $ym = $yi->[0];
-
-$fn = File::Spec->catfile($env{src_dir}, $env{version} . '.yml');
-$yi = YAML::Tiny->read($fn);
-my $yv = $yi->[0];
-debug('have changelog ' . $yv->{changelog} . ' for version ' . $env{version});
-
-my $version = Bluto::from_yaml($ym, $yv, \%env);
+my $version = Bluto::from_yaml($ym, $yv, $env);
if (!defined $version) {
die("config processing failed");
}
-my $announce = Bluto::create_announce(\%env);
+my $announce = Bluto::create_announce($env);
if (!defined $announce) {
die("announce processing failed");
}
-my $rss = Bluto::create_rss(\%env);
+my $rss = Bluto::create_rss($env);
if (!defined $rss) {
die("rss processing failed");
}
diff --git a/bluto.pl b/bluto.pl
@@ -4,14 +4,20 @@ use v5.10.1;
use warnings;
use strict;
+use File::Spec;
use File::Basename qw/ dirname /;
use Cwd qw/ getcwd abs_path /;
use lib (dirname(abs_path($0)));
+use Bluto::Log qw/debug/;
use Bluto::Cmd;
+use Bluto;
Bluto::Cmd::register_param("version", undef, "version", undef);
-Bluto::Cmd::register_param("changelog_file", undef, undef, "f");
+Bluto::Cmd::register_param("out_dir", File::Spec->catfile(getcwd, 'bluto_build'), undef, "o");
+Bluto::Cmd::register_param("feed_dir", undef, "feed-dir", undef);
+Bluto::Cmd::register_param("content_dir", undef, "code-dir", "c");
+Bluto::Cmd::register_param("readme", undef, undef, undef);
Bluto::Cmd::process_param();
@@ -20,16 +26,24 @@ if (!defined $version) {
Bluto::Cmd::croak("version missing");
}
+my $ym = Bluto::Cmd::base_config();
+my $yv = Bluto::Cmd::release_config();
+my $env = Bluto::Cmd::params();
+if (!defined $env) {
+ die("not sane");
+}
+
+my $version = Bluto::from_yaml($ym, $yv, $env);
+if (!defined $version) {
+ die("config processing failed");
+}
-my @contributors;
-my $yd = Bluto::Cmd::base_config();
-my $yv = {
- changelog => 'sha256:' . Bluto::Cmd::process_changelog(1),
- author => $yd->{author}->{name},
- maintainer => $yd->{maintainer}->{name},
- contributors => \@contributors,
-};
+my $announce = Bluto::create_announce($env);
+if (!defined $announce) {
+ die("announce processing failed");
+}
-my $yo = YAML::Tiny->new($yv);
-my $fn = Bluto::Cmd::release_config_path();
-$yo->write($fn);
+my $rss = Bluto::create_rss($env);
+if (!defined $rss) {
+ die("rss processing failed");
+}