diff --git a/lib/fastlane/plugin/ddg_apple_automation/actions/validate_internal_release_bump_action.rb b/lib/fastlane/plugin/ddg_apple_automation/actions/validate_internal_release_bump_action.rb index 36c4792..d458ab2 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/actions/validate_internal_release_bump_action.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/actions/validate_internal_release_bump_action.rb @@ -35,13 +35,18 @@ def self.run(params) def self.find_release_task_if_needed(params) if params[:release_task_url].to_s.empty? - params.merge!( - Fastlane::Actions::AsanaFindReleaseTaskAction.run( - asana_access_token: params[:asana_access_token], - github_token: params[:github_token], - platform: params[:platform] + begin + params.merge!( + Fastlane::Actions::AsanaFindReleaseTaskAction.run( + asana_access_token: params[:asana_access_token], + github_token: params[:github_token], + platform: params[:platform] + ) ) - ) + rescue FastlaneCore::Interface::FastlaneError + UI.important("Regular release task not found. If this is an automatic bump after merging a hotfix branch, this failure is expected. Rerun this workflow from an internal release branch, providing the release task URL explicitly.") + raise + end else params[:release_task_id] = Helper::AsanaHelper.extract_asana_task_id(params[:release_task_url], set_gha_output: false) other_action.ensure_git_branch(branch: "^release/.+$") diff --git a/lib/fastlane/plugin/ddg_apple_automation/version.rb b/lib/fastlane/plugin/ddg_apple_automation/version.rb index d69364b..034e9a6 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/version.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/version.rb @@ -1,5 +1,5 @@ module Fastlane module DdgAppleAutomation - VERSION = "3.1.1" + VERSION = "3.1.2" end end diff --git a/spec/validate_internal_release_bump_action_spec.rb b/spec/validate_internal_release_bump_action_spec.rb index 7116dfd..ba418a6 100644 --- a/spec/validate_internal_release_bump_action_spec.rb +++ b/spec/validate_internal_release_bump_action_spec.rb @@ -21,11 +21,6 @@ allow(Fastlane::Actions).to receive(:other_action).and_return(@other_action) allow(Fastlane::Actions::AsanaFindReleaseTaskAction).to receive(:find_latest_marketing_version) .and_return("1.0.0") - - allow(Fastlane::Actions::ValidateInternalReleaseBumpAction).to receive(:find_release_task_if_needed) do |params| - params[:release_branch] = "release_branch_name" - params[:release_task_id] = "mock_task_id" - end end end @@ -48,6 +43,13 @@ end include_context "common setup" + before do + allow(Fastlane::Actions::ValidateInternalReleaseBumpAction).to receive(:find_release_task_if_needed) do |params| + params[:release_branch] = "release_branch_name" + params[:release_task_id] = "mock_task_id" + end + end + context "when there are changes in the release branch" do it "proceeds with release bump if release notes are valid" do expect(Fastlane::UI).to receive(:message).with("Validating release notes") @@ -94,11 +96,17 @@ describe "#find_release_task_if_needed" do include_context "common setup" + subject { Fastlane::Actions::ValidateInternalReleaseBumpAction.find_release_task_if_needed(@params) } + context "when release_task_url is provided" do + before do + @params[:release_task_url] = "https://app.asana.com/0/1234567890/987654321" + end + it "sets release_task_id and release_branch from release_task_url" do allow(Fastlane::Actions::ValidateInternalReleaseBumpAction).to receive(:find_release_task_if_needed).and_call_original - @params[:release_task_url] = "https://app.asana.com/0/1234567890/987654321" - Fastlane::Actions::ValidateInternalReleaseBumpAction.find_release_task_if_needed(@params) + + subject expect(Fastlane::Helper::AsanaHelper).to have_received(:extract_asana_task_id).with(@params[:release_task_url], set_gha_output: false) expect(Fastlane::Actions.other_action).to have_received(:ensure_git_branch).with(branch: "^release/.+$") @@ -108,10 +116,14 @@ end context "when release_task_url is not provided" do + before do + @params[:release_task_url] = nil + end + it "runs AsanaFindReleaseTaskAction to find the release task" do - allow(Fastlane::Actions::ValidateInternalReleaseBumpAction).to receive(:find_release_task_if_needed).and_call_original allow(Fastlane::Actions::AsanaFindReleaseTaskAction).to receive(:run).and_return({ release_task_id: "1234567890", release_branch: "release_branch_name" }) - Fastlane::Actions::ValidateInternalReleaseBumpAction.find_release_task_if_needed(@params) + + subject expect(Fastlane::Actions::AsanaFindReleaseTaskAction).to have_received(:run).with( asana_access_token: "secret-token", @@ -121,6 +133,18 @@ expect(@params[:release_task_id]).to eq("1234567890") expect(@params[:release_branch]).to eq("release_branch_name") end + + context "when the release task is not found" do + before do + allow(Fastlane::Actions::AsanaFindReleaseTaskAction).to receive(:run).and_raise(FastlaneCore::Interface::FastlaneError.new) + allow(Fastlane::UI).to receive(:important) + end + + it "raises an error" do + expect { subject }.to raise_error(FastlaneCore::Interface::FastlaneError) + expect(Fastlane::UI).to have_received(:important).with("Regular release task not found. If this is an automatic bump after merging a hotfix branch, this failure is expected. Rerun this workflow from an internal release branch, providing the release task URL explicitly.") + end + end end end