Skip to content

Commit

Permalink
Improve bump script
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jul 29, 2024
1 parent 1c0fcaf commit 0b4b348
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions scripts/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require_relative 'scripty'

# Abort if the working tree is dirty
Scripty.die('Working tree dirty!') unless `git status --porcelain`.empty?
Scripty.abort('Working tree dirty!') unless `git status --porcelain`.empty?

# Prompt for the new version
require_relative '../gem/lib/pagy'
Expand All @@ -15,14 +15,14 @@
new_version = gets.chomp

# Abort if the version is missing
Scripty.die('Missing new version!') if new_version.empty?
Scripty.abort('Missing new version!') if new_version.empty?

# Abort if the version is invalid
new_fragments = new_version.split('.')
Scripty.die('Incomplete semantic version!') if new_fragments.size < 3
Scripty.abort('Incomplete semantic version!') if new_fragments.size < 3

# Abort if there is no gem change
Scripty.die("No gem changes since version #{old_version}!") \
Scripty.abort("No gem changes since version #{old_version}!") \
if `git diff --name-only --relative=gem "#{old_version}"..HEAD`.empty?

# Bump the version in files
Expand Down Expand Up @@ -79,14 +79,14 @@
Scripty.tagged_file_sub(release_body_path, 'whats_new', whats_new_content)

# Insert the changes into latest_release_body file
changes = "\n#{File.read(gitlog.path)}"
changes = File.read(gitlog.path)
Scripty.tagged_file_sub(release_body_path, 'changes', changes)

# Edit the Rlease Body?
Scripty.file_edit?('Release Body', release_body_path)

# Update the CHANGELOG
Scripty.file_sub('CHANGELOG.md', /<hr>\n/, "<hr>\n\n## Version #{new_version}\n#{changes}")
Scripty.file_sub('CHANGELOG.md', /<hr>\n/, "<hr>\n\n## Version #{new_version}\n\n#{changes}")

# Run the test to check the consistency of versioning across files
system('bundle exec rake test_version')
Expand Down
10 changes: 5 additions & 5 deletions scripts/scripty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def ask_and_do(question)
module_function :ask_and_do

# Warn and exit
def die(message)
def abort(message)
warn message
exit 1
end
module_function :die
module_function :abort

# Optional edit
def file_edit?(name, filepath)
Expand All @@ -43,16 +43,16 @@ def file_sub(filepath, search, replace)
def tagged_file_sub(filepath, tag, new_content)
filepath = ROOT.join(filepath).to_s
content = File.read(filepath)
content.sub!(/<!-- #{tag}_start -->.*<!-- #{tag}_end -->/m,
"<!-- #{tag}_start -->#{new_content}<!-- #{tag}_end -->")
content.sub!(/<!-- #{tag}_start -->\n.*<!-- #{tag}_end -->/m,
"<!-- #{tag}_start -->\n#{new_content}<!-- #{tag}_end -->")
File.write(filepath, content)
end
module_function :tagged_file_sub

def tagged_extract(filepath, tag)
filepath = ROOT.join(filepath).to_s
content = File.read(filepath)
content[/<!-- #{tag}_start -->(.*)<!-- #{tag}_end -->/m, 1]
content[/<!-- #{tag}_start -->\n(.*)<!-- #{tag}_end -->/m, 1]
end
module_function :tagged_extract
end

0 comments on commit 0b4b348

Please sign in to comment.