diff --git a/README.md b/README.md index ab0bc8d..9c57a69 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,36 @@ Then, at the top of your `Rakefile`, add: require 'voxpupuli-release' ``` -To cut a new release of your module, ensure the `metadata.json` reflects the proper version. Also ensure that the `CHANGELOG.md` has a note about the release and that it actually is named Release or release, some old modules refer to it as Version, which won't work. Lastly check that no tag exists with that version number (format `v#.#.#`), and then run: +# Making a new release + +## Preparations + +First we prepare the release. Ensure you're on a clean branch. Also set ```CHANGELOG_GITHUB_TOKEN``` so you can generate the changelog without hitting rate limts. + +``` +bundle exec rake prepare_release[NEW_VERSION] +``` + +This will bump the version. You can either use `major`, `minor`, `patch` or specify a full version in the `X.Y.Z` format. + +Next you commit this, push it to your remote and create a PR. The following code makes some assumptions about your layout: + +```bash +VERSION="$(bundle exec rake module:version)" +git checkout -b release-$VERSION +git add metadata.json CHANGELOG.md +git commit -m "Release $VERSION" + +# Push it to a remote that matches your username +git push $(whoami) HEAD -u + +# Assumes you have hub installed +hub pull-request -m "Release $VERSION" +``` + +## Releasing + +We'll assume that the preparation PR was acknowledged and merged. ``` bundle exec rake travis_release diff --git a/lib/voxpupuli/release/rake_tasks.rb b/lib/voxpupuli/release/rake_tasks.rb index 70bb8b2..d8453d3 100644 --- a/lib/voxpupuli/release/rake_tasks.rb +++ b/lib/voxpupuli/release/rake_tasks.rb @@ -1,36 +1,57 @@ +require 'github_changelog_generator/task' + +desc 'Prepare a new release' +task :prepare_release, [:version] do |t, args| + unless args[:version] + puts 'you need to provide a version like: rake prepare_release[1.0.0]' + exit + end + + version = args[:version] + if ['major', 'minor', 'patch'].include?(version) + bump_task = "module:bump:#{version}" + elsif /^\d+\.\d+\.\d+$/.match(version) + bump_task = 'module:bump:full' + ENV['BLACKSMITH_FULL_VERSION'] = version + else + puts 'Version needs to be major, minor, patch or in the X.X.X format' + exit + end + + Rake::Task[bump_task].invoke + Rake::Task['changelog'].invoke +end desc 'release new version through Travis-ci' -task "travis_release" do +task "travis_release" => [:check_version, :check_changelog, 'module:clean'] do require 'puppet_blacksmith/rake_tasks' Blacksmith::RakeTask.new do |t| - t.build = false # do not build the module nor push it to the Forge - # just do the tagging [:clean, :tag, :bump_commit] + t.tag_message_pattern = "Version %s" # Use annotated commits end - m = Blacksmith::Modulefile.new - v = m.version - raise "Refusing to release an RC or build-release (#{v}).\n" + - "Please set a semver *release* version." unless v =~ /^\d+\.\d+.\d+$/ - - Rake::Task[:check_changelog].invoke - # do a "manual" module:release (clean, tag, bump, commit, push tags) - Rake::Task["module:clean"].invoke - # idempotently create tags + m = Blacksmith::Modulefile.new g = Blacksmith::Git.new - Rake::Task["module:tag"].invoke unless g.has_version_tag?(v) + Rake::Task["module:tag"].invoke unless g.has_version_tag?(m.version) - v_inc = m.increase_version(v) - v_new = "#{v_inc}-rc0" + # Bump to the next version as rc0 + v_new = "#{m.increase_version(m.version)}-rc0" ENV['BLACKSMITH_FULL_VERSION'] = v_new - Rake::Task["module:bump:full"].invoke + Rake::Task["module:bump_commit:full"].invoke # push it out, and let travis do the release: - g.commit_modulefile!(v_new) g.push! end +desc 'Check if the version is a semver release version' +task :check_version do + m = Blacksmith::Modulefile.new + v = m.version + fail "Refusing to release an RC or build-release (#{v}).\n" + + "Please set a semver *release* version." unless v =~ /^\d+\.\d+.\d+$/ +end + desc 'Check Changelog.' task :check_changelog do v = Blacksmith::Modulefile.new.version @@ -42,3 +63,12 @@ fail "Unable to find a CHANGELOG.md entry for the #{v} release." end end + +GitHubChangelogGenerator::RakeTask.new :changelog do |config| + modulefile = Blacksmith::Modulefile.new + config.user = 'voxpupuli' + config.project = modulefile.name + config.future_release = "v#{modulefile.version}" if modulefile.version =~ /^\d+\.\d+.\d+$/ + config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." + config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} +end diff --git a/voxpupuli-release.gemspec b/voxpupuli-release.gemspec index e51a5a4..0b4c703 100644 --- a/voxpupuli-release.gemspec +++ b/voxpupuli-release.gemspec @@ -19,4 +19,6 @@ Gem::Specification.new do |s| # Runtime dependencies, but also probably dependencies of requiring projects s.add_runtime_dependency 'rake' s.add_runtime_dependency 'puppet-blacksmith', '>= 4.0.0' + # We actually want an unreleased version from it + s.add_runtime_dependency 'github_changelog_generator', '>= 1.14.0' end