-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
134 lines (111 loc) · 3.57 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# frozen_string_literal: true
require 'English'
require 'rake/testtask'
require 'rake/packagetask'
require_relative 'lib/autosparkle/metadata'
############# Common #############
desc 'Build the gem'
task :build do
system 'gem build autosparkle.gemspec'
raise 'Gem build failed' unless $CHILD_STATUS.success?
end
############# CI #############
desc 'Check Ruby files for syntax errors'
task :syntax do
ruby_files = FileList['lib/**/*.rb', 'test/**/*.rb', '*.rb']
ruby_files.each do |file|
sh "ruby -c #{file}"
puts "\n"
end
end
desc 'Run tests'
task :test do
system 'bundle exec rspec'
raise 'Tests failed' unless $CHILD_STATUS.success?
end
desc 'Install the gem'
task install: :build do
gem_file = Dir['*.gem'].first
system "gem install #{gem_file}"
raise 'Gem install failed' unless $CHILD_STATUS.success?
end
############# CD #############
desc 'Bump the version'
task :bump_version do
method = ENV.fetch('METHOD', nil)
raise 'You must specify the method (major, minor, patch)' unless method
metadata_file_path = 'lib/autosparkle/metadata.rb'
metadata_content = File.read(metadata_file_path)
new_version = nil
new_metadata_content = metadata_content.gsub(/(VERSION = ')([^']+)(')/) do
prefix = Regexp.last_match(1)
current_version = Regexp.last_match(2)
suffix = Regexp.last_match(3)
major, minor, patch = current_version.split('.').map(&:to_i)
case method
when 'major'
major += 1
minor = 0
patch = 0
when 'minor'
minor += 1
patch = 0
when 'patch'
patch += 1
end
new_version = [major, minor, patch].join('.')
"#{prefix}#{new_version}#{suffix}"
end
File.write(metadata_file_path, new_metadata_content)
puts "Version updated to #{new_version}"
end
desc 'Push the new version to the repository'
task :push_version do
# Set the git configuration
system 'git config --global user.email "[email protected]"'
system 'git config --global user.name "Hadi Dbouk"'
# Push the changes to the develop branch
system 'git pull origin develop'
system 'git checkout develop'
system 'git add autosparkle.gemspec'
system "git commit -m 'Bump version to #{AutoSparkle::VERSION}'"
system 'git push origin develop'
# Retreive the last commit hash
commit_hash = `git rev-parse HEAD`.strip
# Push the changes to the main branch
system 'git checkout main'
system 'git pull origin main'
system "git cherry-pick #{commit_hash}"
system 'git push origin main'
rescue StandardError
raise e
end
desc 'Create a gem package'
Rake::PackageTask.new('autosparkle', Gem::Specification.load('autosparkle.gemspec').version) do |pkg|
pkg.need_tar = true
pkg.need_zip = true
pkg.package_dir = 'pkg'
pkg.package_files.include('lib/**/*')
pkg.package_files.include('bin/**/*')
end
desc 'Publish a new gem version'
task :publish_gem do
ruby_gem_api_key = ENV.fetch('GEM_HOST_API_KEY', nil)
raise 'You must provide the GEM_HOST_API_KEY secret' unless ruby_gem_api_key
system "gem push autosparkle-*.gem --key #{ruby_gem_api_key}"
raise 'gem push failed' unless $CHILD_STATUS.success?
end
desc 'Release the package on GitHub and create a tag'
task :release_package do
# Get the current version from the gemspec file
current_version = Gem::Specification.load('autosparkle.gemspec').version.to_s
begin
# Create a git tag
system "git tag v#{current_version}"
system 'git push origin --tags'
# Create a GitHub release
system "gh release create v#{current_version} -t 'Release #{current_version}' --notes-from-tag --verify-tag"
rescue StandardError
raise e
end
end