Skip to content

Commit

Permalink
allow destination ids when uploading build (microsoft#326)
Browse files Browse the repository at this point in the history
Co-authored-by: Yves Delcoigne <[email protected]>
  • Loading branch information
DelcoigneYves and Yves Delcoigne authored Oct 17, 2023
1 parent b377ca2 commit 62e9573
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module SharedValues
APPCENTER_OWNER_NAME = :APPCENTER_OWNER_NAME
APPCENTER_APP_NAME = :APPCENTER_APP_NAME
APPCENTER_DISTRIBUTE_DESTINATIONS = :APPCENTER_DISTRIBUTE_DESTINATIONS
APPCENTER_DISTRIBUTE_DESTINATION_IDS = :APPCENTER_DISTRIBUTE_DESTINATION_IDS
end

class AppcenterFetchDevicesAction < Action
Expand Down
38 changes: 37 additions & 1 deletion lib/fastlane/plugin/appcenter/actions/appcenter_upload_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def self.run_release_upload(params)
owner_type = params[:owner_type]
app_name = params[:app_name]
destinations = params[:destinations]
destination_ids = params[:destination_ids]
destination_type = params[:destination_type]
mandatory_update = params[:mandatory_update]
notify_testers = params[:notify_testers]
Expand Down Expand Up @@ -172,6 +173,7 @@ def self.run_release_upload(params)
else
self.optional_error("Can't distribute #{file_ext} to stores, please use `destination_type: 'group'`") unless Constants::STORE_SUPPORTED_EXTENSIONS.include? file_ext
UI.user_error!("The combination of `destinations: '*'` and `destination_type: 'store'` is invalid, please use `destination_type: 'group'` or explicitly specify the destinations") if destinations == "*"
UI.user_error!("The combination of `destination_ids` and `destination_type: 'store'` is invalid, please use `destination_type: 'group'` or use `destinations`") unless destination_ids.to_s.strip.empty?
end

release_upload_body = nil
Expand Down Expand Up @@ -248,7 +250,12 @@ def self.run_release_upload(params)
else
destinations_array = destinations.split(',').map(&:strip)
end


destination_ids_array = []
unless destination_ids.to_s.empty?
destination_ids_array = destination_ids.split(',').map(&:strip)
end

destinations_array.each do |destination_name|
destination = Helper::AppcenterHelper.get_destination(api_token, owner_name, app_name, destination_type, destination_name)
if destination
Expand All @@ -264,6 +271,17 @@ def self.run_release_upload(params)
end
end

unless destination_ids_array.empty?
destination_ids_array.each do |destination_id|
distributed_release = Helper::AppcenterHelper.add_to_destination(api_token, owner_name, app_name, release_id, destination_type, destination_id, mandatory_update, notify_testers)
if distributed_release
UI.success("Release '#{release_id}' (#{distributed_release['short_version']}) was successfully distributed to #{destination_type} \"#{destination_id}\"")
else
UI.error("Release '#{release_id}' was not found for destination '#{destination_id}'")
end
end
end

safe_download_url = Helper::AppcenterHelper.get_install_url(owner_type, owner_name, app_name)
UI.message("Release '#{release_id}' is available for download at: #{safe_download_url}")
else
Expand Down Expand Up @@ -582,6 +600,13 @@ def self.available_options
optional: true,
type: String),

FastlaneCore::ConfigItem.new(key: :destination_ids,
env_name: "APPCENTER_DISTRIBUTE_DESTINATION_IDS",
description: "Comma separated list of destination ids, use '00000000-0000-0000-0000-000000000000' for distributing to the Collaborators group. Only distribution groups are supported",
default_value: Actions.lane_context[SharedValues::APPCENTER_DISTRIBUTE_DESTINATION_IDS],
optional: true,
type: String),

FastlaneCore::ConfigItem.new(key: :destination_type,
env_name: "APPCENTER_DISTRIBUTE_DESTINATION_TYPE",
description: "Destination type of distribution destination. 'group' and 'store' are supported",
Expand Down Expand Up @@ -701,6 +726,17 @@ def self.example_code
release_notes: "release notes",
notify_testers: false
)',
'appcenter_upload(
api_token: "...",
owner_name: "appcenter_owner",
app_name: "testing_ios_app",
file: "./app-release.ipa",
destination_ids: "00000000-0000-0000-0000-000000000000,12341234-1234-1234-1234-123412341234",
destination_type: "group",
dsym: "./app.dSYM.zip",
release_notes: "release notes",
notify_testers: false
)',
'appcenter_upload(
api_token: "...",
owner_name: "appcenter_owner",
Expand Down
31 changes: 31 additions & 0 deletions spec/appcenter_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,37 @@
end.to raise_error("The combination of `destinations: '*'` and `destination_type: 'store'` is invalid, please use `destination_type: 'group'` or explicitly specify the destinations")
end

it "destination_ids for store type" do
expect do
stub_poll_sleeper
stub_check_app(200)
stub_create_release_upload(200)
stub_set_release_upload_metadata(200, "ipa_file_empty.ipa")
stub_upload_build(200)
stub_finish_release_upload(200)
stub_poll_for_release_id(200)
stub_update_release_upload(200, 'uploadFinished')
stub_update_release(200, "No changelog given")
stub_add_to_destination(200)
stub_get_release(200)
stub_create_dsym_upload(200)
stub_upload_dsym(200)
stub_update_dsym_upload(200, "committed")

Fastlane::FastFile.new.parse("lane :test do
appcenter_upload({
api_token: 'xxx',
owner_name: 'owner',
app_name: 'app',
ipa: './spec/fixtures/appfiles/ipa_file_empty.ipa',
dsym: './spec/fixtures/symbols/Themoji.dSYM.zip',
destination_ids: '12341234-1234-1234-1234-123412341234',
destination_type: 'store'
})
end").runner.execute(:test)
end.to raise_error("The combination of `destination_ids` and `destination_type: 'store'` is invalid, please use `destination_type: 'group'` or use `destinations`")
end

it "Handles invalid app name error" do
expect do
Fastlane::FastFile.new.parse("lane :test do
Expand Down

0 comments on commit 62e9573

Please sign in to comment.