Skip to content

Commit

Permalink
Show .zip archive only for Windows (prometheus#1775)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
grobie authored Oct 29, 2020
1 parent da5fa0f commit 17b0494
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/helpers/download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ def assets
@data['assets']
end

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

def tag
Expand Down
14 changes: 14 additions & 0 deletions specs/download_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@
expect([bugfix, regular, rc1, rc0].sort).to eql([bugfix, regular, rc0, rc1])
end
end

describe '#binaries' do
let(:release) do
Downloads::Release.new({ 'assets' => [
{ 'name' => 'prometheus-1.2.0.linux-amd64.tar.gz' },
{ 'name' => 'prometheus-1.2.0.windows-amd64.tar.gz' },
{ 'name' => 'prometheus-1.2.0.windows-amd64.zip' },
]})
end

it 'prefers .zip format over .tar.gz' do
expect(release.binaries.map(&:name)).to eql(['prometheus-1.2.0.linux-amd64.tar.gz', 'prometheus-1.2.0.windows-amd64.zip'])
end
end
end

describe Downloads::Repository do
Expand Down

0 comments on commit 17b0494

Please sign in to comment.