From 879513d54deefe3306a7ea9b157b91e4dd2dddec Mon Sep 17 00:00:00 2001 From: Kieran Date: Sun, 24 Nov 2024 02:46:29 +1100 Subject: [PATCH] PR feedback --- .../actions/start_new_release_action.rb | 10 +- .../plugin/ddg_apple_automation/version.rb | 2 +- spec/ddg_apple_automation_helper_spec.rb | 94 ++++++------------- spec/start_new_release_action_spec.rb | 2 +- 4 files changed, 38 insertions(+), 70 deletions(-) diff --git a/lib/fastlane/plugin/ddg_apple_automation/actions/start_new_release_action.rb b/lib/fastlane/plugin/ddg_apple_automation/actions/start_new_release_action.rb index f6eaffa..acb1f62 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/actions/start_new_release_action.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/actions/start_new_release_action.rb @@ -26,13 +26,13 @@ def self.run(params) ) end - # options[:version] = new_version - # options[:release_branch_name] = release_branch_name + options[:version] = new_version + options[:release_branch_name] = release_branch_name - # release_task_id = Helper::AsanaHelper.create_release_task(options[:platform], options[:version], options[:asana_user_id], options[:asana_access_token], is_hotfix: options[:is_hotfix]) - # options[:release_task_id] = release_task_id + release_task_id = Helper::AsanaHelper.create_release_task(options[:platform], options[:version], options[:asana_user_id], options[:asana_access_token], is_hotfix: options[:is_hotfix]) + options[:release_task_id] = release_task_id - # Helper::AsanaHelper.update_asana_tasks_for_internal_release(options) unless params[:is_hotfix] + Helper::AsanaHelper.update_asana_tasks_for_internal_release(options) unless params[:is_hotfix] end def self.description diff --git a/lib/fastlane/plugin/ddg_apple_automation/version.rb b/lib/fastlane/plugin/ddg_apple_automation/version.rb index 1bfdfec..f999a04 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 = "0.12.1" + VERSION = "0.12.0" end end diff --git a/spec/ddg_apple_automation_helper_spec.rb b/spec/ddg_apple_automation_helper_spec.rb index dd90447..979d005 100644 --- a/spec/ddg_apple_automation_helper_spec.rb +++ b/spec/ddg_apple_automation_helper_spec.rb @@ -64,7 +64,7 @@ def load_file(file) end end - describe ".code_freeze_prechecks" do + describe "#code_freeze_prechecks" do it "performs git and submodule checks" do expect(other_action).to receive(:ensure_git_status_clean).twice expect(other_action).to receive(:ensure_git_branch).with(branch: Fastlane::Helper::DdgAppleAutomationHelper::DEFAULT_BRANCH) @@ -74,7 +74,7 @@ def load_file(file) end end - describe ".validate_new_version" do + describe "#validate_new_version" do it "validates and returns the new version" do allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:current_version).and_return(version) expect(Fastlane::UI).to receive(:important).with("Current version in project settings is #{version}.") @@ -85,39 +85,39 @@ def load_file(file) end end - describe ".format_version" do + describe "#format_version" do it "formats a version string" do expect(Fastlane::Helper::DdgAppleAutomationHelper.format_version("1.2.3.4")).to eq("1.2.3") end end - describe ".bump_minor_version" do + describe "#bump_minor_version" do it "increments the minor version" do expect(Fastlane::Helper::DdgAppleAutomationHelper.bump_minor_version("1.2.0")).to eq("1.3.0") end end - describe ".bump_patch_version" do + describe "#bump_patch_version" do it "increments the patch version" do expect(Fastlane::Helper::DdgAppleAutomationHelper.bump_patch_version("1.2.3")).to eq("1.2.4") end end - describe ".current_build_number" do + describe "#current_build_number" do it "reads the current build number from config" do allow(File).to receive(:read).and_return("CURRENT_PROJECT_VERSION = 123") expect(Fastlane::Helper::DdgAppleAutomationHelper.current_build_number).to eq(123) end end - describe ".current_version" do + describe "#current_version" do it "reads the current version from config" do allow(File).to receive(:read).and_return("MARKETING_VERSION = 1.2.3") expect(Fastlane::Helper::DdgAppleAutomationHelper.current_version).to eq("1.2.3") end end - describe ".prepare_release_branch" do + describe "#prepare_release_branch" do it "prepares the release branch with version updates" do allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:code_freeze_prechecks) allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:validate_new_version).and_return(version) @@ -131,7 +131,7 @@ def load_file(file) end end - describe ".create_hotfix_branch" do + describe "#create_hotfix_branch" do it "creates a new hotfix branch and checks out the branch" do branch_name = "hotfix/1.0.1" source_version = "1.0.0" @@ -157,47 +157,9 @@ def load_file(file) Fastlane::Helper::DdgAppleAutomationHelper.create_hotfix_branch(platform, source_version, new_version) end.to raise_error(FastlaneCore::Interface::FastlaneCommonException, "Branch hotfix/1.0.1 already exists in this repository. Aborting.") end - - describe ".create_hotfix_branch" do - it "creates a new hotfix branch in CI mode" do - source_version = "1.0.0" - new_version = "1.0.1" - branch_name = "hotfix/#{new_version}" - sha = "abc123" - repo = "duckduckgo/macos-browser" - platform = "macos" - allow(Fastlane::Helper).to receive(:is_ci?).and_return(true) - allow(Fastlane::Actions).to receive(:sh).with("git", "branch", "--list", branch_name).and_return("") - allow(Fastlane::Actions).to receive(:sh).with("git", "rev-parse", "#{source_version}^{}").and_return(sha) - allow(Fastlane::Actions).to receive(:sh).with( - "gh", "api", "--method", "POST", - "/repos/#{repo}/git/refs", - "-f", "ref=refs/heads/#{branch_name}", - "-f", "sha=#{sha}" - ) - allow(Fastlane::Actions).to receive(:sh).with("git", "fetch", "origin") - allow(Fastlane::Actions).to receive(:sh).with("git", "checkout", branch_name) - allow(Fastlane::Actions).to receive(:sh).with("bundle", "install") - - result = Fastlane::Helper::DdgAppleAutomationHelper.create_hotfix_branch(platform, source_version, new_version) - - expect(result).to eq(branch_name) - - expect(Fastlane::Actions).to have_received(:sh).with("git", "branch", "--list", branch_name) - expect(Fastlane::Actions).to have_received(:sh).with("git", "rev-parse", "#{source_version}^{}") - expect(Fastlane::Actions).to have_received(:sh).with( - "gh", "api", "--method", "POST", - "/repos/#{repo}/git/refs", - "-f", "ref=refs/heads/#{branch_name}", - "-f", "sha=#{sha}" - ) - expect(Fastlane::Actions).to have_received(:sh).with("git", "fetch", "origin") - expect(Fastlane::Actions).to have_received(:sh).with("git", "checkout", branch_name) - end - end end - describe ".validate_hotfix_version" do + describe "#validate_hotfix_version" do it "validates and bumps the patch version" do source_version = "1.0.0" new_version = "1.0.1" @@ -210,7 +172,7 @@ def load_file(file) end end - describe ".validate_version_exists" do + describe "#validate_version_exists" do it "validates that the provided version exists as a git tag" do version = "1.0.0" formatted_version = "1.0.0" @@ -223,15 +185,21 @@ def load_file(file) end end - describe ".prepare_hotfix_branch" do + describe "#prepare_hotfix_branch" do it "prepares the hotfix branch" do - platform = "ios" + platform = "macos" version = "1.0.0" source_version = "1.0.0" new_version = "1.0.1" release_branch_name = "hotfix/1.0.1" other_action = double("other_action") options = { some_option: "value" } + github_token = "github-token" + + @client = double("Octokit::Client") + allow(Octokit::Client).to receive(:new).and_return(@client) + allow(@client).to receive(:latest_release).and_return(double(tag_name: source_version)) + allow(Fastlane::Helper::GitHelper).to receive(:repo_name).and_return("macOS") allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:validate_version_exists) .with(version).and_return(source_version) @@ -246,10 +214,9 @@ def load_file(file) .with(platform, options, other_action) allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output) - .with("release_branch_name", release_branch_name) result_branch, result_version = Fastlane::Helper::DdgAppleAutomationHelper.prepare_hotfix_branch( - platform, version, other_action, options + github_token, platform, other_action, options ) expect(result_branch).to eq(release_branch_name) @@ -259,11 +226,12 @@ def load_file(file) expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:validate_hotfix_version).with(source_version) expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:create_hotfix_branch).with(platform, source_version, new_version) expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:increment_build_number).with(platform, options, other_action) + expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("last_release", source_version) expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("release_branch_name", release_branch_name) end end - describe ".create_release_branch" do + describe "#create_release_branch" do it "creates a new release branch" do allow(Fastlane::Actions).to receive(:sh).and_return("") Fastlane::Helper::DdgAppleAutomationHelper.create_release_branch(version) @@ -273,7 +241,7 @@ def load_file(file) end end - describe ".update_embedded_files" do + describe "#update_embedded_files" do it "updates embedded files and commits them" do allow(Fastlane::Actions).to receive(:sh).with("./scripts/update_embedded.sh").and_return("") git_status_output = "On branch main\nmodified: Core/trackerData.json\n" @@ -288,7 +256,7 @@ def load_file(file) end end - describe ".increment_build_number" do + describe "#increment_build_number" do it "increments the build number" do allow(File).to receive(:read).with("Configuration/Version.xcconfig").and_return("MARKETING_VERSION = 1.0.0\n") allow(File).to receive(:read).with("Configuration/BuildNumber.xcconfig").and_return("CURRENT_PROJECT_VERSION = 123\n") @@ -303,7 +271,7 @@ def load_file(file) end end - describe ".calculate_next_build_number" do + describe "#calculate_next_build_number" do it "calculates the next build number" do allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:fetch_testflight_build_number).and_return(123) allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:current_build_number).and_return(124) @@ -312,7 +280,7 @@ def load_file(file) end end - describe ".fetch_appcast_build_number" do + describe "#fetch_appcast_build_number" do it "fetches the highest appcast build number for macOS" do allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:`).with("plutil -extract SUFeedURL raw #{Fastlane::Helper::DdgAppleAutomationHelper::INFO_PLIST}").and_return("https://dummy-url.com/feed.xml\n") allow(HTTParty).to receive(:get).with("https://dummy-url.com/feed.xml").and_return( @@ -332,14 +300,14 @@ def load_file(file) end end - describe ".fetch_testflight_build_number" do + describe "#fetch_testflight_build_number" do it "fetches the latest testflight build number" do expect(other_action).to receive(:latest_testflight_build_number).and_return(125) expect(Fastlane::Helper::DdgAppleAutomationHelper.fetch_testflight_build_number(platform, options, other_action)).to eq(125) end end - describe ".get_api_key" do + describe "#get_api_key" do it "returns the API key if available in environment" do ENV["APPLE_API_KEY_ID"] = "key_id" ENV["APPLE_API_KEY_ISSUER"] = "issuer_id" @@ -351,7 +319,7 @@ def load_file(file) end end - describe ".get_username" do + describe "#get_username" do before do @original_ci_value = Fastlane::Helper.is_ci? allow(Fastlane::Helper).to receive(:is_ci?).and_return(false) @@ -366,7 +334,7 @@ def load_file(file) end end - describe ".update_version_config" do + describe "#update_version_config" do it "updates the version in the config file" do expect(File).to receive(:write).with( Fastlane::Helper::DdgAppleAutomationHelper::VERSION_CONFIG_PATH, @@ -382,7 +350,7 @@ def load_file(file) end end - describe ".update_version_and_build_number_config" do + describe "#update_version_and_build_number_config" do it "updates both version and build number in config files" do expect(File).to receive(:write).with(Fastlane::Helper::DdgAppleAutomationHelper::VERSION_CONFIG_PATH, "#{Fastlane::Helper::DdgAppleAutomationHelper::VERSION_CONFIG_DEFINITION} = #{version}\n") expect(File).to receive(:write).with(Fastlane::Helper::DdgAppleAutomationHelper::BUILD_NUMBER_CONFIG_PATH, "#{Fastlane::Helper::DdgAppleAutomationHelper::BUILD_NUMBER_CONFIG_DEFINITION} = 123\n") diff --git a/spec/start_new_release_action_spec.rb b/spec/start_new_release_action_spec.rb index 22c64ff..2aecd80 100644 --- a/spec/start_new_release_action_spec.rb +++ b/spec/start_new_release_action_spec.rb @@ -141,7 +141,7 @@ it "prepares the hotfix branch" do subject expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:prepare_hotfix_branch) - .with("macos", "1.0.0", anything, hash_including(asana_user_id: "user")) + .with("github_token", "macos", anything, hash_including(asana_user_id: "user")) end it "creates a hotfix release task in Asana" do