Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpm: generate changelog if none is provided #2041

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <spec.test@example.com>"
@target = Stud::Temporary.pathname

# Write RPM
subject.output(@target)

@rpm = ::RPM::File.new(@target)
insist { @rpm.tags[:changelogname] } == [ "Spec Test <spec.test@example.com> - 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 <fpm@example.com> - 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 <fpm@example.com> - 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 %>