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