-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.rb
More file actions
executable file
·110 lines (84 loc) · 2.7 KB
/
release.rb
File metadata and controls
executable file
·110 lines (84 loc) · 2.7 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
108
109
110
#!/usr/bin/env ruby
require_relative 'lib/tapsilat/version'
require 'fileutils'
class ReleaseManager
VERSION_FILE = 'lib/tapsilat/version.rb'.freeze
GEMSPEC_FILE = 'tapsilat.gemspec'.freeze
def self.run(version_type = 'patch')
new.release(version_type)
end
def release(version_type)
puts '🚀 Starting release process...'
current_version = Tapsilat::VERSION
puts "📋 Current version: #{current_version}"
new_version = increment_version(current_version, version_type)
puts "📈 New version: #{new_version}"
update_version_file(new_version)
commit_changes(new_version)
build_and_push_gem
cleanup
puts '✅ Release completed successfully!'
puts "🎉 tapsilat #{new_version} is now live on RubyGems!"
end
private
def increment_version(version, type)
major, minor, patch = version.split('.').map(&:to_i)
case type.downcase
when 'major'
"#{major + 1}.0.0"
when 'minor'
"#{major}.#{minor + 1}.0"
when 'patch', 'p'
"#{major}.#{minor}.#{patch + 1}"
else
raise "Invalid version type: #{type}. Use 'major', 'minor', or 'patch'"
end
end
def update_version_file(new_version)
puts '📝 Updating version file...'
content = File.read(VERSION_FILE)
updated_content = content.gsub(/VERSION = '[^']*'/, "VERSION = '#{new_version}'")
File.write(VERSION_FILE, updated_content)
end
def commit_changes(new_version)
puts '📦 Committing changes...'
system("git add #{VERSION_FILE}")
system("git commit -m 'Bump version to #{new_version}'")
system("git tag v#{new_version}")
puts "🏷️ Tagged as v#{new_version}"
end
def build_and_push_gem
puts '🔨 Building gem...'
system("gem build #{GEMSPEC_FILE}")
gem_file = "tapsilat-#{current_version}.gem"
puts '🚀 Pushing to RubyGems...'
system("gem push #{gem_file}")
end
def cleanup
puts '🧹 Cleaning up...'
gem_file = "tapsilat-#{current_version}.gem"
FileUtils.rm_f(gem_file)
end
def current_version
# Read version directly from file to avoid constant redefinition warning
content = File.read(VERSION_FILE)
version_match = content.match(/VERSION = '([^']*)'/)
version_match[1] if version_match
end
end
# Script kullanımı
if __FILE__ == $PROGRAM_NAME
version_type = ARGV[0] || 'patch'
puts <<~USAGE
🎯 Tapsilat Gem Release Manager
Usage: ruby release.rb [version_type]
Version types:
- patch (default): 0.1.3 -> 0.1.4
- minor: 0.1.3 -> 0.2.0#{' '}
- major: 0.1.3 -> 1.0.0
Current command: ruby release.rb #{version_type}
USAGE
puts 'Press Enter to continue or Ctrl+C to cancel...'
$stdin.gets
ReleaseManager.run(version_type)
end