Skip to content

Commit 17b0494

Browse files
authored
Show .zip archive only for Windows (prometheus#1775)
If a release archive is available in both .tar.gz and .zip format, only show the .zip archive in the download list. Signed-off-by: Tobias Schmidt <[email protected]>
1 parent da5fa0f commit 17b0494

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/helpers/download.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,15 @@ def assets
125125
@data['assets']
126126
end
127127

128+
# binaries returns a list of release archives in the .tar.gz or .zip format.
129+
# If both formats are available, only .zip is returned (covers Windows use case).
128130
def binaries
129131
assets.
130132
select { |d| d['name'] && %w[.tar.gz .zip].any? { |ext| d['name'].end_with?(ext) } }.
131-
map { |d| Binary.new(d) }
133+
map { |d| Binary.new(d) }.
134+
group_by { |b| [b.os, b.arch] }.
135+
map { |_, binaries| binaries.sort_by(&:name).last }.
136+
sort_by(&:name)
132137
end
133138

134139
def tag

specs/download_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@
4747
expect([bugfix, regular, rc1, rc0].sort).to eql([bugfix, regular, rc0, rc1])
4848
end
4949
end
50+
51+
describe '#binaries' do
52+
let(:release) do
53+
Downloads::Release.new({ 'assets' => [
54+
{ 'name' => 'prometheus-1.2.0.linux-amd64.tar.gz' },
55+
{ 'name' => 'prometheus-1.2.0.windows-amd64.tar.gz' },
56+
{ 'name' => 'prometheus-1.2.0.windows-amd64.zip' },
57+
]})
58+
end
59+
60+
it 'prefers .zip format over .tar.gz' do
61+
expect(release.binaries.map(&:name)).to eql(['prometheus-1.2.0.linux-amd64.tar.gz', 'prometheus-1.2.0.windows-amd64.zip'])
62+
end
63+
end
5064
end
5165

5266
describe Downloads::Repository do

0 commit comments

Comments
 (0)