-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rakefile
81 lines (64 loc) · 2.29 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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}"
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"
]