Skip to content

Commit 66adc0d

Browse files
committed
More release automation
Set annotated git tags with the related changelog entry. Upload all release files as part of "rake release".
1 parent 38250ff commit 66adc0d

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

Rakefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require 'rake/clean'
1111
require 'rspec/core/rake_task'
1212
require 'bundler'
1313
require 'bundler/gem_helper'
14+
require_relative "rakelib/pg_gem_helper"
1415

1516
# Build directory constants
1617
BASEDIR = Pathname( __FILE__ ).dirname
@@ -34,7 +35,7 @@ CLEAN.include "lib/pg/postgresql_lib_path.rb"
3435
CLEAN.include "ports/*.installed"
3536
CLEAN.include "ports/*mingw*", "ports/*linux*", "ports/*darwin*"
3637

37-
Bundler::GemHelper.install_tasks
38+
PgGemHelper.install_tasks
3839
$gem_spec = Bundler.load_gemspec(GEMSPEC)
3940

4041
desc "Turn on warnings and debugging in the build."
@@ -56,6 +57,9 @@ CrossLibraries = [
5657
CrossLibrary.new platform, openssl_config, toolchain
5758
end
5859

60+
# Register binary gems to be pushed to rubygems.org
61+
Bundler::GemHelper.instance.cross_platforms = CrossLibraries.map(&:platform)
62+
5963
# Rake-compiler task
6064
Rake::ExtensionTask.new do |ext|
6165
ext.name = 'pg_ext'

rakelib/pg_gem_helper.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require 'bundler'
2+
require 'bundler/gem_helper'
3+
4+
class PgGemHelper < Bundler::GemHelper
5+
attr_accessor :cross_platforms
6+
7+
def install
8+
super
9+
10+
task "release:guard_clean" => ["release:update_history"]
11+
12+
task "release:update_history" do
13+
update_history
14+
end
15+
16+
task "release:rubygem_push" => ["gem:native"]
17+
end
18+
19+
def hfile
20+
"CHANGELOG.md"
21+
end
22+
23+
def headline
24+
'([^\w]*)v(\d+\.\d+\.\d+(?:\.\w+)?)([^\w]+)([2Y][0Y][0-9Y][0-9Y]-[0-1M][0-9M]-[0-3D][0-9D])([^\w]*|$)'
25+
end
26+
27+
def reldate
28+
Time.now.strftime("%Y-%m-%d")
29+
end
30+
31+
def update_history
32+
hin = File.read(hfile)
33+
hout = hin.sub(/#{headline}/) do
34+
raise "#{hfile} isn't up-to-date for version #{version}" unless $2==version.to_s
35+
$1 + $2 + $3 + reldate + $5
36+
end
37+
if hout != hin
38+
Bundler.ui.confirm "Updating #{hfile} for release."
39+
File.write(hfile, hout)
40+
Rake::FileUtilsExt.sh "git", "commit", hfile, "-m", "Update release date in #{hfile}"
41+
end
42+
end
43+
44+
def tag_version
45+
Bundler.ui.confirm "Tag release with annotation:"
46+
m = File.read(hfile).match(/(?<annotation>#{headline}.*?)#{headline}/m) || raise("Unable to find release notes in #{hfile}")
47+
Bundler.ui.info(m[:annotation].gsub(/^/, " "))
48+
IO.popen(["git", "tag", "--file=-", version_tag], "w") do |fd|
49+
fd.write m[:annotation]
50+
end
51+
yield if block_given?
52+
rescue
53+
Bundler.ui.error "Untagging #{version_tag} due to error."
54+
sh_with_code "git tag -d #{version_tag}"
55+
raise
56+
end
57+
58+
def rubygem_push(path)
59+
cross_platforms.each do |ruby_platform|
60+
super(path.gsub(/\.gem\z/, "-#{ruby_platform}.gem"))
61+
end
62+
super(path)
63+
end
64+
end

0 commit comments

Comments
 (0)