Skip to content

Commit b3d325a

Browse files
committed
Automate CHANGELOG.md
1 parent e0b90a8 commit b3d325a

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

CHANGELOG.md

+4-1
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

+5-3
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

+1-1
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

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

0 commit comments

Comments
 (0)