Skip to content

Commit 50a96ea

Browse files
authored
Add tds perf testing (#38)
1 parent 7e3719e commit 50a96ea

8 files changed

Lines changed: 525 additions & 41 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "fastlane/action"
22
require "fastlane_core/configuration/config_item"
33
require "octokit"
4+
require_relative "asana_add_comment_action"
45
require_relative "../helper/asana_helper"
56
require_relative "../helper/ddg_apple_automation_helper"
67
require_relative "../helper/git_helper"
@@ -21,7 +22,7 @@ def self.run(params)
2122
params[:github_token], params[:platform], other_action, options
2223
)
2324
else
24-
release_branch_name, new_version = Helper::DdgAppleAutomationHelper.prepare_release_branch(
25+
release_branch_name, new_version, show_update_embedded_warning = Helper::DdgAppleAutomationHelper.prepare_release_branch(
2526
params[:platform], params[:version], other_action
2627
)
2728
end
@@ -33,6 +34,12 @@ def self.run(params)
3334
options[:release_task_id] = release_task_id
3435

3536
Helper::AsanaHelper.update_asana_tasks_for_internal_release(options) unless params[:is_hotfix]
37+
if show_update_embedded_warning
38+
AsanaAddCommentAction.run(
39+
task_id: release_task_id,
40+
comment: "TDS performance tests failed. Make sure to validate performance before releasing to public users. See https://app.asana.com/0/1204165176092271/1209729184622270/f"
41+
)
42+
end
3643
end
3744

3845
def self.description
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
require "fastlane/action"
2+
require "fastlane_core/configuration/config_item"
3+
require "octokit"
4+
require "tmpdir"
5+
require "fileutils"
6+
require_relative "../helper/asana_helper"
7+
require_relative "../helper/ddg_apple_automation_helper"
8+
require_relative "../helper/git_helper"
9+
10+
module Fastlane
11+
module Actions
12+
class TdsPerfTestAction < Action
13+
# Define platform-specific constants
14+
IOS_TEST_PARAMS = {
15+
ut_file_name: "ios-tds.json",
16+
ut_url: "https://staticcdn.duckduckgo.com/trackerblocking/v5/current/",
17+
ref_file_name: "trackerData.json",
18+
ref_url: "https://raw.githubusercontent.com/duckduckgo/apple-browsers/refs/heads/main/iOS/Core/"
19+
}.freeze
20+
21+
MAC_TEST_PARAMS = {
22+
ut_file_name: "macos-tds.json",
23+
ut_url: "https://staticcdn.duckduckgo.com/trackerblocking/v6/current/",
24+
ref_file_name: "trackerData.json",
25+
ref_url: "https://raw.githubusercontent.com/duckduckgo/apple-browsers/refs/heads/main/macOS/DuckDuckGo/ContentBlocker/"
26+
}.freeze
27+
28+
def self.run(params)
29+
UI.message("Starting TDS Performance Testing...")
30+
31+
# Determine platform and set default parameters if needed
32+
platform = lane_context[SharedValues::PLATFORM_NAME]
33+
default_params = platform == :ios ? IOS_TEST_PARAMS : MAC_TEST_PARAMS
34+
35+
# Use provided parameters or defaults
36+
ut_file_name = params[:ut_file_name] || default_params[:ut_file_name]
37+
ut_url = params[:ut_url] || default_params[:ut_url]
38+
ref_file_name = params[:ref_file_name] || default_params[:ref_file_name]
39+
ref_url = params[:ref_url] || default_params[:ref_url]
40+
41+
UI.message("Using TDS parameters for #{platform} platform:")
42+
UI.message(" Under-test file: #{ut_file_name}")
43+
UI.message(" Under-test URL: #{ut_url}")
44+
UI.message(" Reference file: #{ref_file_name}")
45+
UI.message(" Reference URL: #{ref_url}")
46+
47+
# Create temporary directory
48+
tmp_dir = File.join(Dir.tmpdir, "tds-perf-testing")
49+
50+
begin
51+
FileUtils.mkdir_p(tmp_dir)
52+
53+
# Navigate to temp directory
54+
Dir.chdir(tmp_dir) do
55+
# Clone repository
56+
Actions.sh("git clone --depth=1 git@github.com:duckduckgo/TrackerRadarKit.git")
57+
58+
# Navigate to cloned repository
59+
Dir.chdir("TrackerRadarKit") do
60+
# Build for testing
61+
begin
62+
Actions.sh("xcodebuild build-for-testing -scheme TrackerRadarKit -destination 'platform=macOS'")
63+
rescue StandardError => e
64+
UI.error("Failed to build for testing: #{e}")
65+
false
66+
end
67+
68+
# Set environment variables and run test
69+
test_command = [
70+
"env",
71+
"TEST_RUNNER_TDS_UT_FILE_NAME=#{ut_file_name}",
72+
"TEST_RUNNER_TDS_UT_URL=#{ut_url}",
73+
"TEST_RUNNER_TDS_REF_FILE_NAME=#{ref_file_name}",
74+
"TEST_RUNNER_TDS_REF_URL=#{ref_url}",
75+
"xcodebuild test-without-building",
76+
"-scheme TrackerRadarKit",
77+
"-destination 'platform=macOS'",
78+
"-only-testing:TrackerRadarKitPerformanceTests/NextTrackerDataSetPerformanceTests"
79+
].join(" ")
80+
81+
begin
82+
Actions.sh(test_command)
83+
true
84+
rescue StandardError => e
85+
UI.error("Performance tests failed: #{e}")
86+
false
87+
end
88+
end
89+
end
90+
ensure
91+
# Cleanup step - always executed regardless of success or failure
92+
UI.message("Cleaning up temporary test directory...")
93+
FileUtils.rm_rf(tmp_dir)
94+
end
95+
end
96+
97+
def self.description
98+
"Runs performance tests for Tracker Radar Kit with specified TDS files"
99+
end
100+
101+
def self.authors
102+
["DuckDuckGo"]
103+
end
104+
105+
def self.available_options
106+
[
107+
FastlaneCore::ConfigItem.new(
108+
key: :ut_file_name,
109+
env_name: "TEST_RUNNER_TDS_UT_FILE_NAME",
110+
description: "The file name for the under-test TDS",
111+
type: String,
112+
optional: true
113+
),
114+
FastlaneCore::ConfigItem.new(
115+
key: :ut_url,
116+
env_name: "TEST_RUNNER_TDS_UT_URL",
117+
description: "The URL for the under-test TDS",
118+
type: String,
119+
optional: true
120+
),
121+
FastlaneCore::ConfigItem.new(
122+
key: :ref_file_name,
123+
env_name: "TEST_RUNNER_TDS_REF_FILE_NAME",
124+
description: "The file name for the reference TDS",
125+
type: String,
126+
optional: true
127+
),
128+
FastlaneCore::ConfigItem.new(
129+
key: :ref_url,
130+
env_name: "TEST_RUNNER_TDS_REF_URL",
131+
description: "The URL for the reference TDS",
132+
type: String,
133+
optional: true
134+
)
135+
]
136+
end
137+
138+
def self.is_supported?(platform)
139+
[:ios, :mac].include?(platform)
140+
end
141+
142+
def self.return_value
143+
"Returns true if tests passed, false otherwise"
144+
end
145+
end
146+
end
147+
end

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

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require "semantic"
66
require_relative "github_actions_helper"
77
require_relative "git_helper"
8+
require_relative "embedded_files_helper"
89

910
module Fastlane
1011
UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
@@ -22,21 +23,6 @@ class DdgAppleAutomationHelper
2223
VERSION_CONFIG_DEFINITION = 'MARKETING_VERSION'
2324
BUILD_NUMBER_CONFIG_DEFINITION = 'CURRENT_PROJECT_VERSION'
2425

25-
UPGRADABLE_EMBEDDED_FILES = {
26-
"ios" => Set.new([
27-
'Core/AppPrivacyConfigurationDataProvider.swift',
28-
'Core/AppTrackerDataSetProvider.swift',
29-
'Core/ios-config.json',
30-
'Core/trackerData.json'
31-
]),
32-
"macos" => Set.new([
33-
'DuckDuckGo/ContentBlocker/AppPrivacyConfigurationDataProvider.swift',
34-
'DuckDuckGo/ContentBlocker/AppTrackerDataSetProvider.swift',
35-
'DuckDuckGo/ContentBlocker/trackerData.json',
36-
'DuckDuckGo/ContentBlocker/macos-config.json'
37-
])
38-
}.freeze
39-
4026
def self.release_branch_name(platform, version)
4127
"#{RELEASE_BRANCH}/#{platform}/#{version}"
4228
end
@@ -141,7 +127,7 @@ def self.prepare_release_branch(platform, version, other_action)
141127
code_freeze_prechecks(other_action) unless Helper.is_ci?
142128
new_version = validate_new_version(version)
143129
create_release_branch(platform, new_version)
144-
update_embedded_files(platform, other_action)
130+
update_embedded_result = update_embedded_files(platform, other_action)
145131
if platform == "ios"
146132
# Any time we prepare a release branch for iOS the the build number should be reset to 0
147133
update_version_and_build_number_config(new_version, 0, other_action)
@@ -153,7 +139,7 @@ def self.prepare_release_branch(platform, version, other_action)
153139
release_branch_name = release_branch_name(platform, new_version)
154140
Helper::GitHubActionsHelper.set_output("release_branch_name", release_branch_name)
155141

156-
return release_branch_name, new_version
142+
return release_branch_name, new_version, update_embedded_result
157143
end
158144

159145
def self.prepare_hotfix_branch(github_token, platform, other_action, options)
@@ -227,28 +213,7 @@ def self.create_release_branch(platform, version)
227213
end
228214

229215
def self.update_embedded_files(platform, other_action)
230-
Actions.sh("./scripts/update_embedded.sh")
231-
232-
# Verify no unexpected files were modified
233-
git_status = Actions.sh('git', 'status')
234-
modified_files = git_status.split("\n").select { |line| line.include?('modified:') }
235-
modified_files = modified_files.map { |str| str.split(':')[1].strip.delete_prefix('../') }
236-
237-
modified_files.each do |modified_file|
238-
UI.abort_with_message!("Unexpected change to #{modified_file}.") unless UPGRADABLE_EMBEDDED_FILES[platform].any? do |s|
239-
s.include?(modified_file)
240-
end
241-
end
242-
243-
# Run tests (CI will run them separately)
244-
# run_tests(scheme: 'DuckDuckGo Privacy Browser') unless Helper.is_ci?
245-
246-
# Everything looks good: commit and push
247-
unless modified_files.empty?
248-
modified_files.each { |modified_file| Actions.sh('git', 'add', modified_file.to_s) }
249-
Actions.sh('git', 'commit', '-m', 'Update embedded files')
250-
other_action.ensure_git_status_clean
251-
end
216+
Helper::EmbeddedFilesHelper.update_embedded_files(platform, other_action)
252217
end
253218

254219
def self.increment_build_number(platform, options, other_action)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require "fastlane_core/configuration/config_item"
2+
require "fastlane_core/ui/ui"
3+
require "httparty"
4+
require "rexml/document"
5+
require "semantic"
6+
require_relative "github_actions_helper"
7+
require_relative "git_helper"
8+
9+
module Fastlane
10+
UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
11+
12+
module Helper
13+
class EmbeddedFilesHelper
14+
UPGRADABLE_EMBEDDED_FILES = {
15+
"ios" => Set.new([
16+
'Core/AppPrivacyConfigurationDataProvider.swift',
17+
'Core/AppTrackerDataSetProvider.swift',
18+
'Core/ios-config.json',
19+
'Core/trackerData.json'
20+
]),
21+
"macos" => Set.new([
22+
'DuckDuckGo/ContentBlocker/AppPrivacyConfigurationDataProvider.swift',
23+
'DuckDuckGo/ContentBlocker/AppTrackerDataSetProvider.swift',
24+
'DuckDuckGo/ContentBlocker/trackerData.json',
25+
'DuckDuckGo/ContentBlocker/macos-config.json'
26+
])
27+
}.freeze
28+
29+
def self.update_embedded_files(platform, other_action)
30+
perf_test_warning = !other_action.tds_perf_test
31+
Actions.sh("./scripts/update_embedded.sh")
32+
33+
# Verify no unexpected files were modified
34+
git_status = Actions.sh('git', 'status')
35+
modified_files = git_status.split("\n").select { |line| line.include?('modified:') }
36+
modified_files = modified_files.map { |str| str.split(':')[1].strip.delete_prefix('../') }
37+
38+
modified_files.each do |modified_file|
39+
UI.abort_with_message!("Unexpected change to #{modified_file}.") unless UPGRADABLE_EMBEDDED_FILES[platform].any? do |s|
40+
s.include?(modified_file)
41+
end
42+
end
43+
44+
# Everything looks good: commit and push
45+
unless modified_files.empty?
46+
modified_files.each { |modified_file| Actions.sh('git', 'add', modified_file.to_s) }
47+
Actions.sh('git', 'commit', '-m', 'Update embedded files')
48+
other_action.ensure_git_status_clean
49+
end
50+
51+
perf_test_warning
52+
end
53+
54+
def pre_update_embedded_tests
55+
tds_perf_test_result = other_action.tds_perf_test
56+
57+
unless tds_perf_test_result
58+
UI.important("TDS performance tests failed. Make sure to validate performance before releasing to public users.")
59+
return false
60+
end
61+
62+
return true
63+
end
64+
end
65+
end
66+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Fastlane
22
module DdgAppleAutomation
3-
VERSION = "2.1.1"
3+
VERSION = "2.2.0"
44
end
55
end

0 commit comments

Comments
 (0)