Skip to content

Commit b10854a

Browse files
committed
Merge pull request #6 from mackerelio/packaging-preparation
Packaging preparation
2 parents f8d5a42 + 19f67d0 commit b10854a

14 files changed

+644
-2
lines changed

.travis.yml

+23
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,31 @@ language: go
22
go:
33
- 1.4
44
env: PATH=/home/travis/gopath/bin:$PATH
5+
install:
6+
- go get github.com/mitchellh/gox
7+
- gox -build-toolchain -osarch=linux/386
8+
- sudo apt-get update
9+
- DEBIAN_FRONTEND=noninteractive sudo apt-get install -y rpm devscripts debhelper
10+
- mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
511
script:
612
- make lint
713
- make cover
14+
- make all
815
after_script:
916
- goveralls -coverprofile=.profile.cov
17+
after_success:
18+
- tool/travis/autotag.sh
19+
deploy:
20+
provider: releases
21+
api_key:
22+
secure: vmMQz+IjJ/LUa9SHAlLKyg4raSqkEBIRzqnjS1LK7ZjtcAROo6Pn0lUcC4qMZ96/VvNMdLyGndCOBXsdE2VBCY5goTI7uIW1oxbLM3qOMNQQldG1bOY34bjkiiDU15WLUsKKPEC2RdgwG1aAAsqcUDAeyRABYVBANSn9jylQnBC2b2mQMYUtVA1O9jl3Qg64Cy6MUUirE/SuKp/cnE3AakcQt54pNVsnM54bIyrbGhqThLj7p7uLJEm58oRWR7TTUSgmk/Rbj4aJSC4k5lzN9iL/Fr5AgnpEQQUg3ishE+5yqSW7f/PRqXC6ZI9p6XS7bhS8N178ImzouIsoKWltblsgUhfvE6ONyMpi1+RG+6Lp3HlpLuq0Pz/efEpcaSDg6lXDIvMBC2sA5pbPok6Yx4tJOSv8adWu9t0yGVJezYaqbN/071K9m3cM4YTQK4L39b2FxQ2ZrUhee8HZy5rDO8iqx2vgM+NXATz2L5Tjjzd4aqfIDX8R3PVImBci7se/wmamDUpOrcfSjrI2dzEQGBzBfIFIhCaCQSuEjpZqBKdcOztkn1uev7a0AAUeZ7my+uQNpAMO7/AapM7LLugmkLM06FgrHKWDPQP/T92MPyvmC04nNraetAVijVYLQnlK5+TdEMvkKHuY5afLp5mEzX+7jTSmjyaUNrbANs8bH/8=
23+
file:
24+
- "/home/travis/rpmbuild/RPMS/noarch/mackerel-check-plugins-0.0.0-1.noarch.rpm"
25+
- "/home/travis/gopath/src/github.com/mackerelio/go-check-plugins/packaging/mackerel-check-plugins_0.0.0-1_all.deb"
26+
on:
27+
repo: mackerelio/go-check-plugins
28+
all_branches: true
29+
tags: true
30+
notifications:
31+
slack:
32+
secure: gsM+oW5k6hQnL16ubkj0Iu7b3kSeUUGCErwWa8AIBdfk6DUYBxfFNkJkHJ+N44YJPuk/ijaTk8fzQ0HqD9H+Fegkv/KPMnJ00QxOD4XWv4URFACuGQgC2xB4G8OBg7StHPN68KroQn1ryNNoAwiZih///PGJyxb4uU/FrpA8iLATBoGoaEv8OrGkkwIepvtuHeRzyMPAjNvNO6evI0d/+Xn0YLRLtufdznHG3UHc/FJ306QkMz5hbP4iZqyNFlj6sFlvvovsozTqgGYYqKz2QbMzvR3l7xuFWiV6qa6zegy6sWp9pBWykQMm528R3pVDSu/f775shORLS4DaSV7ZM3Gw963gIgfdmcqLi6KP8j+NqqyveUAq5C6JOaVDTKwJg+b2yL6TYYEQ4Lz7WiOLLmjj9V+9+i5oy852FfQEG/en9+jnPDuWDI0ILKTW8EqcQfCf46mtV0TiWY4if5iYAVUOl2O5Jam9LTX9YSeRA0qq9022tJ60GpIvX9vskO2SXTdAAQRRqM5dliOYblo0H3AmBQWTixH+AgcOP0nzAugIRX07Kpni9GfOL5bW3lBVJo1502DZWLdKoF1ulS/nHfWdz9TwuocX8hOko/H3yNH8Lt9DyodgXgWDwtYuHeuXxw7gTcaPX4K3wGgshnaBZXrryWH6u7UPT8hFePqsD58=

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 0.0.0 (2015-10-07)
4+
5+
* Initial release

Makefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TARGET_OSARCH="linux/386"
22

3-
all: clean test build
3+
all: clean test build rpm deb
44

55
test: lint
66
go test $(TESTFLAGS) ./...
@@ -27,15 +27,26 @@ cover: devel-deps
2727
build: deps
2828
mkdir -p build
2929
for i in check-*; do \
30+
if [ $$i = check-load ]; then \
31+
echo ""; \
32+
else \
3033
gox -osarch=$(TARGET_OSARCH) -output build/$$i \
3134
github.com/mackerelio/go-check-plugins/$$i; \
35+
fi; \
3236
done
3337

38+
rpm: build
39+
rpmbuild --define "_sourcedir `pwd`" -ba packaging/rpm/mackerel-check-plugins.spec
40+
41+
deb: build
42+
cp build/check-* packaging/deb/debian/
43+
cd packaging/deb && debuild --no-tgz-check -rfakeroot -uc -us
44+
3445
clean:
3546
if [ -d build ]; then \
3647
rm -f build/check-*; \
3748
rmdir build; \
3849
fi
3950
go clean
4051

41-
.PHONY: all test deps devel-deps lint cover build clean
52+
.PHONY: all test deps devel-deps lint cover build clean rpm deb

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ go-check-plugins
33

44
Check Plugins for monitoring written in golang.
55

6+
7+
Documentation for each plugin is located in its respective sub directory.
8+
9+
* [check-file-age](./check-file-age/README.md)
10+
* [check-http](./check-http/README.md)
11+
* [check-load](./check-load/README.md)
12+
* [check-procs](./check-procs/README.md)
13+
614
Specification
715
-------------
816

@@ -14,3 +22,11 @@ The specs for the check plugins are mostly the same as the [Nagios](https://www.
1422
| 1 | WARNING |
1523
| 2 | CRITICAL |
1624
| other than 0,1, or 2 | UNKNOWN |
25+
26+
27+
Contribution
28+
------------
29+
30+
* fork it
31+
* develop the plugin you want
32+
* create a pullrequest!

packaging/config.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"description": "configuration for packaging mackerel-check-plugins",
3+
"plugins": [
4+
"file-age",
5+
"http",
6+
"load",
7+
"procs"
8+
]
9+
}

packaging/deb/debian/changelog

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mackerel-check-plugins (0.0.0-1) unstable; urgency=low
2+
3+
* Initial release
4+
5+
-- itchyny <[email protected]> Wed, 7 Oct 2015 12:00:00 +0900

packaging/deb/debian/control

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Source: mackerel-check-plugins
2+
Maintainer: Shinji Tanaka <[email protected]>
3+
Section: misc
4+
Priority: optional
5+
Standards-Version: 0.0.0
6+
7+
Package: mackerel-check-plugins
8+
Architecture: all
9+
Description: macekrel.io check plugins

packaging/deb/debian/copyright

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Apache2

packaging/deb/debian/rules

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/make -f
2+
3+
%:
4+
dh $@
5+
6+
package=mackerel-check-plugins
7+
8+
override_dh_auto_install:
9+
dh_auto_install
10+
install -d -m 755 debian/tmp/usr/local/bin
11+
for i in http file-age procs;do \
12+
install -m755 debian/check-$$i debian/tmp/usr/local/bin; \
13+
done
14+
15+
override_dh_usrlocal:
16+
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
%define _binaries_in_noarch_packages_terminate_build 0
2+
%define _localbindir /usr/local/bin
3+
%define __targetdir /usr/local/bin
4+
5+
Name: mackerel-check-plugins
6+
Version: 0.0.0
7+
Release: 1
8+
License: Commercial
9+
Summary: macekrel.io check plugins
10+
URL: https://mackerel.io
11+
Group: Hatena
12+
Packager: Hatena
13+
BuildArch: noarch
14+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
15+
16+
%description
17+
mackerel.io check plugins
18+
19+
%prep
20+
21+
%build
22+
23+
%install
24+
%{__rm} -rf %{buildroot}
25+
26+
%{__mkdir} -p %{buildroot}%{__targetdir}
27+
28+
for i in http file-age procs;do \
29+
%{__install} -m0755 %{_sourcedir}/build/check-$i %{buildroot}%{__targetdir}/; \
30+
done
31+
32+
%clean
33+
%{__rm} -rf %{buildroot}
34+
35+
%files
36+
%defattr(-, root, root, 0755)
37+
%{__targetdir}
38+
39+
%changelog
40+
* Wed Oct 7 2015 itchyny <[email protected]> 0.0.0
41+
- Initial release

tool/autotag

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env perl
2+
3+
=head DESCRIPTION
4+
5+
Automatically `git tag` by travisCI.
6+
7+
When the pull request is merged and the branch name is like "bump-version-N.N.N",
8+
the merge commit is automatically tagged as `vN.N.N`.
9+
10+
=head SYNOPSIS
11+
12+
% tool/autotag
13+
14+
=cut
15+
16+
use 5.014;
17+
use warnings;
18+
19+
use HTTP::Tiny;
20+
use JSON::PP;
21+
22+
my $OWNER = 'mackerelio';
23+
my $REPO = 'go-check-plugins';
24+
25+
sub get_branch_from_msg {
26+
my $msg = shift;
27+
28+
my ($pr_num, $branch) = $msg =~ /^[a-f0-9]{7} Merge pull request #([0-9]+) from (.*)$/;
29+
return unless $pr_num;
30+
31+
my $res = HTTP::Tiny->new->get(
32+
sprintf 'https://api.github.com/repos/%s/%s/pulls/%d?state=closed', $OWNER, $REPO, $pr_num
33+
);
34+
unless ($res->{success}) {
35+
warn 'API request failed'; return;
36+
}
37+
my $data = decode_json $res->{content};
38+
my $label = $data->{head}{label};
39+
$label =~ s!:!/!; # $user:branch/name -> $user/branch/name
40+
41+
if ($label ne $branch) {
42+
return;
43+
}
44+
($data->{head}{ref}, $data->{title}, $data->{body});
45+
}
46+
47+
sub tag_name_from_branch {
48+
my $branch = shift;
49+
50+
my ($tag) = $branch =~ m!^bump-version-([0-9]+(?:\.[0-9]+){2})$!;
51+
$tag && "v$tag";
52+
}
53+
54+
### main
55+
if (!$ENV{HARNESS_ACTIVE}) {
56+
main();
57+
} else {
58+
# When called via `prove`, tests will run.
59+
run_tests();
60+
}
61+
62+
sub main {
63+
# e.g. 492764e Merge pull request #3 from Songmu/fix/remote
64+
chomp(my $msg = `git log HEAD~.. --merges --oneline`);
65+
unless ($msg) {
66+
say 'not a merged commit'; return;
67+
}
68+
69+
my ($branch, $title, $body) = get_branch_from_msg($msg);
70+
unless ($branch) {
71+
say 'not a pull request'; return;
72+
}
73+
my $tag = tag_name_from_branch($branch);
74+
unless ($tag) {
75+
say 'not a autotag target'; return;
76+
}
77+
78+
my %tags = map { chomp; ($_ => 1) } `git tag`;
79+
if ($tags{$tag}) {
80+
say "tag: $tag already tagged"; return;
81+
}
82+
system(qw/git tag -a/, $tag, '-m', "$title\n\n$body");
83+
system(qw/git push --tags/);
84+
}
85+
86+
sub run_tests {
87+
require Test::More;
88+
Test::More->import;
89+
90+
my ($branch) = get_branch_from_msg('58a535b Merge pull request #44 from naokibtn/feature-munin');
91+
is($branch, 'feature-munin');
92+
($branch) = get_branch_from_msg('86b6a58 Merge pull request #36 from mackerelio/bump-version-0.5.0');
93+
is($branch, 'bump-version-0.5.0');
94+
95+
is(tag_name_from_branch('bump-version-0.5.0'), 'v0.5.0');
96+
ok(!tag_name_from_branch('feature-hoge'));
97+
98+
done_testing();
99+
}

0 commit comments

Comments
 (0)