-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRakefile
More file actions
107 lines (81 loc) · 2.51 KB
/
Rakefile
File metadata and controls
107 lines (81 loc) · 2.51 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true
require "bundler/gem_tasks"
require "standard/rake"
require "fileutils"
desc "Run code formatting checks (StandardRB)"
task default: :standard
# Clean up old built gem files
desc "Clean up old built gem files"
task :clean do
rm_f Dir["leoandruby-*.gem"]
end
# Full release: bump version, commit, tag, push, build, release
desc "Full release: bump, commit, tag, push, build and release gem"
task :full_release, [:bump] => [:standard, :clean] do |t, args|
bump_type = args[:bump] || "patch" # default to patch bump
puts "🔧 Bumping #{bump_type} version..."
bump_version(bump_type)
version = current_version
puts "🔖 New version: #{version}"
puts "✅ Committing version bump..."
sh "git add lib/leoandruby/version.rb CHANGELOG.md"
sh "git commit -m 'Bump version to #{version}'"
puts "🏷️ Tagging release..."
sh "git tag v#{version}"
puts "📤 Pushing to GitHub..."
sh "git push"
sh "git push --tags"
puts "📦 Building gem..."
sh "gem build leoandruby.gemspec"
puts "🚀 Pushing gem to RubyGems..."
sh "gem push leoandruby-#{version}.gem"
puts "🎉 Release v#{version} complete!"
end
# Helpers
def current_version
File.read("lib/leoandruby/version.rb")[/VERSION\s*=\s*["'](.+)["']/, 1]
end
def bump_version(bump_type)
file = "lib/leoandruby/version.rb"
content = File.read(file)
major, minor, patch = current_version.split(".").map(&:to_i)
case bump_type
when "major"
major += 1
minor = 0
patch = 0
when "minor"
minor += 1
patch = 0
when "patch"
patch += 1
else
raise "Unknown bump type: #{bump_type}. Use major, minor, or patch."
end
new_version = "#{major}.#{minor}.#{patch}"
new_content = content.gsub(/VERSION\s*=\s*["'](.+)["']/, "VERSION = \"#{new_version}\"")
File.write(file, new_content)
# Also automatically update CHANGELOG.md
update_changelog(new_version)
end
def update_changelog(new_version)
changelog = "CHANGELOG.md"
timestamp = Time.now.strftime("%Y-%m-%d")
entry = <<~MARKDOWN
## [#{new_version}] - #{timestamp}
### Added
- _Describe new features here._
### Changed
- _Describe changes here._
### Fixed
- _Describe fixes here._
MARKDOWN
if File.exist?(changelog)
content = File.read(changelog)
updated_content = content.sub(/^# Changelog/, "# Changelog\n#{entry.strip}\n")
File.write(changelog, updated_content)
puts "📝 Updated CHANGELOG.md"
else
puts "⚠️ CHANGELOG.md not found. Skipping changelog update."
end
end