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

[supply] Fix halted status change handling #22004

Open
wants to merge 1 commit into
base: master
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions supply/lib/supply/uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def perform_upload
if Supply.config[:track_promote_to]
track_to_update = Supply.config[:track_promote_to]
promote_track
elsif Supply.config[:track_promote_release_status] == Supply::ReleaseStatus::HALTED
# If HALTED is specified, the current track type is not changed and the operation is performed on the current track
halt_track
elsif !Supply.config[:rollout].nil? && Supply.config[:track].to_s != ""
update_rollout
end
Expand Down Expand Up @@ -222,6 +225,35 @@ def promote_track
client.update_track(Supply.config[:track_promote_to], track_to)
end

def halt_track
track_from = client.tracks(Supply.config[:track]).first
unless track_from
UI.user_error!("Cannot halt track '#{Supply.config[:track]}' - track doesn't exist")
end

releases = track_from.releases
if Supply.config[:version_code].to_s != ""
releases = releases.select do |release|
release.version_codes.include?(Supply.config[:version_code].to_s)
end
else
releases = releases.select do |release|
release.status == Supply::ReleaseStatus::IN_PROGRESS
end
end

if releases.size == 0
UI.user_error!("Track '#{Supply.config[:track]}' doesn't have any releases")
elsif releases.size > 1
UI.user_error!("Track '#{Supply.config[:track]}' has more than one release - use :version_code to filter the release to halt")
end

release = releases.first
release.status = Supply::ReleaseStatus::HALTED

client.update_track(Supply.config[:track], track_from)
end

def upload_changelog(language, version_code)
UI.user_error!("Cannot find changelog because no version code given - please specify :version_code") unless version_code

Expand Down
118 changes: 118 additions & 0 deletions supply/spec/uploader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,124 @@ def find_obbs
end
end

describe 'halt_track' do
subject { Supply::Uploader.new.halt_track }

let(:track_stage) { 'alpha' }
let(:client) { double('client') }
let(:version_codes) { ['1', '2', '3'] }
let(:config) {
{
release_status: Supply::ReleaseStatus::IN_PROGRESS,
track_promote_release_status: Supply::ReleaseStatus::HALTED,
track: track_stage,
}
}
let(:track) { double('alpha') }
let(:release) { double('release1') }

before do
Supply.config = config
allow(Supply::Client).to receive(:make_from_config).and_return(client)
allow(client).to receive(:tracks).and_return([track])
allow(track).to receive(:releases).and_return([release])
allow(track).to receive(:releases=)
allow(release).to receive(:status=)

allow(client).to receive(:update_track).with(config[:track], track)
end

context 'when version_code is specified' do
let(:config) {
{
version_code: version_codes.first,
track_promote_release_status: Supply::ReleaseStatus::HALTED,
track: 'alpha',
}
}

before do
allow(release).to receive(:version_codes).and_return(version_codes)
end

it 'should call update_track with track_from' do
expect(release).to receive(:status=).with(Supply::ReleaseStatus::HALTED)

expect(client).to receive(:update_track).with(config[:track], track).once
subject
end
end

context 'when release_status is specified' do
let(:config) {
{
release_status: Supply::ReleaseStatus::IN_PROGRESS,
track_promote_release_status: Supply::ReleaseStatus::HALTED,
track: 'alpha',
}
}

before do
allow(release).to receive(:status).and_return(Supply::ReleaseStatus::IN_PROGRESS)
end

it 'should call update_track with track_from' do
expect(release).to receive(:status=).with(Supply::ReleaseStatus::HALTED)

expect(client).to receive(:update_track).with(config[:track], track).once
subject
end
end

context 'when there is no tracks' do
before do
allow(client).to receive(:tracks).and_return([])
end

it 'should only print no track error' do
expect(track).not_to receive(:releases)
expect(client).not_to receive(:update_track)

expect { subject }.to raise_error(FastlaneCore::Interface::FastlaneError, /Cannot halt track '#{track_stage}' - track doesn't exist/)
end
end

context 'when there is no releases on the track' do
before do
allow(track).to receive(:releases).and_return([])
end

it 'should only print no releases error' do
expect(client).not_to receive(:update_track)

expect { subject }.to raise_error(FastlaneCore::Interface::FastlaneError, /Track '#{track_stage}' doesn't have any releases/)
end
end

context 'when there is more than one list' do
let(:release2) { double('release2') }
let(:config) {
{
release_status: Supply::ReleaseStatus::IN_PROGRESS,
track_promote_release_status: Supply::ReleaseStatus::HALTED,
track: track_stage,
}
}

before do
allow(release).to receive(:status).and_return(Supply::ReleaseStatus::IN_PROGRESS)
allow(release2).to receive(:status).and_return(Supply::ReleaseStatus::IN_PROGRESS)
allow(track).to receive(:releases).and_return([release, release2])
end

it 'should only print an error indicating there is more than one release' do
expect(client).not_to receive(:update_track)

expect { subject }.to raise_error(FastlaneCore::Interface::FastlaneError, /Track '#{track_stage}' has more than one release - use :version_code to filter the release to halt/)
end
end
end

# add basic == functionality to LocalizedText class for testing purpose
class AndroidPublisher::LocalizedText
def ==(other)
Expand Down