Add a task to update versions (#47)

This commit is contained in:
Sutou Kouhei 2025-10-10 15:10:32 +09:00 committed by GitHub
parent 744e5ff868
commit 20aba6629d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 77 additions and 2 deletions

View File

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
require "date"
require_relative "helper" require_relative "helper"
version = ENV["VERSION"] || Helper.detect_version version = ENV["VERSION"] || Helper.detect_version
@ -26,3 +28,51 @@ end
desc "Create #{archive_tar_gz}" desc "Create #{archive_tar_gz}"
task :dist => archive_tar_gz task :dist => archive_tar_gz
namespace :release do
namespace :version do
desc "Update versions for a new release"
task :update do
new_version = ENV["NEW_VERSION"]
if new_version.nil?
raise "You must specify NEW_VERSION=..."
end
new_release_date = ENV["NEW_RELEASE_DATE"] || Date.today.iso8601
Helper.update_cmake_lists_txt_version(new_version)
Helper.update_content("python/meson.build") do |content|
content.sub(/^( version: ').*?('.*)$/) do
"#{$1}#{new_version}#{$2}"
end
end
Helper.update_content("python/pyproject.toml") do |content|
content.sub(/^(version = ").*?(")$/) do
"#{$1}#{new_version}#{$2}"
end
end
Helper.update_content("python/openarm/can/__init__.py") do |content|
content.sub(/^(__version__ = ").*?(")$/) do
"#{$1}#{new_version}#{$2}"
end
end
ruby("-C",
"packages",
"-S",
"rake",
"version:update",
"RELEASE_DATE=#{new_release_date}")
sh("git",
"add",
"CMakeLists.txt",
"packages/debian/changelog",
"packages/fedora/openarm-can.spec",
"python/meson.build",
"python/pyproject.toml",
"python/openarm/can/__init__.py")
sh("git",
"commit",
"-m",
"Update version info to #{version} (#{new_release_date})")
sh("git", "push")
end
end
end

View File

@ -14,8 +14,25 @@
module Helper module Helper
module_function module_function
def cmake_lists_txt
File.join(__dir__, "CMakeLists.txt")
end
def detect_version def detect_version
cmakelists = File.join(__dir__, "CMakeLists.txt") File.read(cmake_lists_txt)[/^project\(.+ VERSION (.+?)\)/, 1]
File.read(cmakelists)[/^project\(.+ VERSION (.+?)\)/, 1] end
def update_content(path)
content = File.read(path)
content = yield(content)
File.write(path, content)
end
def update_cmake_lists_txt_version(new_version)
update_content(cmake_lists_txt) do |content|
content.sub(/^(project\(.* VERSION )(?:.*?)(\))/) do
"#{$1}#{new_version}#{$2}"
end
end
end end
end end

View File

@ -45,6 +45,14 @@ class OpenArmCANPackageTask < PackageTask
false false
end end
def update_spec
update_content("fedora/openarm-can.spec") do |content|
content.gsub!(/^(Version:\s+)[\d.]+$/) do
"#{$1}#{@version}"
end
end
end
def define_archive_task def define_archive_task
file @archive_name do file @archive_name do
if File.exist?("../#{@archive_name}") if File.exist?("../#{@archive_name}")