Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix generate docs #703

Merged
merged 6 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ jobs:
NEXT=${{ steps.start.outputs.nextVersion }}
mv packaging/mackerel-check-plugins_$CURRENT.orig.tar.gz packaging/mackerel-check-plugins_$NEXT.orig.tar.gz

- run: |
cpanm -qn Path::Tiny
perl tool/update-docs.pl

- uses: mackerelio/mackerel-create-release-pull-request-action@main
with:
github_token: ${{ secrets.MACKERELBOT_GITHUB_TOKEN }}
Expand Down
98 changes: 93 additions & 5 deletions tool/gen_mackerel_check.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,103 @@
use warnings;
use utf8;
use autodie;
use IO::File;
use JSON::PP;

my $json = do {
my $PLUGIN_PREFIX = 'check-';
my $PACKAGE_NAME = 'mackerel-check-plugins';

# refer Mackerel::ReleaseUtils
sub replace {
my ($glob, $code) = @_;
for my $file (glob $glob) {
my $content = $code->(slurp_utf8($file), $file);
$content .= "\n" if $content !~ /\n\z/ms;

# for keeping permission
append_file($file, $content);
}
}

sub retrieve_plugins {
sort map {s/^$PLUGIN_PREFIX//; $_} <$PLUGIN_PREFIX*>;
}

sub update_readme {
my @plugins = @_;

my $doc_links = '';
for my $plug (@plugins) {
$doc_links .= "* [$PLUGIN_PREFIX$plug](./$PLUGIN_PREFIX$plug/README.md)\n"
}
replace 'README.md' => sub {
my $readme = shift;
my $plu_reg = qr/$PLUGIN_PREFIX[-0-9a-zA-Z_]+/;
$readme =~ s!(?:\* \[$plu_reg\]\(\./$plu_reg/README\.md\)\n)+!$doc_links!ms;
$readme;
};
}

sub update_packaging_specs {
my @plugins = @_;
my $for_in = 'for i in ' . join(' ', @plugins) . '; do';

my $replace_sub = sub {
my $content = shift;
$content =~ s/for i in.*?;\s*do/$for_in/ms;
$content;
};
replace $_, $replace_sub for ("packaging/rpm/$PACKAGE_NAME*.spec", "packaging/deb-v2/debian/rules");
}

####
# file utility
####
sub slurp_utf8 {
my $filename = shift;
my $fh = IO::File->new($filename, "<:utf8");
local $/;
open my $fh, '<', 'packaging/config.json';
<$fh>
};
<$fh>;
}
sub write_file {
my $filename = shift;
my $content = shift;
my $fh = IO::File->new($filename, ">:utf8");
print $fh $content;
$fh->close;
}
sub append_file {
my $filename = shift;
my $content = shift;
my $fh = IO::File->new($filename, "+>:utf8");
print $fh $content;
$fh->close;
}

sub load_packaging_confg {
decode_json(slurp_utf8('packaging/config.json'));
}


####
# some file generate task
####

sub subtask {
my @plugins = retrieve_plugins;
update_readme(@plugins);
my $config = load_packaging_confg;
update_packaging_specs(@{ $config->{plugins} });

}

subtask();

####
# go:generate task
####

my @plugins = sort @{ decode_json($json)->{plugins}};
my @plugins = sort @{ load_packaging_confg()->{plugins}};

my $imports = "";
my $case = "";
Expand Down
70 changes: 0 additions & 70 deletions tool/update-docs.pl

This file was deleted.