Skip to content

Commit 8332e6d

Browse files
committed
Add tests
1 parent dddcf9e commit 8332e6d

5 files changed

Lines changed: 170 additions & 5 deletions

File tree

lib/fastlane/plugin/ddg_apple_automation/actions/start_new_release_action.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def self.run(params)
2121
params[:github_token], params[:platform], other_action, options
2222
)
2323
else
24-
release_branch_name, new_version = Helper::DdgAppleAutomationHelper.prepare_release_branch(
24+
release_branch_name, new_version, update_embedded_warning = Helper::DdgAppleAutomationHelper.prepare_release_branch(
2525
params[:platform], params[:version], other_action
2626
)
2727
end
@@ -33,6 +33,10 @@ def self.run(params)
3333
options[:release_task_id] = release_task_id
3434

3535
Helper::AsanaHelper.update_asana_tasks_for_internal_release(options) unless params[:is_hotfix]
36+
Fastlane::Actions::AsanaAddCommentAction.run(
37+
task_id: release_task_id,
38+
comment: "TDS performance tests failed. Make sure to validate performance before releasing to public users."
39+
) if update_embedded_warning
3640
end
3741

3842
def self.description

lib/fastlane/plugin/ddg_apple_automation/helper/ddg_apple_automation_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def self.prepare_release_branch(platform, version, other_action)
127127
code_freeze_prechecks(other_action) unless Helper.is_ci?
128128
new_version = validate_new_version(version)
129129
create_release_branch(platform, new_version)
130-
update_embedded_files(platform, other_action)
130+
update_embedded_result = update_embedded_files(platform, other_action)
131131
if platform == "ios"
132132
# Any time we prepare a release branch for iOS the the build number should be reset to 0
133133
update_version_and_build_number_config(new_version, 0, other_action)
@@ -139,7 +139,7 @@ def self.prepare_release_branch(platform, version, other_action)
139139
release_branch_name = release_branch_name(platform, new_version)
140140
Helper::GitHubActionsHelper.set_output("release_branch_name", release_branch_name)
141141

142-
return release_branch_name, new_version
142+
return release_branch_name, new_version, update_embedded_result
143143
end
144144

145145
def self.prepare_hotfix_branch(github_token, platform, other_action, options)

lib/fastlane/plugin/ddg_apple_automation/helper/embedded_files_helper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class EmbeddedFilesHelper
2727
}.freeze
2828

2929
def self.update_embedded_files(platform, other_action)
30-
other_action.tds_perf_test
30+
perf_test_warning = !other_action.tds_perf_test
3131
Actions.sh("./scripts/update_embedded.sh")
3232

3333
# Verify no unexpected files were modified
@@ -50,14 +50,19 @@ def self.update_embedded_files(platform, other_action)
5050
Actions.sh('git', 'commit', '-m', 'Update embedded files')
5151
other_action.ensure_git_status_clean
5252
end
53+
54+
perf_test_warning
5355
end
5456

5557
def pre_update_embedded_tests
5658
tds_perf_test_result = other_action.tds_perf_test
5759

5860
unless tds_perf_test_result
59-
UI.important("TDS performance tests failed. Proceeding with caution.")
61+
UI.important("TDS performance tests failed. Make sure to validate performance before releasing to public users.")
62+
return false
6063
end
64+
65+
return true
6166
end
6267
end
6368
end

spec/ddg_apple_automation_helper_spec.rb

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,54 @@ def load_file(file)
188188
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("release_branch_name", release_branch_name)
189189
end
190190

191+
it "prepares the release branch with version updates for macOS and returns update_embedded_warning" do
192+
platform = "macos"
193+
version = "1.0.0"
194+
release_branch_name = "release/#{platform}/#{version}"
195+
other_action = double("other_action")
196+
options = { some_option: "value" }
197+
github_token = "github-token"
198+
update_embedded_warning = true
199+
200+
@client = double("Octokit::Client")
201+
allow(Octokit::Client).to receive(:new).and_return(@client)
202+
allow(@client).to receive(:latest_release).and_return(double(tag_name: version))
203+
allow(Fastlane::Helper).to receive(:is_ci?).and_return(false)
204+
allow(Fastlane::Helper::GitHelper).to receive(:repo_name).and_return("macOS")
205+
206+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:code_freeze_prechecks)
207+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:validate_new_version)
208+
.with(version).and_return(version)
209+
210+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:create_release_branch)
211+
.with(platform, version).and_return(release_branch_name)
212+
213+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:update_embedded_files)
214+
.with(platform, other_action).and_return(update_embedded_warning)
215+
216+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:update_version_config)
217+
.with(version, other_action)
218+
219+
allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output)
220+
221+
expect(other_action).to receive(:push_to_git_remote)
222+
223+
result_branch, result_version, result_warning = Fastlane::Helper::DdgAppleAutomationHelper.prepare_release_branch(
224+
platform, version, other_action
225+
)
226+
227+
expect(result_branch).to eq(release_branch_name)
228+
expect(result_version).to eq(version)
229+
expect(result_warning).to eq(update_embedded_warning)
230+
231+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:code_freeze_prechecks)
232+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:validate_new_version).with(version)
233+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:create_release_branch).with(platform, version)
234+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:update_embedded_files).with(platform, other_action)
235+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:update_version_config).with(version, other_action)
236+
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("release_branch_name", release_branch_name)
237+
end
238+
191239
it "prepares the release branch with version updates for iOS" do
192240
platform = "ios"
193241
version = "1.0.0"
@@ -237,6 +285,58 @@ def load_file(file)
237285
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:update_root_plist_version).with(version, other_action)
238286
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("release_branch_name", release_branch_name)
239287
end
288+
289+
it "prepares the release branch with version updates for iOS and returns update_embedded_warning" do
290+
platform = "ios"
291+
version = "1.0.0"
292+
release_branch_name = "release/#{platform}/#{version}"
293+
other_action = double("other_action")
294+
options = { some_option: "value" }
295+
github_token = "github-token"
296+
update_embedded_warning = true
297+
298+
@client = double("Octokit::Client")
299+
allow(Octokit::Client).to receive(:new).and_return(@client)
300+
allow(@client).to receive(:latest_release).and_return(double(tag_name: version))
301+
allow(Fastlane::Helper).to receive(:is_ci?).and_return(false)
302+
allow(Fastlane::Helper::GitHelper).to receive(:repo_name).and_return("iOS")
303+
304+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:code_freeze_prechecks)
305+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:validate_new_version)
306+
.with(version).and_return(version)
307+
308+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:create_release_branch)
309+
.with(platform, version).and_return(release_branch_name)
310+
311+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:update_embedded_files)
312+
.with(platform, other_action).and_return(update_embedded_warning)
313+
314+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:update_version_and_build_number_config)
315+
.with(version, 0, other_action)
316+
317+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:update_root_plist_version)
318+
.with(version, other_action)
319+
320+
allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output)
321+
322+
expect(other_action).to receive(:push_to_git_remote)
323+
324+
result_branch, result_version, result_warning = Fastlane::Helper::DdgAppleAutomationHelper.prepare_release_branch(
325+
platform, version, other_action
326+
)
327+
328+
expect(result_branch).to eq("release/ios/1.0.0")
329+
expect(result_version).to eq(version)
330+
expect(result_warning).to eq(update_embedded_warning)
331+
332+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:code_freeze_prechecks)
333+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:validate_new_version).with(version)
334+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:create_release_branch).with(platform, version)
335+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:update_embedded_files).with(platform, other_action)
336+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:update_version_and_build_number_config).with(version, 0, other_action)
337+
expect(Fastlane::Helper::DdgAppleAutomationHelper).to have_received(:update_root_plist_version).with(version, other_action)
338+
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("release_branch_name", release_branch_name)
339+
end
240340
end
241341

242342
describe "#create_hotfix_branch" do
@@ -417,6 +517,40 @@ def load_file(file)
417517
expect(Fastlane::Actions).to have_received(:sh).with("git", "add", "Core/trackerData.json")
418518
expect(Fastlane::Actions).to have_received(:sh).with("git", "commit", "-m", "Update embedded files")
419519
end
520+
521+
it "returns true when TDS performance tests fail" do
522+
allow(Fastlane::Actions).to receive(:sh).with("./scripts/update_embedded.sh").and_return("")
523+
git_status_output = "On branch main\nmodified: Core/trackerData.json\n"
524+
allow(Fastlane::Actions).to receive(:sh).with("git", "status").and_return(git_status_output)
525+
allow(Fastlane::Actions).to receive(:sh).with("git", "add", "Core/trackerData.json").and_return("")
526+
allow(Fastlane::Actions).to receive(:sh).with("git", "commit", "-m", "Update embedded files").and_return("")
527+
allow(other_action).to receive(:tds_perf_test).and_return(false)
528+
allow(other_action).to receive(:ensure_git_status_clean)
529+
530+
result = described_class.update_embedded_files(platform, other_action)
531+
532+
expect(result).to eq(true)
533+
expect(Fastlane::Actions).to have_received(:sh).with("git", "status")
534+
expect(Fastlane::Actions).to have_received(:sh).with("git", "add", "Core/trackerData.json")
535+
expect(Fastlane::Actions).to have_received(:sh).with("git", "commit", "-m", "Update embedded files")
536+
end
537+
538+
it "returns false when TDS performance tests pass" do
539+
allow(Fastlane::Actions).to receive(:sh).with("./scripts/update_embedded.sh").and_return("")
540+
git_status_output = "On branch main\nmodified: Core/trackerData.json\n"
541+
allow(Fastlane::Actions).to receive(:sh).with("git", "status").and_return(git_status_output)
542+
allow(Fastlane::Actions).to receive(:sh).with("git", "add", "Core/trackerData.json").and_return("")
543+
allow(Fastlane::Actions).to receive(:sh).with("git", "commit", "-m", "Update embedded files").and_return("")
544+
allow(other_action).to receive(:tds_perf_test).and_return(true)
545+
allow(other_action).to receive(:ensure_git_status_clean)
546+
547+
result = described_class.update_embedded_files(platform, other_action)
548+
549+
expect(result).to eq(false)
550+
expect(Fastlane::Actions).to have_received(:sh).with("git", "status")
551+
expect(Fastlane::Actions).to have_received(:sh).with("git", "add", "Core/trackerData.json")
552+
expect(Fastlane::Actions).to have_received(:sh).with("git", "commit", "-m", "Update embedded files")
553+
end
420554
end
421555

422556
describe "#increment_build_number" do

spec/start_new_release_action_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,28 @@
7979
)
8080
)
8181
end
82+
83+
it 'doesn\'t warn on TDS performance tests success' do
84+
subject
85+
expect(Fastlane::Actions::AsanaAddCommentAction).not_to receive(:run)
86+
end
87+
88+
context "on TDS performance tests failure" do
89+
before do
90+
allow(Fastlane::Helper::DdgAppleAutomationHelper).to receive(:prepare_release_branch).and_return(["release_branch_name", "1.1.0", true])
91+
allow(Fastlane::Actions::AsanaAddCommentAction).to receive(:run)
92+
end
93+
it 'warns about TDS performance tests failures' do
94+
95+
subject
96+
expect(Fastlane::Actions::AsanaAddCommentAction).to have_received(:run).with(
97+
hash_including(
98+
task_id: "1234567890",
99+
comment: include("TDS performance tests failed")
100+
)
101+
)
102+
end
103+
end
82104
end
83105

84106
context "on macos" do

0 commit comments

Comments
 (0)