能源管控程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Rakefile 6.2 KiB

2 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # encoding: utf-8
  2. #
  3. # Copyright:: 2009-2016 Doc Walker
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. require 'git'
  18. require 'github_changelog_generator/task'
  19. require 'rake'
  20. require 'rubygems'
  21. require 'rake/version_task' # gem install version
  22. require 'version'
  23. # requires additional packages on MacOS (including Homebrew):
  24. # $ /usr/bin/ruby -e "$(curl -fsSL \
  25. # https://raw.githubusercontent.com/Homebrew/install/master/install)"
  26. # $ brew install doxygen # generates documentation from source code
  27. # $ brew cask install mactex # MacTeX
  28. Rake::VersionTask.new do |task|
  29. # prevent auto-commit on version bump
  30. task.with_git = false
  31. end
  32. # adjust as appropriate
  33. CWD = File.expand_path(File.dirname(__FILE__))
  34. DOXYFILE = 'Doxyfile'
  35. GITHUB_USERNAME = '4-20ma'
  36. GITHUB_REPO = 'ModbusMaster'
  37. HEADER_FILE = "#{GITHUB_REPO}.h"
  38. CHANGELOG_FILE = 'CHANGELOG.md'
  39. PROPERTIES_FILE = 'library.properties'
  40. VERSION_FILE = Version.version_file('').basename.to_s
  41. task :default => :info
  42. desc 'Display instructions for public release'
  43. task :info do
  44. puts <<-EOF.gsub(/^\s{2}/, '')
  45. Instructions for public release
  46. - Update version, as appropriate:
  47. $ rake version:bump # or
  48. $ rake version:bump:minor # or
  49. $ rake version:bump:major # or
  50. edit 'VERSION' file directly
  51. - Prepare release date, 'CHANGELOG.md' file, documentation:
  52. $ rake prepare
  53. - Review changes to 'CHANGELOG.md' file
  54. This file is assembled using git commit messages; review for completeness.
  55. - Review html documentation files
  56. These files are assembled using source code Doxygen tags; review for
  57. for completeness.
  58. - Add & commit source files, tag, push to origin/master;
  59. add & commit documentation files, push to origin/gh-pages:
  60. $ rake release
  61. EOF
  62. end # task :info
  63. desc "Prepare #{CHANGELOG_FILE} for release"
  64. task :prepare => 'prepare:default'
  65. namespace :prepare do
  66. task :default => [
  67. :release_date,
  68. :library_properties,
  69. :changelog,
  70. :documentation
  71. ]
  72. desc 'Prepare documentation'
  73. task :documentation do
  74. version = Version.current.to_s
  75. # update parameters in Doxyfile
  76. file = File.join(CWD, 'doc', DOXYFILE)
  77. contents = IO.read(file)
  78. contents.sub!(/(^PROJECT_NUMBER\s*=)(.*)$/) do |match|
  79. "#{$1} v#{version}"
  80. end # contents.sub!(...)
  81. IO.write(file, contents)
  82. # chdir to doc/ and call doxygen to update documentation
  83. Dir.chdir(to = File.join(CWD, 'doc'))
  84. system('doxygen', DOXYFILE)
  85. # chdir to doc/latex and call doxygen to update documentation
  86. Dir.chdir(from = File.join(CWD, 'doc', 'latex'))
  87. system('make')
  88. # move/rename file to 'extras/GITHUB_REPO reference-x.y.pdf'
  89. to = File.join(CWD, 'extras')
  90. FileUtils.mv(File.join(from, 'refman.pdf'),
  91. File.join(to, "#{GITHUB_REPO} reference-#{version}.pdf"))
  92. end # task :documentation
  93. desc 'Prepare release history'
  94. GitHubChangelogGenerator::RakeTask.new(:changelog) do |config|
  95. config.add_issues_wo_labels = false
  96. config.add_pr_wo_labels = false
  97. config.enhancement_labels = [
  98. 'Type: Enhancement'
  99. ]
  100. config.bug_labels = ['Type: Bug']
  101. config.exclude_labels = ['Type: Question']
  102. config.header = '# ModbusMaster CHANGELOG'
  103. config.include_labels = [
  104. 'Type: Bug',
  105. 'Type: Enhancement',
  106. 'Type: Feature Request',
  107. 'Type: Maintenance'
  108. ]
  109. # config.since_tag = '0.1.0'
  110. config.future_release = "v#{Version.current.to_s}"
  111. config.user = GITHUB_USERNAME
  112. config.project = GITHUB_REPO
  113. end # GitHubChangelogGenerator::RakeTask.new
  114. desc 'Update version in library properties file'
  115. task :library_properties do
  116. version = Version.current.to_s
  117. file = File.join(CWD, PROPERTIES_FILE)
  118. contents = IO.read(file)
  119. contents.sub!(/(version=\s*)(.*)$/) do |match|
  120. "#{$1}#{version}"
  121. end # contents.sub!(...)
  122. IO.write(file, contents)
  123. end # task :library_properties
  124. desc 'Update release date in header file'
  125. task :release_date do
  126. file = File.join(CWD, 'src', HEADER_FILE)
  127. contents = IO.read(file)
  128. contents.sub!(/(\\date\s*)(.*)$/) do |match|
  129. "#{$1}#{Time.now.strftime('%-d %b %Y')}"
  130. end # contents.sub!(...)
  131. IO.write(file, contents)
  132. end # task :release_date
  133. end # namespace :prepare
  134. desc 'Release source & documentation'
  135. task :release => 'release:default'
  136. namespace :release do
  137. task :default => [:source, :documentation]
  138. desc 'Commit documentation changes related to version bump'
  139. task :documentation do
  140. version = Version.current.to_s
  141. cwd = File.expand_path(File.join(File.dirname(__FILE__), 'doc', 'html'))
  142. g = Git.open(cwd)
  143. # `git add .`
  144. g.add
  145. # remove each deleted item
  146. g.status.deleted.each do |item|
  147. g.remove(item[0])
  148. end # g.status.deleted.each
  149. # commit changes if items added, changed, or deleted
  150. if g.status.added.size > 0 || g.status.changed.size > 0 ||
  151. g.status.deleted.size > 0 then
  152. message = "Update documentation for v#{version}"
  153. puts g.commit(message)
  154. else
  155. puts "No changes to commit v#{version}"
  156. end # if g.status.added.size > 0 || g.status.changed.size > 0...
  157. g.push('origin', 'gh-pages')
  158. end # task :documentation
  159. desc 'Commit source changes related to version bump'
  160. task :source do
  161. version = Version.current.to_s
  162. `git add \
  163. doc/#{DOXYFILE} \
  164. "extras/#{GITHUB_REPO} reference-#{version}.pdf" \
  165. src/#{HEADER_FILE} \
  166. #{CHANGELOG_FILE} \
  167. #{PROPERTIES_FILE} \
  168. #{VERSION_FILE} \
  169. `
  170. `git commit -m 'Version bump to v#{version}'`
  171. `git tag -a -f -m 'Version v#{version}' v#{version}`
  172. `git push origin master`
  173. `git push --tags`
  174. end # task :source
  175. end # namespace :release