From bc19de5c162ff4906bfe55a082f33d3ef1d96614 Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 10:18:14 +0900 Subject: [PATCH 01/11] release blog: generate release post MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GitHub: GH-83 In this PR, we implement a Rake task for generating release announces in blog without contents. At the following PRs, we will implement contents step by step. Generate release announces ```console $ VERSION=14.1.1 rake release:blog:generate $ tree . | grep 2024-12-04-groonga-14.1.1.md │   └── 2024-12-04-groonga-14.1.1.md │   │  └── 2024-12-04-groonga-14.1.1.md ``` --- Rakefile | 8 +++++++- release_task.rb | 24 ++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 841fcd3c52..ed3aabaaec 100644 --- a/Rakefile +++ b/Rakefile @@ -17,5 +17,11 @@ require_relative "release_task" -release_task = ReleaseTask.new("groonga") +def env_var(name, default=nil) + value = ENV[name] || default + raise "${#{name}} is missing" if value.nil? + value +end + +release_task = ReleaseTask.new("groonga", env_var("VERSION"), __dir__) release_task.define diff --git a/release_task.rb b/release_task.rb index dafb947d8e..ad2caacafa 100644 --- a/release_task.rb +++ b/release_task.rb @@ -18,8 +18,10 @@ class ReleaseTask include Rake::DSL - def initialize(package) + def initialize(package, version, jekyll_path) @package = package + @version = version + @jekyll_path = jekyll_path end def define @@ -33,9 +35,27 @@ def define_generate_blog_task namespace :blog do desc "Generate release announce posts from a release note" task :generate do - puts "TODO: Generate release announce posts for #{@package}" + generate_blog_posts end end end end + + def post_filename + "#{Time.now.strftime("%F")}-#{@package}-#{@version}.md" + end + + def post_content(locale) + # TODO: We will write blog post contents here. + # After writing contents, we will remove this TODO comment. + "#{locale}, #{@package}, #{@version}" + end + + def generate_blog_posts + ["ja", "en"].each do |locale| + File.open("#{@jekyll_path}/#{locale}/_posts/#{post_filename}", "w") do |post| + post.write(post_content(locale)) + end + end + end end From a461020b976b5cd5ea434851dcf5f8e88f6c49fa Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 11:38:32 +0900 Subject: [PATCH 02/11] Get Groonga version from _config.yml Because the version is updated when we generate the release posts. --- Rakefile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index ed3aabaaec..644a470c0e 100644 --- a/Rakefile +++ b/Rakefile @@ -17,11 +17,9 @@ require_relative "release_task" -def env_var(name, default=nil) - value = ENV[name] || default - raise "${#{name}} is missing" if value.nil? - value +def version + File.read(File.join(__dir__, "_config.yml"))[/^groonga_version: (.+)$/, 1] end -release_task = ReleaseTask.new("groonga", env_var("VERSION"), __dir__) +release_task = ReleaseTask.new("groonga", version, __dir__) release_task.define From 25ca18c5965e22e530f13154ab9b3b427ac800aa Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 12:28:22 +0900 Subject: [PATCH 03/11] Pass Groonga name without being downcase --- Rakefile | 2 +- release_task.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 644a470c0e..43937cc3fe 100644 --- a/Rakefile +++ b/Rakefile @@ -21,5 +21,5 @@ def version File.read(File.join(__dir__, "_config.yml"))[/^groonga_version: (.+)$/, 1] end -release_task = ReleaseTask.new("groonga", version, __dir__) +release_task = ReleaseTask.new("Groonga", version, __dir__) release_task.define diff --git a/release_task.rb b/release_task.rb index ad2caacafa..a74a48eb6d 100644 --- a/release_task.rb +++ b/release_task.rb @@ -42,7 +42,7 @@ def define_generate_blog_task end def post_filename - "#{Time.now.strftime("%F")}-#{@package}-#{@version}.md" + "#{Time.now.strftime("%F")}-#{@package.downcase}-#{@version}.md" end def post_content(locale) From 653601437cfb9c4f0ddd7d14a478d16666a0f4c6 Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 14:42:56 +0900 Subject: [PATCH 04/11] refer to the Groonga version in _config.yml --- Rakefile | 8 +++----- release_task.rb | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 43937cc3fe..5d9a03cf8d 100644 --- a/Rakefile +++ b/Rakefile @@ -15,11 +15,9 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +require "yaml" +require "date" require_relative "release_task" -def version - File.read(File.join(__dir__, "_config.yml"))[/^groonga_version: (.+)$/, 1] -end - -release_task = ReleaseTask.new("Groonga", version, __dir__) +release_task = ReleaseTask.new("Groonga", __dir__) release_task.define diff --git a/release_task.rb b/release_task.rb index a74a48eb6d..77cdfbbddf 100644 --- a/release_task.rb +++ b/release_task.rb @@ -15,12 +15,15 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +require "yaml" +require "date" + class ReleaseTask include Rake::DSL - def initialize(package, version, jekyll_path) + def initialize(package, jekyll_path) @package = package - @version = version + @version = detect_version @jekyll_path = jekyll_path end @@ -30,6 +33,14 @@ def define private + def jekyll_config + YAML.safe_load_file("_config.yml", permitted_classes: [Date]) + end + + def detect_version + jekyll_config["#{@package.downcase}_version"] + end + def define_generate_blog_task namespace :release do namespace :blog do From 170fbfcf884e72bb87595073639bab96ecf5f345 Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 15:04:22 +0900 Subject: [PATCH 05/11] refer to the release date in _config.yml --- release_task.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/release_task.rb b/release_task.rb index 77cdfbbddf..b14a6c3aad 100644 --- a/release_task.rb +++ b/release_task.rb @@ -23,8 +23,9 @@ class ReleaseTask def initialize(package, jekyll_path) @package = package - @version = detect_version @jekyll_path = jekyll_path + @version = detect_version + @release_date = detect_release_date end def define @@ -41,6 +42,10 @@ def detect_version jekyll_config["#{@package.downcase}_version"] end + def detect_release_date + jekyll_config["#{@package.downcase}_release_date"] + end + def define_generate_blog_task namespace :release do namespace :blog do @@ -53,7 +58,7 @@ def define_generate_blog_task end def post_filename - "#{Time.now.strftime("%F")}-#{@package.downcase}-#{@version}.md" + "#{@release_date.strftime("%F")}-#{@package.downcase}-#{@version}.md" end def post_content(locale) From 2c295008bfa0f0a29a4795ce658e04a3e9c1431a Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 15:08:03 +0900 Subject: [PATCH 06/11] Remove unnecessary requires --- Rakefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Rakefile b/Rakefile index 5d9a03cf8d..b02e134a24 100644 --- a/Rakefile +++ b/Rakefile @@ -15,8 +15,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -require "yaml" -require "date" require_relative "release_task" release_task = ReleaseTask.new("Groonga", __dir__) From 830f70ead9aad430605805735f488dfffd1b7879 Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 16:20:48 +0900 Subject: [PATCH 07/11] Load _config.yml once for efficiency --- release_task.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/release_task.rb b/release_task.rb index b14a6c3aad..a92c1d9da7 100644 --- a/release_task.rb +++ b/release_task.rb @@ -24,6 +24,7 @@ class ReleaseTask def initialize(package, jekyll_path) @package = package @jekyll_path = jekyll_path + @jekyll_config = load_jekyll_config @version = detect_version @release_date = detect_release_date end @@ -34,16 +35,16 @@ def define private - def jekyll_config + def load_jekyll_config YAML.safe_load_file("_config.yml", permitted_classes: [Date]) end def detect_version - jekyll_config["#{@package.downcase}_version"] + @jekyll_config["#{@package.downcase}_version"] end def detect_release_date - jekyll_config["#{@package.downcase}_release_date"] + @jekyll_config["#{@package.downcase}_release_date"] end def define_generate_blog_task From e86ac2585455d632f4db91f0dbb519b1da3ebb49 Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 16:22:27 +0900 Subject: [PATCH 08/11] Make sure the configuration path --- release_task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_task.rb b/release_task.rb index a92c1d9da7..141a859a11 100644 --- a/release_task.rb +++ b/release_task.rb @@ -36,7 +36,7 @@ def define private def load_jekyll_config - YAML.safe_load_file("_config.yml", permitted_classes: [Date]) + YAML.safe_load_file(File.join(@jekyll_path, "_config.yml"), permitted_classes: [Date]) end def detect_version From a2662b0195332324b2f3deaee23c80ea56a2bc09 Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 16:23:09 +0900 Subject: [PATCH 09/11] Sort required libraries --- release_task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_task.rb b/release_task.rb index 141a859a11..845dce2aa1 100644 --- a/release_task.rb +++ b/release_task.rb @@ -15,8 +15,8 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -require "yaml" require "date" +require "yaml" class ReleaseTask include Rake::DSL From 26072b29c1f767ccfaa2e07d052d0a0c589e8740 Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 16:28:01 +0900 Subject: [PATCH 10/11] Clarify the meaning of the `Groonga.downcase` variable --- release_task.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/release_task.rb b/release_task.rb index 845dce2aa1..c5cd8148bb 100644 --- a/release_task.rb +++ b/release_task.rb @@ -21,8 +21,8 @@ class ReleaseTask include Rake::DSL - def initialize(package, jekyll_path) - @package = package + def initialize(product, jekyll_path) + @product = product @jekyll_path = jekyll_path @jekyll_config = load_jekyll_config @version = detect_version @@ -35,16 +35,20 @@ def define private + def product_id + @product.downcase + end + def load_jekyll_config YAML.safe_load_file(File.join(@jekyll_path, "_config.yml"), permitted_classes: [Date]) end def detect_version - @jekyll_config["#{@package.downcase}_version"] + @jekyll_config["#{product_id}_version"] end def detect_release_date - @jekyll_config["#{@package.downcase}_release_date"] + @jekyll_config["#{product_id}_release_date"] end def define_generate_blog_task @@ -59,13 +63,13 @@ def define_generate_blog_task end def post_filename - "#{@release_date.strftime("%F")}-#{@package.downcase}-#{@version}.md" + "#{@release_date.strftime("%F")}-#{product_id}-#{@version}.md" end def post_content(locale) # TODO: We will write blog post contents here. # After writing contents, we will remove this TODO comment. - "#{locale}, #{@package}, #{@version}" + "#{locale}, #{@product}, #{@version}" end def generate_blog_posts From 624c7e556c3e03d5e6f2445ca2a48fe882b201a0 Mon Sep 17 00:00:00 2001 From: otegami Date: Wed, 4 Dec 2024 16:57:17 +0900 Subject: [PATCH 11/11] Remove #product_id for consistency We pre-calculate the variables for generating release blog posts. --- release_task.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/release_task.rb b/release_task.rb index c5cd8148bb..f015cbb647 100644 --- a/release_task.rb +++ b/release_task.rb @@ -23,6 +23,7 @@ class ReleaseTask def initialize(product, jekyll_path) @product = product + @product_id = product.downcase @jekyll_path = jekyll_path @jekyll_config = load_jekyll_config @version = detect_version @@ -35,20 +36,16 @@ def define private - def product_id - @product.downcase - end - def load_jekyll_config YAML.safe_load_file(File.join(@jekyll_path, "_config.yml"), permitted_classes: [Date]) end def detect_version - @jekyll_config["#{product_id}_version"] + @jekyll_config["#{@product_id}_version"] end def detect_release_date - @jekyll_config["#{product_id}_release_date"] + @jekyll_config["#{@product_id}_release_date"] end def define_generate_blog_task @@ -63,7 +60,7 @@ def define_generate_blog_task end def post_filename - "#{@release_date.strftime("%F")}-#{product_id}-#{@version}.md" + "#{@release_date.strftime("%F")}-#{@product_id}-#{@version}.md" end def post_content(locale)