From 20aba6629de49b4cf8c30119bc4e874c37c03d46 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 10 Oct 2025 15:10:32 +0900 Subject: [PATCH] Add a task to update versions (#47) --- Rakefile | 50 +++++++++++++++++++++++++++++++++++++++++++++++ helper.rb | 21 ++++++++++++++++++-- packages/Rakefile | 8 ++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 5c92b5e..94a8368 100644 --- a/Rakefile +++ b/Rakefile @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +require "date" + require_relative "helper" version = ENV["VERSION"] || Helper.detect_version @@ -26,3 +28,51 @@ end desc "Create #{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 diff --git a/helper.rb b/helper.rb index 20799d0..39b561e 100644 --- a/helper.rb +++ b/helper.rb @@ -14,8 +14,25 @@ module Helper module_function + def cmake_lists_txt + File.join(__dir__, "CMakeLists.txt") + end + def detect_version - cmakelists = File.join(__dir__, "CMakeLists.txt") - File.read(cmakelists)[/^project\(.+ VERSION (.+?)\)/, 1] + File.read(cmake_lists_txt)[/^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 diff --git a/packages/Rakefile b/packages/Rakefile index 072a71c..86b35b8 100644 --- a/packages/Rakefile +++ b/packages/Rakefile @@ -45,6 +45,14 @@ class OpenArmCANPackageTask < PackageTask false 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 file @archive_name do if File.exist?("../#{@archive_name}")