From 7a7668d04ccf4bee75e2190e8ecb6a016eb57837 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Fri, 24 May 2024 12:34:29 -0700 Subject: [PATCH] (packaging) Add rake tasks for building nightly gem 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". --- Rakefile | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 1d5a3c9a9f..055f62d1b2 100644 --- a/Rakefile +++ b/Rakefile @@ -16,8 +16,9 @@ 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) @@ -25,6 +26,28 @@ namespace :pl_ci do 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 = `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?