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

[deliver] fetch live app info if no edit info is present, fixing scenario of having both macOS and iOS apps present #21472

Merged
merged 21 commits into from Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
60 changes: 52 additions & 8 deletions deliver/lib/deliver/upload_metadata.rb
Expand Up @@ -89,7 +89,7 @@ def upload(options)
enabled_languages = detect_languages(options)

app_store_version_localizations = verify_available_version_languages!(options, app, enabled_languages) unless options[:edit_live]
app_info_localizations = verify_available_info_languages!(options, app, enabled_languages) unless options[:edit_live]
app_info_localizations = verify_available_info_languages!(options, app, enabled_languages) unless options[:edit_live] || !updating_localised_app_info?(options, app)
rogerluan marked this conversation as resolved.
Show resolved Hide resolved

if options[:edit_live]
# not all values are editable when using live_version
Expand Down Expand Up @@ -211,15 +211,17 @@ def upload(options)
store_version_worker.start

# Update app info localizations
app_info_worker = FastlaneCore::QueueWorker.new do |app_info_localization|
attributes = localized_info_attributes_by_locale[app_info_localization.locale]
if attributes
UI.message("Uploading metadata to App Store Connect for localized info '#{app_info_localization.locale}'")
app_info_localization.update(attributes: attributes)
unless app_info_localizations.nil?
loremattei marked this conversation as resolved.
Show resolved Hide resolved
app_info_worker = FastlaneCore::QueueWorker.new do |app_info_localization|
attributes = localized_info_attributes_by_locale[app_info_localization.locale]
if attributes
UI.message("Uploading metadata to App Store Connect for localized info '#{app_info_localization.locale}'")
app_info_localization.update(attributes: attributes)
end
end
app_info_worker.batch_enqueue(app_info_localizations)
app_info_worker.start
end
app_info_worker.batch_enqueue(app_info_localizations)
app_info_worker.start
rogerluan marked this conversation as resolved.
Show resolved Hide resolved

# Update categories
app_info = fetch_edit_app_info(app)
loremattei marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -437,6 +439,12 @@ def fetch_edit_app_info(app, wait_time: 10)
end
end

def fetch_live_app_info(app, wait_time: 10)
retry_if_nil("Cannot find live app info", wait_time: wait_time) do
app.fetch_live_app_info
end
end

def retry_if_nil(message, tries: 5, wait_time: 10)
loop do
tries -= 1
Expand All @@ -451,6 +459,42 @@ def retry_if_nil(message, tries: 5, wait_time: 10)
end
end

# Checking if the metadata to update includes localised App Info
def updating_localised_app_info?(options, app)
app_info = fetch_edit_app_info(app) || fetch_live_app_info(app)
unless app_info
UI.important('Can\'t find edit or live App info. Skipping upload.')
loremattei marked this conversation as resolved.
Show resolved Hide resolved
return false
end
localizations = app_info.get_app_info_localizations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Unrelated to this PR]

@rogerluan we definitively need to improve our YARD doc on many of our model methods. This isn't clear at all from the definition of the AppInfo#get_app_info_localizations what that method is supposed to return, which makes it harder to read code that uses it like here and why Lore needed to use localizations.find below.

(After some digging, the answer is that it returns Array<Spaceship::ConnectAPI::AppInfo>; which makes sense in retrospect I guess, but was't obvious to me at first sight, and RubyMine isn't able to deduce it automatically)


LOCALISED_APP_VALUES.keys.each do |key|
rogerluan marked this conversation as resolved.
Show resolved Hide resolved
current = options[key]
next unless current

unless current.kind_of?(Hash)
UI.error("Error with provided '#{key}'. Must be a hash, the key being the language.")
rogerluan marked this conversation as resolved.
Show resolved Hide resolved
next
end

current.each do |language, value|
next unless value.to_s.length > 0
loremattei marked this conversation as resolved.
Show resolved Hide resolved
strip_value = value.to_s.strip
next if strip_value.empty?

app_info_locale = localizations.find { |l| l.locale == language }
next if app_info_locale.nil?

current_value = app_info_locale.public_send(key.to_sym)

return true if current_value != strip_value
end
end

UI.important('No changes to localised App Info detected. Skipping upload.')
rogerluan marked this conversation as resolved.
Show resolved Hide resolved
return false
end

# Finding languages to enable
def verify_available_info_languages!(options, app, languages)
app_info = fetch_edit_app_info(app)
Expand Down
9 changes: 8 additions & 1 deletion deliver/spec/upload_metadata_spec.rb
rogerluan marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -257,11 +257,18 @@ def create_metadata(path, text)
description: { "en-US" => "App description" }
}

# Get number of verions (used for if whats_new should be sent)
# Get number of versions (used for if whats_new should be sent)
expect(Spaceship::ConnectAPI).to receive(:get_app_store_versions).and_return(app_store_versions)

expect(version).to receive(:update).with(attributes: {})

# Get app info
expect(app).to receive(:fetch_edit_app_info).and_return(app_info)
expect(app_info).to receive(:get_app_info_localizations).and_return([app_info_localization_en])

# Get app info localization English (Used to compare with data to upload)
expect(app_info_localization_en).to receive(:name).and_return("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 rubocop might complain if you use double-quotes while you don't need any interpolation

Suggested change
expect(app_info_localization_en).to receive(:name).and_return("")
expect(app_info_localization_en).to receive(:name).and_return('')

💡 Also, might make it clearer and easier to understand the logic of the spec to provide a dummy name instead? Or was it intentional and important to the test that this was blank?

Suggested change
expect(app_info_localization_en).to receive(:name).and_return("")
expect(app_info_localization_en).to receive(:name).and_return('Old App Name')

Copy link
Member

@rogerluan rogerluan Sep 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 rubocop might complain if you use double-quotes while you don't need any interpolation

The rubocop rules we have in fastlane explicitly allows both " and ' to be used whenever 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL!


# Update version localization
expect(version_localization_en).to receive(:update).with(attributes: {
"description" => options[:description]["en-US"]
Expand Down