diff --git a/lib/fpm/package/rpm.rb b/lib/fpm/package/rpm.rb index a925256561..0159c7e121 100644 --- a/lib/fpm/package/rpm.rb +++ b/lib/fpm/package/rpm.rb @@ -275,6 +275,24 @@ def iteration return @iteration ? @iteration : 1 end # def iteration + # Generate a generic changelog or return an existing definition + def changelog + if attributes[:rpm_changelog] + return attributes[:rpm_changelog] + end + + reldate = if attributes[:source_date_epoch].nil? + Time.now() + else + Time.at(attributes[:source_date_epoch].to_i) + end + changed = reldate.strftime("%a %b %_e %Y") + changev = "#{version}-#{iteration}" + changev += "%{?dist}" if attributes[:rpm_dist] + + "* #{changed} #{maintainer} - #{changev}\n- Package created with FPM\n" + end + # See FPM::Package#converted_from def converted_from(origin) if origin == FPM::Package::Gem diff --git a/spec/fpm/package/rpm_spec.rb b/spec/fpm/package/rpm_spec.rb index 77d62abc9d..015a801f4a 100644 --- a/spec/fpm/package/rpm_spec.rb +++ b/spec/fpm/package/rpm_spec.rb @@ -484,6 +484,45 @@ def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end File.unlink(@target) end end # dist + + context "changelog" do + it "should generate a changelog in the release" do + subject.name = "example" + subject.attributes[:rpm_dist] = 'rhel' + subject.version = "1.2.3" + subject.maintainer = "Spec Test " + @target = Stud::Temporary.pathname + + # Write RPM + subject.output(@target) + + @rpm = ::RPM::File.new(@target) + insist { @rpm.tags[:changelogname] } == [ "Spec Test - 1.2.3-1.rhel" ] + insist { @rpm.tags[:changelogtext] } == [ "- Package created with FPM" ] + + File.unlink(@target) + end + + it "should have the changelog in the release" do + subject.name = "example" + subject.attributes[:rpm_changelog] = < - 1.0-1 +- First example package +CHANGELOG + subject.version = "1.0" + @target = Stud::Temporary.pathname + + # Write RPM + subject.output(@target) + + @rpm = ::RPM::File.new(@target) + insist { @rpm.tags[:changelogtime] } == [ 1464696000 ] + insist { @rpm.tags[:changelogname] } == [ "Example Maintainers - 1.0-1" ] + insist { @rpm.tags[:changelogtext] } == [ "- First example package" ] + + File.unlink(@target) + end + end # changelog end # #output describe "prefix attribute" do diff --git a/templates/rpm.erb b/templates/rpm.erb index 0e851f26d9..584038f636 100644 --- a/templates/rpm.erb +++ b/templates/rpm.erb @@ -260,4 +260,4 @@ fi <% end -%> %changelog -<%= attributes[:rpm_changelog] %> +<%= changelog %>