Skip to content

Commit

Permalink
Merge pull request #2041 from UiP9AV6Y/feature_rpm_changelog
Browse files Browse the repository at this point in the history
rpm: generate changelog if none is provided
  • Loading branch information
jordansissel authored Dec 8, 2024
2 parents e6b83c4 + c9d749a commit 468f455
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/fpm/package/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions spec/fpm/package/rpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"
@target = Stud::Temporary.pathname

# Write RPM
subject.output(@target)

@rpm = ::RPM::File.new(@target)
insist { @rpm.tags[:changelogname] } == [ "Spec Test <[email protected]> - 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] = <<CHANGELOG
* Tue May 31 2016 Example Maintainers <[email protected]> - 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 <[email protected]> - 1.0-1" ]
insist { @rpm.tags[:changelogtext] } == [ "- First example package" ]

File.unlink(@target)
end
end # changelog
end # #output

describe "prefix attribute" do
Expand Down
2 changes: 1 addition & 1 deletion templates/rpm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,4 @@ fi
<% end -%>

%changelog
<%= attributes[:rpm_changelog] %>
<%= changelog %>

0 comments on commit 468f455

Please sign in to comment.