Skip to content

Commit

Permalink
[action][download_dsyms] fix: download_dsyms with `wait_for_dsym_pr…
Browse files Browse the repository at this point in the history
…ocessing` is not checking the latest data from Connect API (#19523)

* Fix: `download_dsyms` with `wait_for_dsym_processing` is not checking the latest data from Connect API

* Added tests

* Apply suggestions from code review

Co-authored-by: Satoshi Namai <s.namai.09@gmail.com>

* Fixed tests

Co-authored-by: Josh Holtz <me@joshholtz.com>
Co-authored-by: Satoshi Namai <s.namai.09@gmail.com>
  • Loading branch information
3 people authored Dec 6, 2021
1 parent 77be2c7 commit 2668eff
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 33 deletions.
44 changes: 21 additions & 23 deletions fastlane/lib/fastlane/actions/download_dsyms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,39 +115,37 @@ def self.run(params)
end

UI.verbose("Build_version: #{asc_build_number} matches #{build_number}, grabbing dsym_url") if build_number

build.build_bundles&.each do |build_bundle|
download_dsym(build_bundle: build_bundle, build: build, app: app, wait_for_dsym_processing: wait_for_dsym_processing, wait_timeout: wait_timeout, output_directory: output_directory)
end
download_dsym(build: build, app: app, wait_for_dsym_processing: wait_for_dsym_processing, wait_timeout: wait_timeout, output_directory: output_directory)
end
end

def self.download_dsym(build_bundle: nil, build: nil, app: nil, wait_for_dsym_processing: nil, wait_timeout: nil, output_directory: nil)
def self.download_dsym(build: nil, app: nil, wait_for_dsym_processing: nil, wait_timeout: nil, output_directory: nil)
start = Time.now
download_url = nil
dsym_urls = []

loop do
download_url = build_bundle.dsym_url

unless download_url
if !wait_for_dsym_processing || (Time.now - start) > wait_timeout
# In some cases, AppStoreConnect does not process the dSYMs, thus no error should be thrown.
UI.message("Could not find any dSYM for #{build.version} (#{build.app_version})")
else
UI.message("Waiting for dSYM file to appear...")
sleep(30)
next
end
build_bundles = build.build_bundles.select { |b| b.includes_symbols == true }
dsym_urls = build_bundles.map(&:dsym_url).compact

break if build_bundles.count == dsym_urls.count

if !wait_for_dsym_processing || (Time.now - start) > wait_timeout
# In some cases, AppStoreConnect does not process the dSYMs, thus no error should be thrown.
UI.message("Could not find any dSYM for #{build.version} (#{build.app_version})")
break
else
UI.message("Waiting for dSYM file to appear...")
sleep(30) unless FastlaneCore::Helper.is_test?
build = Spaceship::ConnectAPI::Build.get(build_id: build.id)
end

break
end

if download_url
self.download(download_url, build, app, output_directory)
return if build.version
else
if dsym_urls.count == 0
UI.message("No dSYM URL for #{build.version} (#{build.app_version})")
else
dsym_urls.each do |url|
self.download(url, build, app, output_directory)
end
end
end
# rubocop:enable Metrics/PerceivedComplexity
Expand Down
58 changes: 48 additions & 10 deletions fastlane/spec/actions_specs/download_dsyms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
let(:build6) { double('build6') }

let(:build_bundle) { double('build_bundle') }
let(:empty_build_bundle) { double('empty_build_bundle') }
let(:not_processed_build_bundle) { double('not_processed_build_bundle') }
let(:no_symbols_build_bundle) { double('no_symbols_build_bundle') }

let(:empty_build) { double('empty_build') }
let(:not_processed_build) { double('not_processed_build') }
let(:no_symbols_build) { double('no_symbols_build') }

let(:download_url) { 'https://example.com/myapp-dsym' }

Expand All @@ -43,9 +45,17 @@
allow(build5).to receive(:build_bundles).and_return([build_bundle])
allow(build6).to receive(:build_bundles).and_return([build_bundle])

allow(not_processed_build).to receive(:build_bundles).and_return([not_processed_build_bundle])
allow(no_symbols_build).to receive(:build_bundles).and_return([no_symbols_build_bundle])

allow(build_bundle).to receive(:dsym_url).and_return(download_url)
allow(build_bundle).to receive(:includes_symbols).and_return(true)

allow(not_processed_build_bundle).to receive(:dsym_url).and_return(nil)
allow(not_processed_build_bundle).to receive(:includes_symbols).and_return(true)

allow(empty_build).to receive(:build_bundles).and_return(nil)
allow(no_symbols_build_bundle).to receive(:dsym_url).and_return(nil)
allow(no_symbols_build_bundle).to receive(:includes_symbols).and_return(false)

allow(Fastlane::Actions::DownloadDsymsAction).to receive(:download)
end
Expand Down Expand Up @@ -88,7 +98,7 @@
[build5, '2.0.0', '2', '2020-09-12T14:00:00+01:00'],
[build6, '2.0.0', '5', '2020-09-12T15:00:00+01:00']].each do |build, version, build_number, uploaded_date|
expect(build).to receive(:app_version).and_return(version)
expect(build).to receive(:version).and_return(build_number).twice
expect(build).to receive(:version).and_return(build_number)
expect(build).to receive(:uploaded_date).and_return(uploaded_date)
expect(Fastlane::Actions::DownloadDsymsAction).to receive(:download).with(download_url, build, app, nil)
end
Expand All @@ -101,13 +111,41 @@
end
end

context 'with wait_for_dsym_processing' do
it 'downloads all dsyms of all builds in all trains' do
expect(build_resp).to receive(:to_models).and_return([not_processed_build])

# Returns not processed build (no dsym url)
build = not_processed_build
build_id = 1
version = '2.0.0'
build_number = '5'
uploaded_date = '2020-09-12T15:00:00+01:00'
expect(build).to receive(:id).and_return(build_id)
expect(build).to receive(:app_version).and_return(version)
expect(build).to receive(:version).and_return(build_number)
expect(build).to receive(:uploaded_date).and_return(uploaded_date)

# Refetches build info
expect(Spaceship::ConnectAPI::Build).to receive(:get).with(build_id: build_id).and_return(build1)

build = build1
expect(Fastlane::Actions::DownloadDsymsAction).to receive(:download).with(download_url, build, app, nil)
expect(Fastlane::Actions::DownloadDsymsAction).not_to(receive(:download))

Fastlane::FastFile.new.parse("lane :test do
download_dsyms(username: 'user@fastlane.tools', app_identifier: 'tools.fastlane.myapp', wait_for_dsym_processing: true)
end").runner.execute(:test)
end
end

context 'with version with leading zero' do
it 'downloads all dsyms of all builds in train 1.07.0' do
expect(build_resp).to receive(:all_pages_each).and_yield(build1)

[[build1, '1.07.0', '3', '2020-09-12T14:10:30+01:00']].each do |build, version, build_number, uploaded_date|
expect(build).to receive(:app_version).and_return(version)
expect(build).to receive(:version).and_return(build_number).twice
expect(build).to receive(:version).and_return(build_number)
expect(build).to receive(:uploaded_date).and_return(uploaded_date)
expect(Fastlane::Actions::DownloadDsymsAction).to receive(:download).with(download_url, build, app, nil)
end
Expand All @@ -124,7 +162,7 @@

[[build1, '2.0.0', '2', '2020-09-12T14:10:30+01:00']].each do |build, version, build_number, uploaded_date|
expect(build).to receive(:app_version).and_return(version)
expect(build).to receive(:version).and_return(build_number).twice
expect(build).to receive(:version).and_return(build_number)
expect(build).to receive(:uploaded_date).and_return(uploaded_date)
expect(Fastlane::Actions::DownloadDsymsAction).to receive(:download).with(download_url, build, app, nil)
end
Expand All @@ -150,7 +188,7 @@

[[build2, '2.0.0', '3', '2020-09-12T11:00:00+01:00']].each do |build, version, build_number, uploaded_date|
expect(build).to receive(:app_version).and_return(version).twice
expect(build).to receive(:version).and_return(build_number).exactly(3).times
expect(build).to receive(:version).and_return(build_number).exactly(2).times
expect(build).to receive(:uploaded_date).and_return(uploaded_date)

expect(Fastlane::Actions::DownloadDsymsAction).to receive(:download).with(download_url, build, app, nil)
Expand Down Expand Up @@ -181,7 +219,7 @@

[[build2, '1.0.0', '42', '2020-09-12T14:10:30+01:00']].each do |build, version, build_number, uploaded_date|
expect(build).to receive(:app_version).and_return(version)
expect(build).to receive(:version).and_return(build_number).twice
expect(build).to receive(:version).and_return(build_number)
expect(build).to receive(:uploaded_date).and_return(uploaded_date)

expect(Fastlane::Actions::DownloadDsymsAction).to receive(:download).with(download_url, build, app, nil)
Expand All @@ -206,7 +244,7 @@

[[build2, '2.0.0', '42', '2020-09-12T14:10:30+01:00']].each do |build, version, build_number, uploaded_date|
expect(build).to receive(:app_version).and_return(version)
expect(build).to receive(:version).and_return(build_number).twice
expect(build).to receive(:version).and_return(build_number)
expect(build).to receive(:uploaded_date).and_return(uploaded_date)

expect(Fastlane::Actions::DownloadDsymsAction).to receive(:download).with(download_url, build, app, nil)
Expand Down Expand Up @@ -239,7 +277,7 @@
[[build5, '2.0.0', '2', '2020-09-12T14:00:00+01:00'],
[build6, '2.0.0', '5', '2020-09-12T15:00:00+01:00']].each do |build, version, build_number, uploaded_date|
expect(build).to receive(:app_version).and_return(version)
expect(build).to receive(:version).and_return(build_number).twice
expect(build).to receive(:version).and_return(build_number)
expect(build).to receive(:uploaded_date).and_return(uploaded_date)
expect(Fastlane::Actions::DownloadDsymsAction).to receive(:download).with(download_url, build, app, nil)
end
Expand Down

0 comments on commit 2668eff

Please sign in to comment.