-
Notifications
You must be signed in to change notification settings - Fork 53
/
release
executable file
·74 lines (58 loc) · 2 KB
/
release
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
#!/usr/bin/env ruby
require 'pathname'
require 'date'
MAIN_FILE = 'blueutil.m'
DEFINE_VERSION_REGEXP = /(?<=#define VERSION ")\d+(?:\.\d+)+(?=")/
version_parts = File.read(MAIN_FILE)[DEFINE_VERSION_REGEXP].split('.').map(&:to_i)
new_version = case ARGV
when %w[major]
"#{version_parts[0] + 1}.0.0"
when %w[minor]
"#{version_parts[0]}.#{version_parts[1] + 1}.0"
when %w[patch]
"#{version_parts[0]}.#{version_parts[1]}.#{version_parts[2] + 1}"
else
abort 'Expected major, minor or patch as the only argument'
end
def clean_workind_directory?
`git status --porcelain`.empty?
end
clean_workind_directory? or abort('Working directory not clean')
system './update_usage'
clean_workind_directory? or abort('Usage in README is not up to date')
paths = Pathname.glob('*').select do |path|
next unless path.file?
next if path.executable?
original = path.read
changed = original.gsub(/(?<before>Copyright \(c\) )(?<year>\d+)(?:-\d+)?(?<after> \w+ \w+)/) do
m = Regexp.last_match
"#{m[:before]}#{[m[:year].to_i, Time.now.year].uniq.join('-')}#{m[:after]}"
end
case path.to_s
when MAIN_FILE
changed = changed.sub(DEFINE_VERSION_REGEXP, new_version)
when 'CHANGELOG.md'
lines = changed.lines
{
2 => "## unreleased\n",
3 => "\n",
}.each do |n, expected|
abort "Expected #{expected} on line #{n}, got #{lines[n]}" unless lines[n] == expected
end
lines.insert(3, "\n", "## v#{new_version} (#{Date.today.strftime('%Y-%m-%d')})\n")
changed = lines.join
end
next if original == changed
path.open('w'){ |f| f.write(changed) }
end
Pathname('blueutil').unlink
system(*%w[make blueutil]) or abort('failed to build')
`./blueutil -h`[new_version] or abort('did not find new version in help output')
system *%w[git add] + paths.map(&:to_s)
system *%w[git diff --cached]
puts %q{Type "yes" to continue}
abort unless $stdin.gets.strip == 'yes'
system *%W[git commit -m v#{new_version}]
system *%W[git tag v#{new_version}]
system *%w[git push]
system *%w[git push --tags]