Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module AutoHCK
autoload_relative :Downloader, 'auxiliary/downloader'
autoload_relative :Engine, 'engines/engine'
autoload_relative :EngineError, 'engines/exceptions'
autoload_relative :ExternalScript, 'notificationmanagers/external_script/external_script'
autoload_relative :ExtraSoftwareBrokenConfig, 'auxiliary/extra_software/exceptions'
autoload_relative :ExtraSoftwareManager, 'auxiliary/extra_software/manager'
autoload_relative :ExtraSoftwareMissingConfig, 'auxiliary/extra_software/exceptions'
Expand All @@ -56,6 +57,8 @@ module AutoHCK
autoload_relative :MachineRunError, 'setupmanagers/exceptions'
autoload_relative :Models, 'models'
autoload_relative :MultiLogger, 'auxiliary/multi_logger'
autoload_relative :NotificationManager, 'notificationmanagers/notification_manager'
autoload_relative :NotificationProviderInterface, 'notificationmanagers/notification_provider_interface'
autoload_relative :NotImplementedError, 'exceptions'
autoload_relative :OpenJsonError, 'exceptions'
autoload_relative :PackageManager, 'auxiliary/package_manager'
Expand Down
8 changes: 8 additions & 0 deletions lib/engines/config_manager/config_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(project)
@project = project
@logger = project.logger
@project.append_multilog("#{self.class.tag}.log")
@project.notification_manager.post_engine_init(self)
end

def self.tag(*)
Expand All @@ -23,11 +24,14 @@ def test_steps
end

def run
@project.notification_manager.pre_engine_run(self)
ResourceScope.open do |scope|
@project.logger.info('Stating result uploader token initialization')
@result_uploader = ResultUploader.new(scope, @project)
@result_uploader.ask_token
end
ensure
@project.notification_manager.post_engine_run(self)
end

def drivers
Expand All @@ -41,5 +45,9 @@ def self.platform(*)
def result_uploader_needed?
false
end

def target
nil
end
end
end
4 changes: 4 additions & 0 deletions lib/engines/hckinstall/hckinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def initialize(project)
validate_paths
prepare_extra_sw
@logger.debug('HCKInstall: initialized')
@project.notification_manager.post_engine_init(self)
end

def test_steps
Expand Down Expand Up @@ -438,6 +439,7 @@ def plan_client
end

def run
@project.notification_manager.pre_engine_run(self)
@logger.debug('HCKInstall: run')

prepare_setup_scripts_config
Expand All @@ -449,6 +451,8 @@ def run
run_first(studio:, client:)
run_second(client:)
end
ensure
@project.notification_manager.post_engine_run(self)
end
end
end
4 changes: 4 additions & 0 deletions lib/engines/hcktest/hcktest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def initialize(project)
@extensions = find_extensions
prepare_extra_sw
validate_paths unless @driver_path.nil?
@project.notification_manager.post_engine_init(self)
end

def test_steps
Expand Down Expand Up @@ -345,6 +346,7 @@ def group_tests_by_config
end

def run
@project.notification_manager.pre_engine_run(self)
upload_driver_package unless @driver_path.nil?

if @project.options.test.dump
Expand All @@ -358,6 +360,8 @@ def run
else
auto_run
end
ensure
@project.notification_manager.post_engine_run(self)
end

def result_uploader_needed?
Expand Down
7 changes: 7 additions & 0 deletions lib/engines/hcktest/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def perform_queue_test_commands(test)

sig { params(test: Models::HLK::Test, wait: T::Boolean).void }
def queue_test(test, wait: false)
@project.notification_manager.pre_tests_queue_test(test, wait)
retries = 0
begin
perform_queue_test_commands(test)
Expand Down Expand Up @@ -367,6 +368,7 @@ def done_test_results

sig { params(test: Models::HLK::Test).void }
def on_test_start(test)
@project.notification_manager.pre_tests_on_test_start(test)
@logger.info(">>> Currently running: #{test.name} [#{test.estimatedruntime}]")

test.started_at = DateTime.now
Expand Down Expand Up @@ -571,6 +573,7 @@ def collect_memory_dumps(test)

sig { params(test: Models::HLK::Test, test_result: T::Hash[String, T.untyped]).void }
def handle_finished_test_result(test, test_result)
@project.notification_manager.pre_tests_handle_finished_test_result(test, test_result)
collect_memory_dumps(test)

print_test_results(test, test_result)
Expand All @@ -590,6 +593,7 @@ def test_for_result(result)
end

def handle_finished_test_results(results)
@project.notification_manager.pre_tests_handle_finished_test_results(results, tests_stats)
@project.update_test_stats(tests_stats)

results.each do |result|
Expand Down Expand Up @@ -787,6 +791,7 @@ def retry_tests(current_run_tests)

sig { params(tests: T::Array[Models::HLK::Test]).void }
def run(tests)
@project.notification_manager.pre_tests_run(tests)
load_clients_system_info
update_summary_results_log
tests.each do |test|
Expand All @@ -804,6 +809,8 @@ def run(tests)
return if @project.run_terminated

retry_tests(tests) unless @project.options.test.auto_retry_failed_tests.zero?
ensure
@project.notification_manager.post_tests_run(tests)
end
end
end
17 changes: 17 additions & 0 deletions lib/notificationmanagers/external_script/example_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Example AutoHCK external notification hook.
# Environment: AUTOHCK_NOTIFICATION_HOOK and one variable per Ruby argument,
# e.g. AUTOHCK_NOTIFICATION_PROJECT holds JSON for the Project snapshot.

set -euo pipefail

log_default="${TMPDIR:-/tmp}/autohck_external_notification.log"
log_path="${AUTOHCK_NOTIFICATION_LOG_PATH:-$log_default}"

{
printf '%s\n' "=== $(date -Iseconds 2>/dev/null || date) ==="

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The date -Iseconds command is a GNU coreutils extension and might not be available on all Unix-like systems (e.g., macOS, BSD). While there's a fallback to date, relying on specific date formats can lead to portability issues. Consider using a more universally available method for generating ISO 8601 timestamps if this script is expected to run in diverse environments.

env | LC_ALL=C sort | grep '^AUTOHCK_NOTIFICATION_' || true
printf '\n'
} >>"$log_path"

exit 0
27 changes: 27 additions & 0 deletions lib/notificationmanagers/external_script/external_script.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"_readme": "Optional 'hooks' object maps Ruby notification method names to executable scripts. Paths are relative to this file's directory unless absolute. Omit hooks you do not need.",
"hooks": {
"post_project_init": "example_hook.sh",
"pre_project_run": "example_hook.sh",
"post_project_run": "example_hook.sh",
"post_engine_init": "example_hook.sh",
"pre_engine_run": "example_hook.sh",
"post_engine_run": "example_hook.sh",
"post_setup_manager_init": "example_hook.sh",
"pre_setup_manager_run_hck_studio": "example_hook.sh",
"post_setup_manager_run_hck_studio": "example_hook.sh",
"pre_setup_manager_run_studio": "example_hook.sh",
"post_setup_manager_run_studio": "example_hook.sh",
"pre_setup_manager_run_hck_client": "example_hook.sh",
"post_setup_manager_run_hck_client": "example_hook.sh",
"pre_setup_manager_run_client": "example_hook.sh",
"post_setup_manager_run_client": "example_hook.sh",
"pre_tests_run": "example_hook.sh",
"post_tests_run": "example_hook.sh",
"pre_tests_queue_test": "example_hook.sh",
"pre_tests_on_test_start": "example_hook.sh",
"pre_tests_handle_finished_test_results": "example_hook.sh",
"pre_tests_handle_finished_test_result": "example_hook.sh",
"close": "example_hook.sh"
}
}
Loading
Loading