Skip to content

Commit 8501f35

Browse files
committed
Automate CHANGELOG.md
1 parent c147370 commit 8501f35

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ If you think ShakaCode can help your project, [click here](https://meetings.hubs
1515
Please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.
1616

1717
## Versions
18-
### [15.0.0-alpha.2] - 2025-03-07
1918
Changes since the last non-beta release.
2019

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

2324
#### Added
@@ -1205,7 +1206,8 @@ Best done with Object destructing:
12051206
##### Fixed
12061207
- Fix several generator-related issues.
12071208

1208-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/14.2.0...master
1209+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/15.0.0-alpha.2...master
1210+
[15.0.0-alpha.2]: https://github.com/shakacode/react_on_rails/compare/14.2.0...15.0.0-alpha.2
12091211
[14.2.0]: https://github.com/shakacode/react_on_rails/compare/14.1.1...14.2.0
12101212
[14.1.1]: https://github.com/shakacode/react_on_rails/compare/14.1.0...14.1.1
12111213
[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 update_changelog")
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

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
abort("Failed to find tag #{tag}")
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+
compare_link_prefix = "https://github.com/shakacode/react_on_rails/compare"
34+
match_data = %r{#{compare_link_prefix}/(?<prev_tag>.*)\.\.\.master}.match(changelog)
35+
if match_data
36+
prev_tag = match_data[:prev_tag]
37+
new_unreleased_link = "#{compare_link_prefix}/#{tag}...master"
38+
new_tag_link = "#{anchor}: #{compare_link_prefix}/#{prev_tag}...#{tag}"
39+
changelog.sub!(match_data[0], "#{new_unreleased_link}\n#{new_tag_link}")
40+
end
41+
42+
File.write("CHANGELOG.md", changelog)
43+
puts "Updated CHANGELOG.md with an entry for #{tag}"
44+
end

0 commit comments

Comments
 (0)