Skip to content

Commit 7425e2e

Browse files
committed
Automate CHANGELOG.md
1 parent e0b90a8 commit 7425e2e

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
1818
### [Unreleased]
1919
Changes since the last non-beta release.
2020

21+
## [15.0.0-alpha.2] - 2025-03-07
22+
2123
See [Release Notes](docs/release-notes/15.0.0.md) for full details.
2224

2325
#### Added
@@ -1205,7 +1207,8 @@ Best done with Object destructing:
12051207
##### Fixed
12061208
- Fix several generator-related issues.
12071209

1208-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/14.2.0...master
1210+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/15.0.0-alpha.2...master
1211+
[15.0.0-alpha.2]: https://github.com/shakacode/react_on_rails/compare/14.2.0...15.0.0-alpha.2
12091212
[14.2.0]: https://github.com/shakacode/react_on_rails/compare/14.1.1...14.2.0
12101213
[14.1.1]: https://github.com/shakacode/react_on_rails/compare/14.1.0...14.1.1
12111214
[14.1.0]: https://github.com/shakacode/react_on_rails/compare/14.0.5...14.1.0

rakelib/release.rake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
7575
sh_in_dir(gem_root, "gem release") unless is_dry_run
7676

7777
msg = <<~MSG
78-
Once you have successfully published, run these commands to update Gemfile.lock locally and in the spec apps:
78+
Once you have successfully published, run these commands to update Gemfile.lock and CHANGELOG.md:
7979
8080
bundle install
81+
bundle exec rake update_changelog
8182
cd #{dummy_app_dir}; bundle update react_on_rails
8283
cd #{gem_root}
83-
git commit -a -m 'Update Gemfile.lock'
84+
git commit -a -m 'Update Gemfile.lock and CHANGELOG.md'
8485
git push
8586
MSG
8687
puts msg
@@ -89,7 +90,8 @@ end
8990

9091
task :test do
9192
bundle_install_in(gem_root)
93+
bundle_exec(gem_root, "rake test")
9294
unbundled_sh_in_dir(gem_root, "cd #{dummy_app_dir}; bundle update react_on_rails")
93-
sh_in_dir(gem_root, "git commit -a -m 'Update Gemfile.lock'")
95+
sh_in_dir(gem_root, "git commit -a -m 'Update Gemfile.lock and CHANGELOG.md'")
9496
sh_in_dir(gem_root, "git push")
9597
end

rakelib/task_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def bundle_install_in_no_turbolinks(dir)
4444

4545
# Runs bundle exec using that directory's Gemfile
4646
def bundle_exec(dir: nil, args: nil, env_vars: "")
47-
sh_in_dir(dir, "#{env_vars} #{args}")
47+
sh_in_dir(dir, "#{env_vars} bundle exec #{args}")
4848
end
4949

5050
def generators_source_dir

rakelib/update_changelog.rake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler"
4+
require_relative "task_helpers"
5+
6+
desc "Updates CHANGELOG.md inserting headers for the new version.
7+
8+
Argument: Git tag. Defaults to the latest tag."
9+
10+
task :update_changelog, %i[tag] do |_, args|
11+
tag = args[:tag] || `git describe --tags --abbrev=0`.strip
12+
anchor = "[#{tag}]"
13+
14+
changelog = File.read("CHANGELOG.md")
15+
16+
if changelog.include?(anchor)
17+
puts "Tag #{tag} already documented in CHANGELOG.md"
18+
next
19+
end
20+
21+
tag_date_output = `git show -s --format=%cs #{tag} 2>&1`
22+
if $?.success?
23+
tag_date = tag_date_output.split("\n").last.strip
24+
else
25+
puts "Failed to find the tag: #{tag_date_output}"
26+
next
27+
end
28+
29+
# after "Changes since the last non-beta release.", insert link header
30+
changelog.sub!("Changes since the last non-beta release.", "\\0\n\n## #{anchor} - #{tag_date}")
31+
32+
# find the link in "[Unreleased]: ...", update it, and add the link for our new tag after it
33+
match_data = %r{https://github.com/shakacode/react_on_rails/compare/(?<prev_tag>.*)\.\.\.master}.match(changelog)
34+
if match_data
35+
prev_tag = match_data[:prev_tag]
36+
new_unreleased_link = "https://github.com/shakacode/react_on_rails/compare/#{tag}...master"
37+
new_tag_link = "#{anchor}: https://github.com/shakacode/react_on_rails/compare/#{prev_tag}...#{tag}"
38+
changelog.sub!(match_data[0], "#{new_unreleased_link}\n#{new_tag_link}")
39+
end
40+
41+
File.write("CHANGELOG.md", changelog)
42+
end

0 commit comments

Comments
 (0)