diff --git a/.travis.yml b/.travis.yml index ee19df2b..7c2371ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,10 @@ language: go go: - 1.5 env: - - PATH=/home/travis/gopath/bin:$PATH DEBIAN_FRONTEND=noninteractive + global: + - PATH=~/gopath/bin:$PATH + - DEBIAN_FRONTEND=noninteractive + - secure: "eVK4VPUaQNF1a3CMUz/5jWaNY0+Wj10HnscPhcvmnH+IUJ+B6n2W4M5ht5WXEmx5EnKgLIZveL9CtPJTTsW4lE1RO03xfuVoe8+dElUSlKLJEHIDKm7koYgFEURWZXRcMAMqW2yj3y7D34fnwP4Evt/HuV8ZtWktMtJUzLr12oFxQDS0RC7II5nh8BiqSGCkKC8QJ6qQzbjZavBQ8M70Y4WWPArYHzwcSQjOLxhQmGCyx9JI7/nIqSosldFwqiFTh+UH3x7Pntt1Ji6Ra0rAuGFN28nQc8ISxfytwAgV4h7ubAWPUom2rXdUpHVvWZXoxDJr8YYq4rGRmyuLl/gBUfv72l/u8wIlMo5gRB2vJXHwKAaogSheGtdVwv7BwPSvjA6oOz5imqkhIm5kNgyrXaBglF7fornPiJNVgv2lMzuLB3GgqjYxhfipFahJT99x91/xd6kZ5OSSUVYkTx/0JwkEmGXyOJNzynC22VNHj6u1T41hkRHHSUjzrNBwNhMEcXDy75VaJukKMi9YyyHgehitWUFnGq0rakMz3tQxeO8K6YVQqjD7NWPiHh1vh4vWYRn2/T7ewTksW1h+/ETJR98YYsjpHnuQSJh6gGj6i4jKKy04hWagVciJ3Jr4i6ouA8ggKoEMzEB9KXd44yJoXk/ozk5VOXPithyp8NuA5BA=" sudo: false addons: apt: @@ -19,19 +22,26 @@ script: - make all after_script: - goveralls -coverprofile=.profile.cov -after_success: -- tool/travis/autotag.sh +before_deploy: +- go get github.com/aktau/github-release +- mkdir -p ~/bin +- git clone https://github.com/github/hub.git && cd hub && script/build -o ~/bin/hub && cd .. +- echo $TRAVIS_BRANCH +- git config --add remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*' +- git fetch +- git checkout master || git checkout -b master origin/master +- git checkout $TRAVIS_BRANCH +- git fetch --depth=100 || true +- git fetch --tags --depth=100 || true deploy: - provider: releases - api_key: - secure: vmMQz+IjJ/LUa9SHAlLKyg4raSqkEBIRzqnjS1LK7ZjtcAROo6Pn0lUcC4qMZ96/VvNMdLyGndCOBXsdE2VBCY5goTI7uIW1oxbLM3qOMNQQldG1bOY34bjkiiDU15WLUsKKPEC2RdgwG1aAAsqcUDAeyRABYVBANSn9jylQnBC2b2mQMYUtVA1O9jl3Qg64Cy6MUUirE/SuKp/cnE3AakcQt54pNVsnM54bIyrbGhqThLj7p7uLJEm58oRWR7TTUSgmk/Rbj4aJSC4k5lzN9iL/Fr5AgnpEQQUg3ishE+5yqSW7f/PRqXC6ZI9p6XS7bhS8N178ImzouIsoKWltblsgUhfvE6ONyMpi1+RG+6Lp3HlpLuq0Pz/efEpcaSDg6lXDIvMBC2sA5pbPok6Yx4tJOSv8adWu9t0yGVJezYaqbN/071K9m3cM4YTQK4L39b2FxQ2ZrUhee8HZy5rDO8iqx2vgM+NXATz2L5Tjjzd4aqfIDX8R3PVImBci7se/wmamDUpOrcfSjrI2dzEQGBzBfIFIhCaCQSuEjpZqBKdcOztkn1uev7a0AAUeZ7my+uQNpAMO7/AapM7LLugmkLM06FgrHKWDPQP/T92MPyvmC04nNraetAVijVYLQnlK5+TdEMvkKHuY5afLp5mEzX+7jTSmjyaUNrbANs8bH/8= - file: - - "/home/travis/rpmbuild/RPMS/noarch/mackerel-check-plugins-0.5.2-1.noarch.rpm" - - "/home/travis/gopath/src/github.com/mackerelio/go-check-plugins/packaging/mackerel-check-plugins_0.5.2-1_all.deb" +- provider: script + script: tool/releng --task=upload-to-github-release -v + skip_cleanup: true + on: + branch: master +- provider: script + script: tool/releng --task=create-pullrequest --current-branch=$TRAVIS_BRANCH --package-name=mackerel-check-plugins -v + skip_cleanup: true on: - repo: mackerelio/go-check-plugins all_branches: true - tags: true -notifications: - slack: - secure: gsM+oW5k6hQnL16ubkj0Iu7b3kSeUUGCErwWa8AIBdfk6DUYBxfFNkJkHJ+N44YJPuk/ijaTk8fzQ0HqD9H+Fegkv/KPMnJ00QxOD4XWv4URFACuGQgC2xB4G8OBg7StHPN68KroQn1ryNNoAwiZih///PGJyxb4uU/FrpA8iLATBoGoaEv8OrGkkwIepvtuHeRzyMPAjNvNO6evI0d/+Xn0YLRLtufdznHG3UHc/FJ306QkMz5hbP4iZqyNFlj6sFlvvovsozTqgGYYqKz2QbMzvR3l7xuFWiV6qa6zegy6sWp9pBWykQMm528R3pVDSu/f775shORLS4DaSV7ZM3Gw963gIgfdmcqLi6KP8j+NqqyveUAq5C6JOaVDTKwJg+b2yL6TYYEQ4Lz7WiOLLmjj9V+9+i5oy852FfQEG/en9+jnPDuWDI0ILKTW8EqcQfCf46mtV0TiWY4if5iYAVUOl2O5Jam9LTX9YSeRA0qq9022tJ60GpIvX9vskO2SXTdAAQRRqM5dliOYblo0H3AmBQWTixH+AgcOP0nzAugIRX07Kpni9GfOL5bW3lBVJo1502DZWLdKoF1ulS/nHfWdz9TwuocX8hOko/H3yNH8Lt9DyodgXgWDwtYuHeuXxw7gTcaPX4K3wGgshnaBZXrryWH6u7UPT8hFePqsD58= + condition: "$TRAVIS_BRANCH =~ ^bump-version-.*$" diff --git a/Makefile b/Makefile index e1a71a25..0fa1d8cb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ TARGET_OSARCH="linux/amd64" +CURRENT_VERSION = $(shell git log --merges --oneline | perl -ne 'if(m/^.+Merge pull request \#[0-9]+ from .+\/bump-version-([0-9\.]+)/){print $$1;exit}') + +check-variables: + echo "CURRENT_VERSION: ${CURRENT_VERSION}" all: clean test build rpm deb @@ -28,13 +32,17 @@ build: deps for i in check-*; do \ gox -ldflags "-s -w" \ -osarch=$(TARGET_OSARCH) -output build/$$i \ - github.com/mackerelio/go-check-plugins/$$i; \ + `pwd | sed -e "s|${GOPATH}/src/||"`/$$i; \ done rpm: build - rpmbuild --define "_sourcedir `pwd`" -ba packaging/rpm/mackerel-check-plugins.spec + TARGET_OSARCH="linux/386" make build + rpmbuild --define "_sourcedir `pwd`" --define "_version ${CURRENT_VERSION}" --define "buildarch noarch" -bb packaging/rpm/mackerel-check-plugins.spec + TARGET_OSARCH="linux/amd64" make build + rpmbuild --define "_sourcedir `pwd`" --define "_version ${CURRENT_VERSION}" --define "buildarch x86_64" -bb packaging/rpm/mackerel-check-plugins.spec -deb: build +deb: deps + TARGET_OSARCH="linux/386" make build cp build/check-* packaging/deb/debian/ cd packaging/deb && debuild --no-tgz-check -rfakeroot -uc -us @@ -45,7 +53,4 @@ clean: fi go clean -release: - tool/releng - .PHONY: all test deps devel-deps lint cover build rpm deb clean release diff --git a/packaging/rpm/mackerel-check-plugins.spec b/packaging/rpm/mackerel-check-plugins.spec index b9f765f3..dbccaea9 100644 --- a/packaging/rpm/mackerel-check-plugins.spec +++ b/packaging/rpm/mackerel-check-plugins.spec @@ -4,14 +4,14 @@ %define __oldtargetdir /usr/local/bin Name: mackerel-check-plugins -Version: 0.5.2 +Version: %{_version} Release: 1 License: Commercial Summary: macekrel.io check plugins URL: https://mackerel.io Group: Hatena Packager: Hatena -BuildArch: noarch +BuildArch: %{buildarch} BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root %description diff --git a/tool/autotag b/tool/autotag deleted file mode 100755 index ac9e5ebf..00000000 --- a/tool/autotag +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env perl - -=head DESCRIPTION - -Automatically `git tag` by travisCI. - -When the pull request is merged and the branch name is like "bump-version-N.N.N", -the merge commit is automatically tagged as `vN.N.N`. - -=head SYNOPSIS - - % tool/autotag - -=cut - -use 5.014; -use warnings; - -use HTTP::Tiny; -use JSON::PP; - -my $OWNER = 'mackerelio'; -my $REPO = 'go-check-plugins'; - -sub get_branch_from_msg { - my $msg = shift; - - my ($pr_num, $branch) = $msg =~ /^[a-f0-9]{7} Merge pull request #([0-9]+) from (.*)$/; - return unless $pr_num; - - my $res = HTTP::Tiny->new->get( - sprintf 'https://api.github.com/repos/%s/%s/pulls/%d?state=closed', $OWNER, $REPO, $pr_num - ); - unless ($res->{success}) { - warn 'API request failed'; return; - } - my $data = decode_json $res->{content}; - my $label = $data->{head}{label}; - $label =~ s!:!/!; # $user:branch/name -> $user/branch/name - - if ($label ne $branch) { - return; - } - ($data->{head}{ref}, $data->{title}, $data->{body}); -} - -sub tag_name_from_branch { - my $branch = shift; - - my ($tag) = $branch =~ m!^bump-version-([0-9]+(?:\.[0-9]+){2})$!; - $tag && "v$tag"; -} - -### main -if (!$ENV{HARNESS_ACTIVE}) { - main(); -} else { - # When called via `prove`, tests will run. - run_tests(); -} - -sub main { - # e.g. 492764e Merge pull request #3 from Songmu/fix/remote - chomp(my $msg = `git log HEAD~.. --merges --oneline`); - unless ($msg) { - say 'not a merged commit'; return; - } - - my ($branch, $title, $body) = get_branch_from_msg($msg); - unless ($branch) { - say 'not a pull request'; return; - } - my $tag = tag_name_from_branch($branch); - unless ($tag) { - say 'not a autotag target'; return; - } - - my %tags = map { chomp; ($_ => 1) } `git tag`; - if ($tags{$tag}) { - say "tag: $tag already tagged"; return; - } - system(qw/git tag -a/, $tag, '-m', "$title\n\n$body"); - system(qw/git push --tags/); -} - -sub run_tests { - require Test::More; - Test::More->import; - - my ($branch) = get_branch_from_msg('58a535b Merge pull request #44 from naokibtn/feature-munin'); - is($branch, 'feature-munin'); - ($branch) = get_branch_from_msg('86b6a58 Merge pull request #36 from mackerelio/bump-version-0.5.0'); - is($branch, 'bump-version-0.5.0'); - - is(tag_name_from_branch('bump-version-0.5.0'), 'v0.5.0'); - ok(!tag_name_from_branch('feature-hoge')); - - done_testing(); -} diff --git a/tool/releng b/tool/releng index 1b58f6ed..b8f62e99 100755 --- a/tool/releng +++ b/tool/releng @@ -2,15 +2,23 @@ =head DESCRIPTION -releng script for mackerel-check-plugins +Release Engineering script for mackerel related packages. =head SYNOPSIS - % tool/releng + % releng + --help + --task= # 'create-pullrequest' or 'github-release' + --next-version= # specify next version. if not specified, a + # value derived from the branch name is used. + --package-name= # target package name. if not specified, + # the repository name is used. + --verbose + --dry-run =head DEPENDENCY -`git` command and `hub` or `gh` command are required. +`git` command and `hub` (or `gh`) command and `github-release` command are required. =cut @@ -26,32 +34,99 @@ use ExtUtils::MakeMaker qw/prompt/; use Time::Piece; use POSIX qw(setlocale LC_TIME); use version; +use Getopt::Long; +use File::Basename; -sub DEBUG() { $ENV{MC_RELENG_DEBUG} } +chomp(my $REPO_NAME = `git rev-parse --show-toplevel`); +$REPO_NAME =~ s|^.+/([^/]+/[^/]+)$|$1|; +$REPO_NAME =~ m!/([^/]+)$!; +my $REPO = $1; +my $dry_run; +my $verbose; +my $next_version; +my $package_name = $REPO; + +sub DEBUG() { $ENV{MC_RELENG_DEBUG} || $verbose } sub command {say('+ '. join ' ', @_) if DEBUG; !system(@_) or croak $!} +sub command_with_exit_code {say('+ '. join ' ', @_) if DEBUG; system(@_)} sub _git { - state $com = do { + if($dry_run){ + return + } + state $com = do { chomp(my $c = `which git`); die "git command is required\n" unless $c; $c; }; } sub git { + if($dry_run){ + return + } unshift @_, _git; goto \&command } +sub git_with_exit_code { + if($dry_run){ + return + } + unshift @_, _git; goto \&command_with_exit_code +} + + sub _hub { + if($dry_run){ + return + } state $com = do { chomp(my $c = `which hub`); - die "hub command is required\n" unless $c; + unless ($c) { + chomp($c = `which gh`); + } + die "hub or gh command is required\n" unless $c; $c; }; } sub hub { + if($dry_run){ + return + } unshift @_, _hub; goto \&command; } +sub hub_with_exit_code { + if($dry_run){ + return + } + unshift @_, _hub; goto \&command_with_exit_code; +} + +sub _github_release { + if($dry_run){ + return + } + state $com = do { + chomp(my $c = `which github-release`); + die "github-release command is required\n" unless $c; + $c; + }; +} +sub github_release { + if($dry_run){ + return + } + unshift @_, _github_release; goto \&command +} + +sub github_release_with_exit_code { + if($dry_run){ + return + } + unshift @_, _github_release; goto \&command_with_exit_code +} + + sub http_get { my $url = shift; my ($ok, $err, undef, $stdout) = run(command => [qw{curl -sf}, $url]); @@ -63,7 +138,7 @@ sub http_get { # logger. steal from minilla use Term::ANSIColor qw(colored); -use constant { LOG_DEBUG => 1, LOG_INFO => 2, LOG_WARN => 3, LOG_ERROR => 4 }; +use constant { LOG_DEBUG => 1, LOG_INFO => 2, LOG_WARN => 3, LOG_ERROR => 4 }; my $Colors = { LOG_DEBUG, => 'green', @@ -108,6 +183,7 @@ sub spew { } sub replace { my ($file, $code) = @_; + if(!-f $file){ errorf "File does not exist: %s\n", $file; } my $content = $code->(slurp($file)); spew($file, $content); } @@ -134,22 +210,48 @@ sub last_release { my ($tag) = sort { version->parse($b) <=> version->parse($a) } - map {/^v([0-9]+(?:\.[0-9]+){2})$/; $1 || ()} + map {if(/^\d.\d$/){ $_ . ".0" } else { $_ } } + map {if(/^v([0-9]+(?:\.[0-9]+)+)$/){ $1 } else { () }} map {chomp; $_} @out; $tag; } +sub current_branch { + chomp(my $branch = `git symbolic-ref --short HEAD`); + return $branch; +} + +sub next_version { + return $next_version if $next_version; + if(current_branch() =~ /^bump-version-([\d\.]+)$/){ + return $next_version = $1; + } elsif(current_branch() =~ /^master$/){ + my $next = `git log --merges --oneline`; + if($next =~ /^.+Merge pull request #[0-9]+ from .+\/bump-version-([0-9\.]+)$/m){ + return $next_version = $1; + } + } + return ""; +} + +sub diff { + git_with_exit_code qw/diff --exit-code/ +} + sub merged_prs { my $current_tag = shift; - my @pull_nums = sort {$a <=> $b} map {m/Merge pull request #([0-9]+) /; $1 || () } `git log v$current_tag... --merges --oneline`; + my @pull_nums = sort {$a <=> $b} map { + if(m/Merge pull request #([0-9]+) /){ $1 } else { () } + } `git log v$current_tag... --merges --oneline`; + say "Pull Requests: " . join(", ", @pull_nums); my @releases; for my $pull_num (@pull_nums) { - my $url = sprintf "https://api.github.com/repos/mackerelio/go-check-plugins/pulls/%d?state=closed", $pull_num; + my $url = sprintf "https://api.github.com/repos/%s/pulls/%d?state=closed", $REPO_NAME, $pull_num; my $res = http_get($url); unless ($res->{success}) { warnf "request to $url failed\n"; - exit; + next; #exit; } my $data = eval { decode_json $res->{content} }; if ($@) { @@ -173,96 +275,13 @@ sub parse_version { ($major, $minor, $patch) } -sub suggest_next_version { - my $ver = shift; - my ($major, $minor, $patch) = parse_version($ver); - join '.', $major, ++$minor, 0; -} - -sub is_valid_version { - my $ver = shift; - my ($major) = parse_version($ver); - defined $major; -} - -sub decide_next_version { - my $current_version = shift; - my $next_version = suggest_next_version($current_version); - $next_version = prompt("next version", $next_version); - - if (!is_valid_version($next_version)) { - die qq{"$next_version" is invalid version string\n}; - } - if (version->parse($next_version) < version->parse($current_version)) { - die qq{"$next_version" is smaller than current version "$current_version"\n}; - } - $next_version; -} - -sub update_versions { - my ($current_version, $next_version) = @_; - - ### update versions - my $cur_ver_reg = quotemeta $current_version; - # update .travis.yml - replace '.travis.yml' => sub { - my $content = shift; - $content =~ s/$cur_ver_reg/$next_version/msg; - $content; - }; - - # update rpm spec - replace 'packaging/rpm/mackerel-check-plugins.spec' => sub { - my $content = shift; - $content =~ s/^(Version:\s+)$cur_ver_reg/$1$next_version/ms; - $content; - }; - -} - -sub retrieve_plugins { - my @plugin_dirs = ; - for my $plugin_dir (@plugin_dirs) { - my $readme = "$plugin_dir/README.md"; - unless (-f $readme) { - warnf "[$readme] is misssing!!! You must locate it.\n"; - } - } - sort map {s/^check-//; $_} @plugin_dirs; -} - -sub update_readme { - my @plugins = @_; - - my $doc_links = ''; - for my $plug (@plugins) { - $doc_links .= "* [check-$plug](./check-$plug/README.md)\n" - } - replace 'README.md' => sub { - my $readme = shift; - my $plu_reg = qr/check-[-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.*?;do/$for_in/ms; - $content; - }; - replace $_, $replace_sub for qw!packaging/rpm/mackerel-check-plugins.spec packaging/deb/debian/rules!; -} - sub update_changelog { my ($next_version, @releases) = @_; - chomp(my $email = `git config user.email`); - chomp(my $name = `git config user.name`); + my $email = 'mackerel-developers@hatena.ne.jp'; + my $name = 'mackerel'; + #chomp(my $email = `git config user.email`); + #chomp(my $name = `git config user.name`); my $old_locale = setlocale(LC_TIME); setlocale(LC_TIME, "C"); @@ -271,26 +290,43 @@ sub update_changelog { }; my $now = localtime; + my $ret = 0; replace 'packaging/deb/debian/changelog' => sub { my $content = shift; - my $update = "mackerel-check-plugins ($next_version-1) stable; urgency=low\n\n"; + my $update = "$package_name ($next_version-1) stable; urgency=low\n\n"; for my $rel (@releases) { $update .= sprintf " * %s (by %s)\n <%s>\n", $rel->{title}, $rel->{user}, $rel->{url}; } $update .= sprintf "\n -- %s <%s> %s\n\n", $name, $email, $now->strftime("%a, %d %b %Y %H:%M:%S %z"); - $update . $content; + + # '35' means a rough length to cut timestamp at the end of update. + if(index($content, substr($update, 0, length($update) - 35)) == -1){ + infof "update 'packaging/deb/debian/changelog'.\n"; + $ret = 1; + $update . $content; + } else { + infof "skip to update 'packaging/deb/debian/changelog'.\n"; + $content; + } }; - replace 'packaging/rpm/mackerel-check-plugins.spec' => sub { + my $spec = sprintf "packaging/rpm/%s.spec", $package_name; + replace $spec => sub { my $content = shift; - my $update = sprintf "* %s <%s> - %s\n", $now->strftime('%a %b %d %Y'), $email, $next_version; + my $update = sprintf "* %s <%s> - %s-1\n", $now->strftime('%a %b %d %Y'), $email, $next_version; for my $rel (@releases) { $update .= sprintf "- %s (by %s)\n", $rel->{title}, $rel->{user}; } - $content =~ s/%changelog/%changelog\n$update/; + if(index($content, $update) == -1){ + infof "update '%s'\n", $spec; + $ret = 1; + $content =~ s/%changelog/%changelog\n$update/; + } else { + infof "skip to update '%s'\n", $spec; + } $content; }; @@ -301,9 +337,16 @@ sub update_changelog { for my $rel (@releases) { $update .= sprintf "* %s #%d (%s)\n", $rel->{title}, $rel->{num}, $rel->{user}; } - $content =~ s/\A# Changelog/# Changelog$update/; + if(index($content, $update) == -1){ + infof "update 'CHANGELOG.md'\n"; + $ret = 1; + $content =~ s/\A# Changelog/# Changelog$update/; + } else { + infof "skip to update 'CHANGELOG.md'\n"; + } $content; }; + $ret; } sub build_pull_request_body { @@ -315,60 +358,148 @@ sub build_pull_request_body { $body; } -sub load_packaging_confg { - decode_json slurp 'packaging/config.json'; -} +sub upload_to_github_release { + my $ret = github_release_with_exit_code qw/release --user/, "mackerelio", + qw/--repo/, $REPO, + qw/--tag/, "v". next_version(), + qw/--name/, $REPO ."-" . next_version(), + qw/--description/, "pre-release", + qw/--pre-release/; -### main process -if (!$ENV{HARNESS_ACTIVE}) { - main() unless caller; -} else { - # When called via `prove`, tests will run. - run_tests(); -} + if($ret != 0){ + infof "The release of this version has already existed at GitHub Release, so skip the process.\n"; + return; + } -sub main { - # check command - _git;_hub; + # upload files + my $description = ""; + my @filepaths = glob("~/rpmbuild/RPMS/*/*.rpm packaging/*.deb snapshot/*.zip"); + infof "uploading following files:\n" . join("\n", @filepaths). "\n"; + for my $path (@filepaths){ + my $filename = basename($path); + $description .= "* $filename\n"; + github_release qw/upload --user/, "mackerelio", + qw/--repo/, $REPO, + qw/--tag/, "v". next_version(), + qw/--name/, $filename, + qw/--file/, $path; + } + github_release qw/edit --user/, "mackerelio", + qw/--repo/, $REPO, + qw/--tag/, "v". next_version(), + qw/--description/, $description; +} - git qw/checkout master/; - git qw/pull/; +sub create_pull_request { + my($current_branch) = @_; - my $config = load_packaging_confg; + git qw/checkout/, $current_branch; my $current_version = last_release; - my $next_version = decide_next_version($current_version); - - my $branch_name = "bump-version-$next_version"; - infof "checkout new releasing branch [$branch_name]\n"; - git qw/checkout -b/, $branch_name; + my $next_version = next_version; + if(!$next_version) { + warnf("current branch should be 'bump-version-x.y.z'.\n"); + return; + } - infof "bump versions and update readme\n"; - update_versions($current_version, $next_version); - my @plugins = retrieve_plugins; - update_readme(@plugins); - update_packaging_specs(@{ $config->{plugins} }); - git qw/commit -am/, "ready for next release. version: $next_version"; + # return if last commit is updating specs and changelogs + my $last_commitlog = `git log -1 --oneline | cut -d ' ' -f2-`; + if($last_commitlog =~ /update changelogs/){ + infof "skip to update changelogs because the last commit is 'update changelogs'.\n"; + return; + } - infof "update changelogs\n"; + infof "Update changelogs, between %s and %s.\n", $current_version, $next_version; my @releases = merged_prs $current_version; - update_changelog($next_version, @releases); - git qw/commit -am/, "update changelogs"; + my $ret = 0; + if(@releases){ + $ret = update_changelog($next_version, @releases); + } else { + infof "skip to update changelogs because no merged pull request is found after the last release.\n" + } + if($ret || git_with_exit_code qw/diff --exit-code/){ + git qw/commit -am/, "update changelogs"; + git qw/config --global push.default matching/; + git qw/config user.email/, 'mackerel-developers@hatena.ne.jp'; + git qw/config user.name/, 'mackerel'; + git qw/push -u/, "https://$ENV{GITHUB_TOKEN}\@github.com/$REPO_NAME.git"; + infof "Difference is pushed to GitHub.\n"; + } - git qw/diff/, qw/--word-diff/, "master..$branch_name"; + #git qw/diff/, qw/--word-diff/, "master..".current_branch(); my $pr_body = build_pull_request_body($next_version, @releases); + say "Pull Request\n--------"; say $pr_body; - if (prompt('push changes?', 'y') !~ /^y(?:es)?$/i ) { - warnf('releng is aborted. remove the branch [%s] before next releng', $branch_name); - return; + infof "Push changes\n"; + git qw/pull/; + $ret = hub_with_exit_code qw/pull-request -m/, $pr_body, qq/-b/, qq/$REPO_NAME:master/; + if(!defined($ret) || $ret == 0){ + infof "Releasing pull request is created. Review and merge it. You can update changelogs and commit more in this branch before merging.\n"; + } else { + # do push and pull-request again + git qw/push -u/, "https://$ENV{GITHUB_TOKEN}\@github.com/$REPO_NAME.git"; + $ret = hub_with_exit_code qw/pull-request -m/, $pr_body, qq/-b/, qq/$REPO_NAME:master/; + if(!defined($ret) || $ret == 0){ + infof "Releasing pull request is created. Review and merge it. You can update changelogs and commit more in this branch before merging.\n"; + } else { + infof "Pull Request already seems to exist.\n" + } } +} + +### main process +if (!$ENV{HARNESS_ACTIVE}) { + main(); +} else { + # When called via `prove`, tests will run. + run_tests(); +} - infof "push changes\n"; - git qw/push --set-upstream origin/, $branch_name; - hub qw/pull-request -m/, $pr_body; +sub help { + print < # 'create-pullrequest' or 'github-release' + --next-version= # specify next version. if not specified, a + # value derived from the branch name is used. + --package-name= # target package name. if not specified, + # the repository name is used. + --verbose + --dry-run +EOS - infof "Releasing pull request is created. Review and merge it. You can update changelogs and commit more in this branch before merging.\n"; +} + +sub main { + my $help; + my $task; + my $current_branch; + GetOptions ("help" => \$help, + "task=s" => \$task, # create-pullrequest, upload_to_github_release + "verbose" => \$verbose, + "dry-run" => \$dry_run, + "current-branch=s" => \$current_branch, + "next-version=s" => \$next_version, + "package-name=s" => \$package_name, + ); + + if($help){ + help(); + exit 0; + } + # check command + _git;_hub; + + if($task eq "create-pullrequest"){ + infof "Create a Pull Request for version up.\n"; + create_pull_request($current_branch); + return; + } elsif($task eq "upload-to-github-release"){ + infof "Upload files to GitHub Release.\n"; + upload_to_github_release(); + return; + } } sub run_tests { @@ -380,17 +511,6 @@ sub run_tests { is($major, 0); is($minor, 1); is($patch, 2); - is( suggest_next_version($version), '0.2.0' ); - my $config = load_packaging_confg; - ok($config->{description}); - - my $plugins_to_be_packaged = $config->{plugins}; - isa_ok($plugins_to_be_packaged, 'ARRAY'); - - my %plugins = map { $_ => 1, } retrieve_plugins; - for my $plug (@$plugins_to_be_packaged) { - ok($plugins{$plug}, "$plug ok"); - } done_testing(); } diff --git a/tool/travis/autotag.sh b/tool/travis/autotag.sh deleted file mode 100755 index 8d493ddf..00000000 --- a/tool/travis/autotag.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -set -e - -deploykey=~/.ssh/deploy.key - -echo " -Host github.com - StrictHostKeyChecking no - IdentityFile $deploykey -" >> ~/.ssh/config -openssl aes-256-cbc -K $encrypted_87d0e2b1ee75_key -iv $encrypted_87d0e2b1ee75_iv -in tool/travis/go-check-plugins.pem.enc -out $deploykey -d -chmod 600 $deploykey -git config --global user.email "mackerel-developers@hatena.ne.jp" -git config --global user.name "mackerel" -git remote set-url origin git@github.com:mackerelio/go-check-plugins.git -tool/autotag