Method: Supply::Uploader#update_rollout

Defined in:
supply/lib/supply/uploader.rb

#update_rolloutObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'supply/lib/supply/uploader.rb', line 126

def update_rollout
  track, release = fetch_track_and_release!(Supply.config[:track], Supply.config[:version_code], [Supply::ReleaseStatus::IN_PROGRESS, Supply::ReleaseStatus::DRAFT])
  UI.user_error!("Unable to find the requested track - '#{Supply.config[:track]}'") unless track
  UI.user_error!("Unable to find the requested release on track - '#{Supply.config[:track]}'") unless release

  version_code = release.version_codes.max

  UI.message("Updating #{version_code}'s rollout to '#{Supply.config[:rollout]}' on track '#{Supply.config[:track]}'...")

  if track && release
    rollout = Supply.config[:rollout]
    status = Supply.config[:release_status]

    # If release_status not provided explicitly (and thus defaults to 'completed'), but rollout is provided with a value < 1.0, then set to 'inProgress' instead
    status = Supply::ReleaseStatus::IN_PROGRESS if status == Supply::ReleaseStatus::COMPLETED && !rollout.nil? && rollout.to_f < 1
    # If release_status is set to 'inProgress' but rollout is provided with a value = 1.0, then set to 'completed' instead
    status = Supply::ReleaseStatus::COMPLETED if status == Supply::ReleaseStatus::IN_PROGRESS && rollout.to_f == 1
    # If release_status is set to 'inProgress' but no rollout value is provided, error out
    UI.user_error!("You need to provide a rollout value when release_status is set to 'inProgress'") if status == Supply::ReleaseStatus::IN_PROGRESS && rollout.nil?
    release.status = status
    # user_fraction is only valid for IN_PROGRESS or HALTED status
    # https://googleapis.dev/ruby/google-api-client/latest/Google/Apis/AndroidpublisherV3/TrackRelease.html#user_fraction-instance_method
    release.user_fraction = [Supply::ReleaseStatus::IN_PROGRESS, Supply::ReleaseStatus::HALTED].include?(release.status) ? rollout : nil

    # It's okay to set releases to an array containing the newest release
    # Google Play will keep previous releases there untouched
    track.releases = [release]
  else
    UI.user_error!("Unable to find version to rollout in track '#{Supply.config[:track]}'")
  end

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