forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump-version.rb
executable file
·52 lines (42 loc) · 1.5 KB
/
bump-version.rb
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
#!/usr/bin/env ruby
# frozen_string_literal: true
unless %w(minor patch).include?(ARGV[0])
puts "usage: bin/bump-version.rb minor|patch"
exit 1
end
component = ARGV[0].to_sym
# Update version file
version_path = File.join(__dir__, "..", "lib", "dependabot", "version.rb")
version_contents = File.read(version_path)
version = version_contents.scan(/\d+.\d+.\d+/).first
segments = Gem::Version.new(version).segments
new_version =
case component
when :minor
[segments[0], segments[1] + 1, 0].join(".")
when :patch
[segments[0], segments[1], segments[2] + 1].join(".")
end
new_version_contents = version_contents.gsub(version, new_version)
File.open(version_path, "w") { |f| f.write(new_version_contents) }
puts "✓ lib/dependabot/version.rb updated"
# Update CHANGELOG
changelog_path = File.join(__dir__, "..", "CHANGELOG.md")
changelog_contents = File.read(changelog_path)
commit_subjects = `git log --pretty="%s" v#{version}..HEAD`.lines
proposed_changes = commit_subjects.map { |line| "- #{line}" }.join("")
new_changelog_contents = [
"## v#{new_version}, #{Time.now.strftime('%e %B %Y').strip}\n",
proposed_changes,
changelog_contents
].join("\n")
File.open(changelog_path, "w") { |f| f.write(new_changelog_contents) }
puts "✓ CHANGELOG.md updated"
puts
puts "Double check the changes (editing CHANGELOG.md where necessary), then"
puts "commit, tag, and push the release:"
puts
puts "git commit -a -m 'v#{new_version}'"
puts "git tag 'v#{new_version}'"
puts "git push --tags origin master"
puts