Created
March 27, 2013 08:04
-
-
Save mizzy/5252543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
use String::IRC; | |
use JSON; | |
my $ukigumo_base_url = 'http://ukigumo.example.jp:5000'; | |
my $repo_url = 'git@github.com:foo/puppet.git'; | |
my $repo_dir = '/home/mizzy/puppet'; | |
my $ikachan_base_url = 'http://ikachan.example.jp:4969'; | |
chdir $repo_dir; | |
my $res = `git pull origin master 2> /dev/null`; | |
exit if $res =~ /Already up-to-date/; | |
my $rev = `git log |grep '^commit' |head -1|awk '{print \$2}'`; | |
chomp $rev; | |
for my $role ( 'base', 'manage', 'hosting-bench' ) { | |
# Apply puppet manifests | |
my $cmd = "/usr/bin/ssh ${role}.lxc-test-box puppet agent --server=puppet-ci.kiban.pb \\ | |
--onetime --no-daemonize --no-usecacheonfailure --ignorecache --show_diff \\ | |
--no-splay --verbose --color=false"; | |
my $res = `$cmd`; | |
my $args = {}; | |
$args->{status} = $? == 0 ? 1 : 2; | |
$args->{project} = "Apply puppet manifests to $role role container"; | |
$args->{branch} = 'master'; | |
$args->{body} = $res; | |
$args->{rev} = $rev; | |
$args->{repo} = $repo_url; | |
post_result($args); | |
# Run serverspec | |
my $task = $role; | |
$task =~ s/\-/_/g; | |
$cmd = "rake spec:$task"; | |
$res = `$cmd`; | |
$args = {}; | |
$args->{status} = $? == 0 ? 1 : 2; | |
$args->{project} = "Run serverspec to $role role container"; | |
$args->{branch} = 'master'; | |
$args->{body} = $res; | |
$args->{rev} = $rev; | |
$args->{repo} = $repo_url; | |
post_result($args); | |
} | |
sub post_result { | |
my $args = shift; | |
my $status = $args->{status}; | |
my $ua = LWP::UserAgent->new(); | |
my $res = $ua->post("$ukigumo_base_url/api/v1/report/add", [ | |
status => $status, | |
project => $args->{project}, | |
branch => $args->{branch}, | |
body => $args->{body}, | |
revision => $args->{rev}, | |
repo => $args->{repo}, | |
]); | |
$res = decode_json($res->content); | |
my $message = $status == 1 ? 'Success: ' : 'Fail: '; | |
$message .= $args->{project} . ' ' . $res->{report}->{url}; | |
$message = String::IRC->new($message); | |
if ( $status == 1 ) { | |
$message->green; | |
} | |
else { | |
$message->red; | |
} | |
$ua->post("$ikachan_base_url/join", [ | |
channel => '#channel', | |
]); | |
$ua->post("$ikachan_base_url/notice", [ | |
channel => '#channel', | |
message => $message, | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment