forked from 4-20ma/ModbusMaster
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
171 lines (128 loc) · 4.78 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# encoding: utf-8
require 'git'
require 'rake'
require 'rubygems'
require 'rake/version_task' # gem install version
require 'version'
Rake::VersionTask.new do |task|
# prevent auto-commit on version bump
task.with_git = false
end
# adjust as appropriate
GITHUB_USERNAME = '4-20ma'
GITHUB_REPO = 'ModbusMaster'
HEADER_FILE = "#{GITHUB_REPO}.h"
HISTORY_FILE = 'HISTORY.markdown'
VERSION_FILE = Version.version_file('').basename.to_s
task :default => :info
desc 'Display instructions for public release'
task :info do
puts <<-EOF.gsub(/^\s{2}/, '')
Instructions for public release
- Update version, as appropriate:
$ rake version:bump # or
$ rake version:bump:minor # or
$ rake version:bump:major # or
edit 'VERSION' file directly
- Prepare release date, 'HISTORY.markdown' file, documentation:
$ rake prepare
- Review changes to 'HISTORY.markdown' file
This file is assembled using git commit messages; review for completeness.
- Review html documentation files
These files are assembled using source code Doxygen tags; review for
for completeness.
- Add & commit source files, tag, push to origin/master;
add & commit documentation files, push to origin/gh-pages:
$ rake release
EOF
end # task :info
desc 'Prepare HISTORY file for release'
task :prepare => 'prepare:default'
namespace :prepare do
task :default => [:release_date, :history, :documentation]
desc 'Prepare documentation'
task :documentation do
version = Version.current.to_s
# update parameters in Doxyfile
cwd = File.expand_path(File.dirname(__FILE__))
file = File.join(cwd, 'doc', 'Doxyfile')
contents = IO.read(file)
contents.sub!(/(^PROJECT_NUMBER\s*=)(.*)$/) do |match|
"#{$1} v#{version}"
end # contents.sub!(...)
IO.write(file, contents)
# chdir to doc/ and call doxygen to update documentation
Dir.chdir(to = File.join(cwd, 'doc'))
system('doxygen', 'Doxyfile')
# chdir to doc/latex and call doxygen to update documentation
Dir.chdir(from = File.join(cwd, 'doc', 'latex'))
system('make')
# move/rename file to 'doc/GITHUB_REPO reference-x.y.pdf'
FileUtils.mv(File.join(from, 'refman.pdf'),
File.join(to, "#{GITHUB_REPO} reference-#{version}.pdf"))
end # task :documentation
desc 'Prepare release history'
task :history, :tag do |t, args|
cwd = File.expand_path(File.dirname(__FILE__))
g = Git.open(cwd)
current_tag = args[:tag] || Version.current.to_s
prior_tag = g.tags.last
history = "## [v#{current_tag} (#{Time.now.strftime('%Y-%m-%d')})]"
history << "(/#{GITHUB_USERNAME}/#{GITHUB_REPO}/tree/v#{current_tag})\n"
commits = prior_tag ? g.log.between(prior_tag) : g.log
history << commits.map do |commit|
"- #{commit.message}"
end.join("\n")
history << "\n\n---\n"
file = File.join(cwd, HISTORY_FILE)
puts "Updating file #{file}:"
puts history
contents = IO.read(file)
IO.write(file, history << contents)
end # task :history
desc 'Update release date in header file'
task :release_date do
cwd = File.expand_path(File.dirname(__FILE__))
file = File.join(cwd, HEADER_FILE)
contents = IO.read(file)
contents.sub!(/(\\date\s*)(.*)$/) do |match|
"#{$1}#{Time.now.strftime('%-d %b %Y')}"
end # contents.sub!(...)
IO.write(file, contents)
end # task :release_date
end # namespace :prepare
desc 'Release source & documentation'
task :release => 'release:default'
namespace :release do
task :default => [:source, :documentation]
desc 'Commit documentation changes related to version bump'
task :documentation do
version = Version.current.to_s
cwd = File.expand_path(File.join(File.dirname(__FILE__), 'doc', 'html'))
g = Git.open(cwd)
# `git add .`
g.add
# remove each deleted item
g.status.deleted.each do |item|
g.remove(item[0])
end # g.status.deleted.each
# commit changes if items added, changed, or deleted
if g.status.added.size > 0 || g.status.changed.size > 0 ||
g.status.deleted.size > 0 then
message = "Update documentation for v#{version}"
puts g.commit(message)
else
puts "No changes to commit v#{version}"
end # if g.status.added.size > 0 || g.status.changed.size > 0...
g.push('origin', 'gh-pages')
end # task :documentation
desc 'Commit source changes related to version bump'
task :source do
version = Version.current.to_s
`git add #{HEADER_FILE} #{HISTORY_FILE} #{VERSION_FILE}`
`git commit -m 'Version bump to v#{version}'`
`git tag -a -f -m 'Version v#{version}' v#{version}`
`git push origin master`
`git push --tags`
end # task :source
end # namespace :release