forked from poka-yoke/skyed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
111 lines (103 loc) · 3.71 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require 'coveralls'
Coveralls.wear!
task test: :spec
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task test: :rubocop
SimpleCov.command_name 'Rubocop'
task :rubocop do
sh 'rubocop'
end
task :'clean-tmp' do
require 'fileutils'
paths = %w(/tmp/.skyed /tmp/.ansible /tmp/.vagrant.d /tmp/Library)
paths += %w( /tmp/Virtualbox\ VMs /tmp/opsworks /tmp/.vbox-ifosch-ipc)
paths.each do |path|
puts "Removing #{path}..."
FileUtils.rm_rf(path)
end
end
task :'build-tmp' do
require 'git'
current_repo = Git.open(Dir.pwd)
current_remote = current_repo.remote('origin').url
current_remote ||= current_repo.remotes.first.url
user = current_remote.split(':')[1].split('/')[-2]
remote = ENV['OW_REMOTE'] || current_remote.sub('skyed', 'opsworks')
puts "Cloning #{remote} into /tmp/opsworks"
Git.clone(remote, '/tmp/opsworks') unless File.directory?('/tmp/opsworks')
user_remote = remote.split(':')[0] + ':' + user + '/' + remote.split('/')[-1]
repo = Git.open('/tmp/opsworks')
puts "Adding remote #{user} with url: #{user_remote}"
repo.add_remote(user, user_remote) unless repo.remote(user).url
end
task :build do
require 'rubygems'
require 'gems'
puts 'Comparing versions'
gemspec_re = /version\s+=\s+'([^']*)'$/
current = File.open('skyed.gemspec').read.match(gemspec_re)[1]
versions = Gems.versions('skyed').collect { |g| g['number'] }
versions.each do |v|
msg = "Gemspec version (#{current}) is the last version"
msg += " (#{v}). Try release"
fail msg if v == current
end
build
end
def build
puts 'Building'
`gem build skyed.gemspec`
end
def publish(version)
require 'fileutils'
require 'rubygems'
require 'gems'
puts 'Publishing'
Gems.push File.new "skyed-#{version}.gem" unless ENV['FAKE']
FileUtils.rm "skyed-#{version}.gem" unless ENV['FAKE']
end
task :release do
require 'git'
changelog_re = /## (\d+\.\d+\.\d+(|\..*)) \(\?\?\?\?-\?\?-\?\?\)/
changelog = File.open('CHANGELOG.md').read
changelog_matches = changelog.match(changelog_re)
new_version = changelog_matches[1]
new_date = Time.now.strftime('%04Y-%02m-%02d')
gemspec_re = /version\s+=\s+'([^']*)'$/
gemspec = File.open('skyed.gemspec').read
current = gemspec.match(gemspec_re)[1]
fail 'Update your CHANGELOG first, please' if current == new_version
repo = Git.open('.')
fail 'Switch to master and merge' unless repo.current_branch == 'master'
skyed = File.open('lib/skyed.rb').read
skyed_version_re = /VERSION(\s+)=(\s+).*/
new_skyed = skyed.gsub(skyed_version_re, "VERSION\\1=\\2'#{new_version}'")
gspec_version_re = /version(\s+)=(\s+).*/
new_gemspec = gemspec.gsub(gspec_version_re, "version\\1=\\2'#{new_version}'")
date_re = /date(\s+)=(\s+)'.*'/
new_gemspec = new_gemspec.gsub(date_re, "date\\1=\\2'#{new_date}'")
date_re = /## #{new_version} .*/
new_changelog = changelog.gsub(date_re, "## #{new_version} (#{new_date})")
puts "Updating CHANGELOG: #{new_changelog.lines.first}"
File.open('CHANGELOG.md', 'w') { |f| f.puts new_changelog } unless ENV['FAKE']
puts "Updating lib/skyed.rb: #{new_skyed.match(skyed_version_re)}"
File.open('lib/skyed.rb', 'w') { |f| f.puts new_skyed } unless ENV['FAKE']
puts "Updating gemspec: #{new_gemspec.match(gspec_version_re)}"
File.open('skyed.gemspec', 'w') { |f| f.puts new_gemspec } unless ENV['FAKE']
unless ENV['FAKE']
repo.add('lib/skyed.rb')
repo.add('skyed.gemspec')
repo.add('CHANGELOG.md')
repo.commit('Updates gemspec')
end
puts 'Tagging'
repo.add_tag(
"v#{new_version}",
a: "v#{new_version}",
m: "Releasing #{new_version}") unless ENV['FAKE']
puts 'Pushing'
repo.push(repo.remote('ifosch'), 'master', tags: true) unless ENV['FAKE']
build unless ENV['FAKE']
publish(new_version)
end