Skip to content

Commit

Permalink
(packaging) Add rake tasks for building nightly gem
Browse files Browse the repository at this point in the history
The nightly gem's version (aka extended_dot_version) is generated from git
describe as the last tag, plus some number of commits and abbreviated git ref:

    4.7.0-36-g2ab655b

Additionally, if there are changes in the worktree, then we add 'dirty'
to the version.

    4.7.0-36-g2ab655b-dirty

The "extended_dot_version" is added to a temporary gemspec that's used
to build the gem. That version determines the resulting filename, e.g.

    facter-4.7.0-36-g2ab655b.gem

Neither the packaging repo nor this commit update the version in `version.rb`,
so running facter --version may return the "version to be released in the
future".
  • Loading branch information
joshcooper committed May 24, 2024
1 parent 2ab655b commit b956cd2
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,38 @@ end

namespace :pl_ci do
desc 'build the gem and place it at the directory root'
task :gem_build do
stdout, stderr, status = Open3.capture3('gem build facter.gemspec')
task :gem_build, [:gemspec] do |t, args|
args.with_defaults(gemspec: 'facter.gemspec')
stdout, stderr, status = Open3.capture3("gem build #{args.gemspec}")
if !status.exitstatus.zero?
puts "Error building facter.gemspec \n#{stdout} \n#{stderr}"
exit(1)
else
puts stdout
end
end

desc 'build the nightly gem and place it at the directory root'
task :nightly_gem_build do
# this is taken from `rake package:nightly_gem`
extended_dot_version = %x{git describe --tags --dirty --abbrev=7}.chomp.tr('-', '.')

# we must create tempfile in the same directory as facter.gemspec, since
# it uses __dir__ to determine which files to include
require 'tempfile'
Tempfile.create("gemspec", __dir__) do |dst|
File.open("facter.gemspec", "r") do |src|
src.readlines.each do |line|
if line.match?(/spec\.version\s*=\s*'[0-9.]+'/)
line = "spec.version = '#{extended_dot_version}'"
end
dst.puts line
end
end
dst.flush
Rake::Task['pl_ci:gem_build'].invoke(dst.path)
end
end
end

if Rake.application.top_level_tasks.grep(/^(pl:|package:)/).any?
Expand Down

0 comments on commit b956cd2

Please sign in to comment.