Skip to content

Commit

Permalink
Add Rake tasks for version bumping and gem publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalejandroaguilar committed Nov 26, 2024
1 parent f35d632 commit f88d3f5
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
81 changes: 81 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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"
]
1 change: 1 addition & 0 deletions lib/phlexy_ui.rb
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
7 changes: 7 additions & 0 deletions lib/phlexy_ui/updated_at.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion phlexy_ui.gemspec
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

0 comments on commit f88d3f5

Please sign in to comment.