Sha256: 5ee2fa9acd712702dbbed6e5fc8b2103a584d3c52f701ef5bb11680d9c5b6d2c

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'structured_changelog'
require 'git'

desc 'Commit changes to the Changelog & version files as necessary'
task 'changelog:commit', [:repo_path, :changelog_path, :version_path] do |_task, arguments|
  repo_path      = arguments.to_h.fetch(:repo_path)      { Pathname.pwd }
  changelog_path = arguments.to_h.fetch(:changelog_path) { "CHANGELOG.md" }
  version_path   = arguments.to_h.fetch(:version_path)   { "lib/#{Pathname.pwd.basename}/version.rb" }

  changelog = StructuredChangelog.new(changelog_path)
  git       = Git.open(repo_path)

  if git.status.deleted.any?
    abort "Please commit all file deletions before bumping the version."
  end

  if git.status.added.any?
    abort "Please commit all new files before bumping the version."
  end

  diff               = git.diff('HEAD').stats[:files]
  acceptable_changes = [changelog_path, version_path, 'Gemfile.lock']

  only_release_changes = (diff.keys - acceptable_changes).empty?

  unless only_release_changes
    abort "Please commit all files that aren't #{acceptable_changes.join(' or ')} before bumping the version."
  end

  if diff.key?('Gemfile.lock')
    lockfile_only_changed_version = diff['Gemfile.lock'][:deletions] == 1 && diff['Gemfile.lock'][:insertions] == 1

    unless lockfile_only_changed_version
      abort "Please commit all Gemfile.lock changes not related to this version bump."
    end

    git.add(['Gemfile.lock'])
  end

  git.add([changelog_path, version_path])
  git.commit("Version bump to #{changelog.version}")

  puts "Commited 'Version bumped to #{changelog.version}'"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
structured_changelog-0.8.1 lib/structured_changelog/tasks/commit.rb