forked from settingslogic/settingslogic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
332 lines (273 loc) · 9.54 KB
/
Rakefile
File metadata and controls
332 lines (273 loc) · 9.54 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# frozen_string_literal: true
require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
desc 'Run RuboCop with autocorrect'
task :rubocop_autocorrect do
sh 'bundle exec rubocop -a'
end
rescue LoadError
desc 'Run RuboCop'
task :rubocop do
puts 'RuboCop not available. Install it with: gem install rubocop'
end
desc 'Run RuboCop with autocorrect'
task :rubocop_autocorrect do
puts 'RuboCop not available. Install it with: gem install rubocop'
end
end
# Security audit task
desc 'Run security audit on dependencies'
task :audit do
require 'bundler/audit/cli'
Bundler::Audit::CLI.start(['check', '--update'])
rescue LoadError
puts 'bundler-audit not available. Install it with: gem install bundler-audit'
puts 'Run: gem install bundler-audit'
end
desc 'Run all checks (specs, rubocop, audit)'
task check: [:spec, :rubocop, :audit]
# Console for testing
desc 'Open IRB console with settingslogic loaded'
task :console do
require 'irb'
require_relative 'lib/settingslogic'
ARGV.clear
IRB.start
end
# Default task
task default: [:spec]
# Version management helpers
require 'fileutils'
def version_file
'lib/settingslogic/version.rb'
end
def current_version
require_relative version_file
Settingslogic::VERSION
end
def update_version(new_version)
content = File.read(version_file)
content.gsub!(/VERSION = ["'][\d.]+["']/, "VERSION = '#{new_version}'")
File.write(version_file, content)
puts "Updated version to #{new_version}"
# Update Gemfile.lock to match new version
puts 'Updating Gemfile.lock...'
system('bundle install')
end
def update_changelog(version, type)
changelog = 'CHANGELOG.md'
# Check if git-cliff is available
has_git_cliff = system('which git-cliff > /dev/null 2>&1')
if has_git_cliff
# Use git-cliff to generate changelog
puts 'Generating changelog with git-cliff...'
system("git-cliff --tag v#{version} --output #{changelog}")
puts "✅ Generated CHANGELOG.md with git-cliff for version #{version}"
else
# Fallback to manual changelog update
date = Time.now.strftime('%Y-%m-%d')
# Read existing changelog
content = File.read(changelog)
# Prepare new entry based on type
new_entry = case type
when :patch
"## [#{version}] - #{date}\n\n### Fixed\n- Bug fixes and minor improvements\n\n"
when :minor
"## [#{version}] - #{date}\n\n### Added\n- New features\n\n### Changed\n- Improvements\n\n"
when :major
"## [#{version}] - #{date}\n\n### Breaking Changes\n- Breaking changes\n\n" \
"### Added\n- New features\n\n"
else
"## [#{version}] - #{date}\n\n### Changed\n- Updates\n\n"
end
# Insert after the header
content.sub!(/^(# Changelog.*?\n\n)/m, "\\1#{new_entry}")
File.write(changelog, content)
puts "✅ Updated CHANGELOG.md manually for version #{version}"
puts '💡 Install git-cliff for automatic changelog generation: brew install git-cliff'
end
end
def git_status_clean?
`git status --porcelain`.empty?
end
def on_main_branch?
`git rev-parse --abbrev-ref HEAD`.strip == 'main'
end
# Changelog task
desc 'Generate CHANGELOG.md using git-cliff'
task :changelog do
if system('which git-cliff > /dev/null 2>&1')
puts 'Generating CHANGELOG.md with git-cliff...'
system('git-cliff --output CHANGELOG.md')
puts '✅ CHANGELOG.md generated successfully'
else
puts '❌ git-cliff not installed. Install with: brew install git-cliff'
exit 1
end
end
# Version tasks
namespace :version do
desc 'Show current version'
task :show do
puts "Current version: #{current_version}"
end
desc 'Bump patch version (e.g., 3.0.0 -> 3.0.1)'
task :patch do
parts = current_version.split('.')
new_version = "#{parts[0]}.#{parts[1]}.#{parts[2].to_i + 1}"
update_version(new_version)
update_changelog(new_version, :patch)
end
desc 'Bump minor version (e.g., 3.0.0 -> 3.1.0)'
task :minor do
parts = current_version.split('.')
new_version = "#{parts[0]}.#{parts[1].to_i + 1}.0"
update_version(new_version)
update_changelog(new_version, :minor)
end
desc 'Bump major version (e.g., 3.0.0 -> 4.0.0)'
task :major do
parts = current_version.split('.')
new_version = "#{parts[0].to_i + 1}.0.0"
update_version(new_version)
update_changelog(new_version, :major)
end
end
# Release tasks
namespace :release do
desc 'Prepare patch release'
task patch: ['version:patch', :rubocop_autocorrect, :check] do
prepare_release_commit
end
desc 'Prepare minor release'
task minor: ['version:minor', :rubocop_autocorrect, :check] do
prepare_release_commit
end
desc 'Prepare major release'
task major: ['version:major', :rubocop_autocorrect, :check] do
prepare_release_commit
end
desc 'Create and push release tag'
task :tag do
abort 'ERROR: Must be on main branch to create a release tag' unless on_main_branch?
abort 'ERROR: Working directory not clean. Commit changes first.' unless git_status_clean?
# Reload version from file to avoid caching issues
version_content = File.read(version_file)
version = version_content.match(/VERSION = ['"](.+)['"]/)[1]
tag = "v#{version}"
puts "\n📦 Creating release tag #{tag}..."
# Create annotated tag
sh "git tag -a #{tag} -m 'Release version #{version}'"
puts "\n📤 Pushing tag to origin..."
sh "git push origin #{tag}"
puts "\n✅ Release tag #{tag} created and pushed!"
puts "\n🚀 GitHub Actions will now:"
puts ' 1. Run all tests'
puts ' 2. Create GitHub Release'
puts ' 3. Publish gem to RubyGems'
puts "\nMonitor progress at: https://github.com/mitre/settingslogic/actions"
end
end
def prepare_release_commit
version = current_version
# Check git status
puts 'WARNING: Not on main branch' unless on_main_branch?
# Stage changes (including any RuboCop fixes)
sh "git add #{version_file} CHANGELOG.md Gemfile.lock"
sh 'git add -u' # Add any modified files (from RuboCop autocorrect)
# Show what will be committed
puts "\n📝 Changes to be committed:"
sh 'git diff --cached --stat'
puts "\n💡 To complete the release:"
puts ' 1. Review and update CHANGELOG.md if needed'
puts " 2. Commit: git commit -m 'Bump version to #{version}"
puts ''
puts " Authored by: Aaron Lippold<lippold@gmail.com>'"
puts ' 3. Push: git push origin main'
puts ' 4. Create tag: bundle exec rake release:tag'
end
# Quick release commands (combines everything)
desc 'Quick patch release (bump, test, commit, tag, push)'
task 'release:quick:patch' do
Rake::Task['release:patch'].invoke
if git_status_clean?
puts 'No changes to commit'
else
# Reload version from file to get the updated version
version_content = File.read(version_file)
version = version_content.match(/VERSION = ['"](.+)['"]/)[1]
sh %(git commit -m "Bump version to #{version}\n\nAuthored by: Aaron Lippold<lippold@gmail.com>")
sh 'git push origin main'
end
Rake::Task['release:tag'].invoke
end
desc 'Quick minor release (bump, test, commit, tag, push)'
task 'release:quick:minor' do
Rake::Task['release:minor'].invoke
if git_status_clean?
puts 'No changes to commit'
else
# Reload version from file to get the updated version
version_content = File.read(version_file)
version = version_content.match(/VERSION = ['"](.+)['"]/)[1]
sh %(git commit -m "Bump version to #{version}\n\nAuthored by: Aaron Lippold<lippold@gmail.com>")
sh 'git push origin main'
end
Rake::Task['release:tag'].invoke
end
desc 'Quick major release (bump, test, commit, tag, push)'
task 'release:quick:major' do
Rake::Task['release:major'].invoke
if git_status_clean?
puts 'No changes to commit'
else
# Reload version from file to get the updated version
version_content = File.read(version_file)
version = version_content.match(/VERSION = ['"](.+)['"]/)[1]
sh %(git commit -m "Bump version to #{version}\n\nAuthored by: Aaron Lippold<lippold@gmail.com>")
sh 'git push origin main'
end
Rake::Task['release:tag'].invoke
end
# Helpful info task
desc 'Show release process help'
task 'release:help' do
puts <<~HELP
SETTINGSLOGIC RELEASE PROCESS
==============================
Standard Release (interactive):
-------------------------------
1. bundle exec rake release:patch # or :minor, :major
2. Review CHANGELOG.md and make edits
3. git commit -m "Bump version to X.Y.Z
#{" "}
Authored by: Aaron Lippold<lippold@gmail.com>"
4. git push origin main
5. bundle exec rake release:tag
Quick Release (automated):
-------------------------
bundle exec rake release:quick:patch # Everything in one command
bundle exec rake release:quick:minor
bundle exec rake release:quick:major
Version Commands:
----------------
bundle exec rake version:show # Show current version
bundle exec rake version:patch # Bump patch version
bundle exec rake version:minor # Bump minor version#{" "}
bundle exec rake version:major # Bump major version
Other Commands:
--------------
bundle exec rake check # Run all tests/checks
bundle exec rake spec # Run tests only
bundle exec rake rubocop # Run linter only
bundle exec rake audit # Run security audit only
HELP
end
# Add help to default rake -T output
desc 'Show release help'
task help: 'release:help'