|
65 | 65 | desc "Run all tests for CI" |
66 | 66 | task ci: %w[rubocop spec:unit spec:integration spec:compliance] |
67 | 67 |
|
| 68 | +# Changelog management |
| 69 | +namespace :changelog do |
| 70 | + desc "Update changelog with current date for unreleased version" |
| 71 | + task :update_date do |
| 72 | + changelog_path = "CHANGELOG.md" |
| 73 | + current_date = Time.now.strftime("%Y-%m-%d") |
| 74 | + |
| 75 | + unless File.exist?(changelog_path) |
| 76 | + puts "CHANGELOG.md not found!" |
| 77 | + exit 1 |
| 78 | + end |
| 79 | + |
| 80 | + content = File.read(changelog_path) |
| 81 | + |
| 82 | + # Replace any unreleased or incorrect dates with current date |
| 83 | + # Pattern matches: ## [version] - YYYY-MM-DD or ## [version] - Unreleased |
| 84 | + updated_content = content.gsub(/^(## \[[^\]]+\]) - (?:\d{4}-\d{2}-\d{2}|Unreleased)$/) do |match| |
| 85 | + version_part = match.split(' - ').first |
| 86 | + "#{version_part} - #{current_date}" |
| 87 | + end |
| 88 | + |
| 89 | + if content != updated_content |
| 90 | + File.write(changelog_path, updated_content) |
| 91 | + puts "Updated CHANGELOG.md with current date: #{current_date}" |
| 92 | + else |
| 93 | + puts "No changelog dates needed updating" |
| 94 | + end |
| 95 | + end |
| 96 | + |
| 97 | + desc "Add new version entry to changelog" |
| 98 | + task :new_version, [:version] do |task, args| |
| 99 | + version = args[:version] || ENV['VERSION'] |
| 100 | + |
| 101 | + unless version |
| 102 | + puts "Please provide a version: rake changelog:new_version[1.0.1] or VERSION=1.0.1 rake changelog:new_version" |
| 103 | + exit 1 |
| 104 | + end |
| 105 | + |
| 106 | + changelog_path = "CHANGELOG.md" |
| 107 | + current_date = Time.now.strftime("%Y-%m-%d") |
| 108 | + |
| 109 | + unless File.exist?(changelog_path) |
| 110 | + puts "CHANGELOG.md not found!" |
| 111 | + exit 1 |
| 112 | + end |
| 113 | + |
| 114 | + content = File.read(changelog_path) |
| 115 | + |
| 116 | + # Find the first ## heading and insert new version before it |
| 117 | + new_entry = <<~ENTRY |
| 118 | + ## [#{version}] - #{current_date} |
| 119 | +
|
| 120 | + ### Added |
| 121 | + - |
| 122 | +
|
| 123 | + ### Changed |
| 124 | + - |
| 125 | +
|
| 126 | + ### Fixed |
| 127 | + - |
| 128 | +
|
| 129 | + ENTRY |
| 130 | + |
| 131 | + # Insert after the header but before the first version entry |
| 132 | + updated_content = content.sub(/^(# Changelog.*?\n\n)/m, "\\1#{new_entry}") |
| 133 | + |
| 134 | + File.write(changelog_path, updated_content) |
| 135 | + puts "Added new version #{version} to CHANGELOG.md with date #{current_date}" |
| 136 | + end |
| 137 | +end |
| 138 | + |
| 139 | +# Release tasks |
| 140 | +namespace :release do |
| 141 | + desc "Prepare release with updated changelog date" |
| 142 | + task :prepare, [:version] do |task, args| |
| 143 | + version = args[:version] || ENV['VERSION'] |
| 144 | + |
| 145 | + if version |
| 146 | + Rake::Task["changelog:new_version"].invoke(version) |
| 147 | + else |
| 148 | + Rake::Task["changelog:update_date"].invoke |
| 149 | + end |
| 150 | + |
| 151 | + puts "Release preparation complete!" |
| 152 | + puts "Don't forget to:" |
| 153 | + puts "1. Update version in lib/a2a/version.rb" |
| 154 | + puts "2. Commit changes" |
| 155 | + puts "3. Create and push git tag: git tag v#{version || 'X.X.X'} && git push origin v#{version || 'X.X.X'}" |
| 156 | + end |
| 157 | +end |
| 158 | + |
68 | 159 | # Default task |
69 | 160 | task default: :spec |
70 | 161 |
|
|
0 commit comments