Skip to content

Commit

Permalink
Handle attachment upload error when submitting build for review
Browse files Browse the repository at this point in the history
  • Loading branch information
nid90 committed Dec 13, 2023
1 parent cd82662 commit 9285866
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/libs/deployments/app_store_connect/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Release
ExternalReleaseNotInTerminalState = Class.new(StandardError)
ReleaseNotFullyLive = Class.new(StandardError)

RETRYABLE_FAILURE_REASONS = [:attachment_upload_in_progress]

def self.kickoff!(deployment_run)
new(deployment_run).kickoff!
end
Expand Down Expand Up @@ -132,8 +134,8 @@ def submit_for_review!
result = provider.submit_release(build_number, release_version)

unless result.ok?
run.fail_with_error(result.error)
return
return run.update(failure_reason: result.error.reason) if result.error.reason.in? RETRYABLE_FAILURE_REASONS
return run.fail_with_error(result.error)
end

run.submit_for_review!
Expand Down
5 changes: 5 additions & 0 deletions app/libs/installations/apple/app_store_connect/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class Apple::AppStoreConnect::Error < Installations::Error
resource: "release",
code: "version_already_exists",
decorated_reason: :version_already_exists
},
{
resource: "release",
code: "attachment_upload_in_progress",
decorated_reason: :attachment_upload_in_progress
}
]

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ en:
build_not_submittable: "the build not being submittable"
build_mismatch: "the build not matching the release that exists in store"
review_in_progress: "a review already being in progress"
attachment_upload_in_progress: "store version is not in a valid state to submit for review, attachment uploads still in progress"
review_submission_exists: "a release already being added for review in the store"
phased_release_not_found: "the release not being phased release enabled"
release_already_exists: "a release already being present in the store"
Expand Down
11 changes: 11 additions & 0 deletions spec/libs/deployments/app_store_connect/release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,33 @@
context "when failure" do
let(:run) { create_deployment_run_for_ios(:started, deployment_traits: [:with_app_store, :with_production_channel], step_trait: :release) }
let(:error) { Installations::Apple::AppStoreConnect::Error.new({"error" => {"resource" => "build", "code" => "not_found"}}) }
let(:retryable_error) { Installations::Apple::AppStoreConnect::Error.new({"error" => {"resource" => "release", "code" => "attachment_upload_in_progress"}}) }

before do
allow(providable_dbl).to receive(:submit_release).and_return(GitHub::Result.new { raise error })
end

it "marks the deployment run as failed when failure" do
allow(providable_dbl).to receive(:submit_release).and_return(GitHub::Result.new { raise error })
described_class.submit_for_review!(run)

expect(run.reload.failed?).to be(true)
end

it "adds the reason of failure to deployment run" do
allow(providable_dbl).to receive(:submit_release).and_return(GitHub::Result.new { raise error })
described_class.submit_for_review!(run)

expect(run.reload.failure_reason).to eq("build_not_found")
end

it "does not mark the deployment run as failed when the failure is retryable" do
allow(providable_dbl).to receive(:submit_release).and_return(GitHub::Result.new { raise retryable_error })
described_class.submit_for_review!(run)

expect(run.reload.failed?).to be(false)
expect(run.reload.failure_reason).to eq("attachment_upload_in_progress")
end
end
end

Expand Down

0 comments on commit 9285866

Please sign in to comment.