bluto

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

commit de77e8f360738034192d6b67abf91f101cf23c35
parent fb4222e74daf359a0df3f6878c47f46d7247089d
Author: lash <dev@holbrook.no>
Date:   Thu,  6 Mar 2025 03:12:25 +0000

Add yaml package output for all releases

Diffstat:
MBluto.pm | 1+
ABluto/Yaml.pm | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/Bluto.pm b/Bluto.pm @@ -544,6 +544,7 @@ sub create_rss { sub create_yaml { my $y_base = shift; my $y_release = shift; + my $env = shift; my $y = Bluto::Yaml::add_release_yaml(\%m_main, $y_base, $y_release, $env); my $fp = Bluto::Yaml::to_file(\%m_main, $y); diff --git a/Bluto/Yaml.pm b/Bluto/Yaml.pm @@ -0,0 +1,74 @@ +package Bluto::Yaml; + +use Bluto::Log qw/error info debug warn trace/; +use Bluto::Tree; + + +sub yaml_path { + my $release = shift; + + my $fp_base = File::Spec->catfile(Bluto::Tree->announce_path); + if ( ! -d $fp_base) { + make_path($fp_base); + } + my $fp = File::Spec->catfile($fp_base, $release->{slug} . '.bluto.yaml'); + return $fp; +} + +sub add_existing_releases { + my $release = shift; + my $yr = shift; + + my $fp = yaml_path($release); + + if ( ! -f $fp ) { + debug("no existing release yaml"); + return $yr; + } + my $yf = YAML::Tiny->read($fp); + for my $k (keys %{$yf->[0]->{releases}}) { + if (!defined $k) { + continue; + } + debug("processing file " . $fp); + debug("processing key " . $k); + if (defined $yr->{releases}->{$k}) { + error("already have version in yaml: " . $k); + return $yr; + } + debug("adding existing release to yaml: " . $k); + $yr->{releases}->{$k} = $yf->[0]->{releases}->{$k}; + } + + return $yr; +} + +sub add_release_yaml { + my $release = shift; + my $yb = shift; + my $yr = shift; + my $env = shift; + + if (!defined $yb->{releases}) { + $yb->{releases} = {}; + } + + $yb->{releases}->{$env->{version}} = $yr; + + $yb = add_existing_releases($release, $yb); + + return YAML::Tiny->new($yb); +} + +sub to_file { + my $release = shift; + my $y = shift; + + my $fp = yaml_path($release); + + $y->write($fp); + + return $fp; +} + +1;