From f88d3f5f13925b9e29adb0ad3e8b57f6e6806deb Mon Sep 17 00:00:00 2001 From: David Alejandro <15317732+davidalejandroaguilar@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:47:59 +0100 Subject: [PATCH] Add Rake tasks for version bumping and gem publishing --- Gemfile.lock | 2 + Rakefile | 81 +++++++++++++++++++++++++++++++++++++ lib/phlexy_ui.rb | 1 + lib/phlexy_ui/updated_at.rb | 7 ++++ phlexy_ui.gemspec | 5 ++- 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 Rakefile create mode 100644 lib/phlexy_ui/updated_at.rb diff --git a/Gemfile.lock b/Gemfile.lock index f74400e..c00a93c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,7 @@ GEM stringio racc (1.8.1) rainbow (3.1.1) + rake (13.2.1) rdoc (6.7.0) psych (>= 4.0.0) regexp_parser (2.9.2) @@ -90,6 +91,7 @@ PLATFORMS DEPENDENCIES debug (~> 1.9, >= 1.9.2) phlexy_ui! + rake (~> 13.0) rspec (~> 3.13.0) standard (~> 1.39.2) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..a31af7d --- /dev/null +++ b/Rakefile @@ -0,0 +1,81 @@ +require "bundler/gem_tasks" +require "time" + +namespace :release do + desc "Bump version (specify VERSION=x.x.x)" + task :bump_version do + new_version = ENV["VERSION"] + raise "Please specify VERSION=x.x.x" unless new_version + + # Update version.rb + version_file = "lib/phlexy_ui/version.rb" + content = File.read(version_file) + content.gsub!(/VERSION = "[^"]+"/, %(VERSION = "#{new_version}")) + File.write(version_file, content) + + puts "Bumped version to #{new_version}" + end + + desc "Update the UPDATED_AT timestamp" + task :update_timestamp do + timestamp = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S UTC") + file_path = "lib/phlexy_ui/updated_at.rb" + + content = <<~RUBY + # frozen_string_literal: true + + module PhlexyUI + # This timestamp is automatically updated when releasing a new version + # Format: YYYY-MM-DD HH:MM:SS UTC + UPDATED_AT = "#{timestamp}".freeze + end + RUBY + + File.write(file_path, content) + puts "Updated timestamp to #{timestamp}" + end + + desc "Build, tag, and push gem without creating GitHub release" + task publish: [:bump_version, :update_timestamp] do + # Read version directly from the file + version_content = File.read("lib/phlexy_ui/version.rb") + version = version_content.match(/VERSION = "([^"]+)"/)[1] + tag = "v#{version}" + + # Build the gem first + sh "gem build phlexy_ui.gemspec" + + # Update Gemfile.lock + sh "bundle install" + + # Single commit for all changes + sh "git add lib/phlexy_ui/version.rb lib/phlexy_ui/updated_at.rb Gemfile.lock" + sh %(git commit -m "Release version #{version}") + + # Create and push git tag + sh "git tag -s #{tag} -m 'Version #{version}'" + sh "git push origin main" # Push the commits + sh "git push origin #{tag}" # Push the tag + + # Prompt for OTP + print "Enter your RubyGems OTP code: " + otp = $stdin.gets.chomp + + # Push to RubyGems with OTP + sh "gem push phlexy_ui-#{version}.gem --otp #{otp}" + + # Clean up the generated gem file + sh "rm phlexy_ui-#{version}.gem" + + puts "Successfully:" + puts "- Released version #{version}" + puts "- Built and pushed gem" + puts "- Created and pushed tag #{tag}" + puts "- Cleaned up generated gem file" + end +end + +Rake::Task["release"].enhance [ + "release:update_timestamp", + "release:ensure_committed" +] diff --git a/lib/phlexy_ui.rb b/lib/phlexy_ui.rb index 0507803..fc1f804 100644 --- a/lib/phlexy_ui.rb +++ b/lib/phlexy_ui.rb @@ -1,6 +1,7 @@ require "phlex" require "zeitwerk" require_relative "phlexy_ui/version" +require_relative "phlexy_ui/updated_at" loader = Zeitwerk::Loader.for_gem loader.inflector.inflect( diff --git a/lib/phlexy_ui/updated_at.rb b/lib/phlexy_ui/updated_at.rb new file mode 100644 index 0000000..2633a3a --- /dev/null +++ b/lib/phlexy_ui/updated_at.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module PhlexyUI + # This timestamp is automatically updated when releasing a new version + # Format: YYYY-MM-DD HH:MM:SS UTC + UPDATED_AT = "2024-11-26 12:47:27 UTC" +end diff --git a/phlexy_ui.gemspec b/phlexy_ui.gemspec index a7f5a3d..bcdd9b8 100644 --- a/phlexy_ui.gemspec +++ b/phlexy_ui.gemspec @@ -1,6 +1,8 @@ +require_relative "lib/phlexy_ui/version" + Gem::Specification.new do |s| s.name = "phlexy_ui" - s.version = "0.1.20" + s.version = PhlexyUI::VERSION s.licenses = ["MIT"] s.summary = "PhlexyUI is a Ruby UI component library for DaisyUI using Phlex" s.description = "PhlexyUI is a Ruby UI component library for DaisyUI using Phlex" @@ -18,4 +20,5 @@ Gem::Specification.new do |s| s.add_development_dependency "standard", "~> 1.39.2" s.add_development_dependency "rspec", "~> 3.13.0" s.add_development_dependency "debug", "~> 1.9", ">= 1.9.2" + s.add_development_dependency "rake", "~> 13.0" end