Skip to content

Commit 1f9f36c

Browse files
authored
Merge pull request mackerelio#703 from mackerelio/generate-docs
fix generate docs
2 parents bc999b2 + ee73351 commit 1f9f36c

File tree

3 files changed

+93
-79
lines changed

3 files changed

+93
-79
lines changed

.github/workflows/create-release-pr.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ jobs:
3434
NEXT=${{ steps.start.outputs.nextVersion }}
3535
mv packaging/mackerel-check-plugins_$CURRENT.orig.tar.gz packaging/mackerel-check-plugins_$NEXT.orig.tar.gz
3636
37-
- run: |
38-
cpanm -qn Path::Tiny
39-
perl tool/update-docs.pl
40-
4137
- uses: mackerelio/mackerel-create-release-pull-request-action@main
4238
with:
4339
github_token: ${{ secrets.MACKERELBOT_GITHUB_TOKEN }}

tool/gen_mackerel_check.pl

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,103 @@
33
use warnings;
44
use utf8;
55
use autodie;
6+
use IO::File;
67
use JSON::PP;
78

8-
my $json = do {
9+
my $PLUGIN_PREFIX = 'check-';
10+
my $PACKAGE_NAME = 'mackerel-check-plugins';
11+
12+
# refer Mackerel::ReleaseUtils
13+
sub replace {
14+
my ($glob, $code) = @_;
15+
for my $file (glob $glob) {
16+
my $content = $code->(slurp_utf8($file), $file);
17+
$content .= "\n" if $content !~ /\n\z/ms;
18+
19+
# for keeping permission
20+
append_file($file, $content);
21+
}
22+
}
23+
24+
sub retrieve_plugins {
25+
sort map {s/^$PLUGIN_PREFIX//; $_} <$PLUGIN_PREFIX*>;
26+
}
27+
28+
sub update_readme {
29+
my @plugins = @_;
30+
31+
my $doc_links = '';
32+
for my $plug (@plugins) {
33+
$doc_links .= "* [$PLUGIN_PREFIX$plug](./$PLUGIN_PREFIX$plug/README.md)\n"
34+
}
35+
replace 'README.md' => sub {
36+
my $readme = shift;
37+
my $plu_reg = qr/$PLUGIN_PREFIX[-0-9a-zA-Z_]+/;
38+
$readme =~ s!(?:\* \[$plu_reg\]\(\./$plu_reg/README\.md\)\n)+!$doc_links!ms;
39+
$readme;
40+
};
41+
}
42+
43+
sub update_packaging_specs {
44+
my @plugins = @_;
45+
my $for_in = 'for i in ' . join(' ', @plugins) . '; do';
46+
47+
my $replace_sub = sub {
48+
my $content = shift;
49+
$content =~ s/for i in.*?;\s*do/$for_in/ms;
50+
$content;
51+
};
52+
replace $_, $replace_sub for ("packaging/rpm/$PACKAGE_NAME*.spec", "packaging/deb-v2/debian/rules");
53+
}
54+
55+
####
56+
# file utility
57+
####
58+
sub slurp_utf8 {
59+
my $filename = shift;
60+
my $fh = IO::File->new($filename, "<:utf8");
961
local $/;
10-
open my $fh, '<', 'packaging/config.json';
11-
<$fh>
12-
};
62+
<$fh>;
63+
}
64+
sub write_file {
65+
my $filename = shift;
66+
my $content = shift;
67+
my $fh = IO::File->new($filename, ">:utf8");
68+
print $fh $content;
69+
$fh->close;
70+
}
71+
sub append_file {
72+
my $filename = shift;
73+
my $content = shift;
74+
my $fh = IO::File->new($filename, "+>:utf8");
75+
print $fh $content;
76+
$fh->close;
77+
}
78+
79+
sub load_packaging_confg {
80+
decode_json(slurp_utf8('packaging/config.json'));
81+
}
82+
83+
84+
####
85+
# some file generate task
86+
####
87+
88+
sub subtask {
89+
my @plugins = retrieve_plugins;
90+
update_readme(@plugins);
91+
my $config = load_packaging_confg;
92+
update_packaging_specs(@{ $config->{plugins} });
93+
94+
}
95+
96+
subtask();
97+
98+
####
99+
# go:generate task
100+
####
13101

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

16104
my $imports = "";
17105
my $case = "";

tool/update-docs.pl

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)