Skip to content
Merged
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Qubership Testing Platform Common Scripts

ATP3 submodule for ATP3-runners that contains base bash scripts.
ATP3 submodule for ATP3-runners that contains base Bash scripts.

# Modular Test Execution Scripts
## Modular Test Execution Scripts

This directory contains modular scripts for test execution in containerized environments.

Expand All @@ -14,6 +14,7 @@ The test execution process is divided into modular components that can be easily

- **`init.sh`** - Environment initialization and secure AWS/S3 configuration
- **`git-clone.sh`** - Repository cloning and extraction (clears Git token)
- **`render-environment-configuration.sh`** - Renders `/environment-configuration/environment-configuration-template.json` in the clone: substitutes `${VAR_NAME}` from the pod env, writes `/tmp/clone/environment-configuration.json`, exports `ATP_ENVGENE_CONFIGURATION` and `ENV_SYSTEMS`. Unset placeholders stay in the file (warning only). Call after `clone_repository`.
- **`runtime-setup.sh`** - Runtime-specific environment setup
- **`test-runner.sh`** - Test execution and results collection (clears sensitive vars)
- **`upload-monitor.sh`** - Event-based upload monitoring and finalization
Expand Down Expand Up @@ -174,4 +175,4 @@ ENTRYPOINT ["/entrypoint.sh"]
1. Create runtime-specific setup script in `runtimes/`
2. Create runtime-specific test runner if needed
3. Update Dockerfile to copy appropriate modules
4. Test with your specific runtime environment
4. Test with your specific runtime environment
2 changes: 1 addition & 1 deletion email-notification/README-email-notification-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ echo "$json_content"

# Or use exported variables
echo "JSON file: $JSON_FILE"

echo "Content: $GENERATED_JSON"

# File will be saved to: ../email-notification-generated/email-notification-results-generated.json
```
Expand Down
11 changes: 5 additions & 6 deletions email-notification/calculate-email-notification-variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# - jq (for JSON parsing)
# - bc (for floating point calculations)

set -eo pipefail

# Logging functions
log_info() {
echo "ℹ️ $1"
Expand All @@ -37,13 +35,13 @@ ALLURE_RESULTS_DIR="${1:-/tmp/clone/allure-results}"
# Check if allure-results directory exists
if [ ! -d "$ALLURE_RESULTS_DIR" ]; then
log_error "Allure results directory not found: $ALLURE_RESULTS_DIR"
exit 1
return 1
fi

# Check if jq is available
if ! command -v jq &> /dev/null; then
log_error "jq is required but not installed. Please install jq to parse JSON files."
exit 1
return 1
fi

# Check if bc is available, if not we'll use awk for calculations
Expand Down Expand Up @@ -105,7 +103,7 @@ done
# Calculate pass rate
if [ $total_tests -eq 0 ]; then
log_error "No test results found in $ALLURE_RESULTS_DIR"
exit 1
return 1
fi

# Calculate pass rate as percentage (passed / total * 100)
Expand Down Expand Up @@ -138,15 +136,16 @@ export TEST_FAILED_COUNT="$failed_tests"
export TEST_SKIPPED_COUNT="$skipped_tests"
export TEST_OVERALL_STATUS="$overall_status"

TEST_DETAILS_STRING=""
# Create test details string
TEST_DETAILS_STRING=""
for test_detail in "${test_details[@]}"; do
if [ -n "$TEST_DETAILS_STRING" ]; then
TEST_DETAILS_STRING="$TEST_DETAILS_STRING\n$test_detail"
else
TEST_DETAILS_STRING="$test_detail"
fi
done
export TEST_DETAILS_STRING="$TEST_DETAILS_STRING"

# Display summary
echo ""
Expand Down
20 changes: 14 additions & 6 deletions email-notification/generate-email-notification-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ generate_email_notification_file() {
}

# Get script directory
local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local SCRIPT_DIR
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Set default values if not provided
if [ -z "$template_file" ]; then
Expand All @@ -45,7 +46,8 @@ generate_email_notification_file() {
local allure_results_dir="/tmp/clone/allure-results"

# Generate output file name based on template name
local template_basename=$(basename "$template_file" .txt)
local template_basename
template_basename=$(basename "$template_file" .txt)

# Create email-notification-generated directory one level up
local output_dir="/tmp/clone/scripts/email-notification-generated"
Expand Down Expand Up @@ -76,16 +78,22 @@ generate_email_notification_file() {
EXECUTION_DATE="${EXECUTION_DATE:-$(date '+%Y-%m-%d %H:%M:%S')}"
TEST_COVERAGE="${TEST_COVERAGE:-100.00}"
ATP_REPORT_VIEW_UI_URL="${ATP_REPORT_VIEW_UI_URL:-https://example.com}"
ALLURE_REPORT_URL="${ATP_REPORT_VIEW_UI_URL}/Report/${ENVIRONMENT_NAME}/${CURRENT_DATE}/${CURRENT_TIME}/allure-report/index.html"
if [[ "${ATP_REPORT_VIEW_UI_URL}" == Test\ not\ started* ]]; then
ALLURE_REPORT_URL="${ATP_REPORT_VIEW_UI_URL}"
else
ALLURE_REPORT_URL="${ATP_REPORT_VIEW_UI_URL}/Report/${ENVIRONMENT_NAME}/${CURRENT_DATE}/${CURRENT_TIME}/allure-report/index.html"
fi
TIMESTAMP="${TIMESTAMP:-$(date '+%Y-%m-%d %H:%M:%S UTC')}"

# Read template content
local template_content=$(cat "$template_file")
local template_content
template_content=$(cat "$template_file")

log_info "Replacing placeholders with actual values..."

# Replace placeholders and handle conditional blocks using awk
local message_content=$(echo "$template_content" | awk -v overall_status="$TEST_OVERALL_STATUS" \
local message_content
message_content=$(cho "$template_content" | awk -v overall_status="$TEST_OVERALL_STATUS" \
-v pass_rate="$TEST_PASS_RATE" \
-v total_count="$TEST_TOTAL_COUNT" \
-v passed_count="$TEST_PASSED_COUNT" \
Expand Down Expand Up @@ -207,4 +215,4 @@ generate_email_notification_file() {

# Return the message content
# echo "$message_content"
}
}
14 changes: 8 additions & 6 deletions email-notification/generate-email-notification-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# Dependencies:
# - calculate-email-notification-variables.sh (for test statistics)

set -eo pipefail

# Function to generate email notification JSON results
generate_email_notification_json() {
# Logging functions
Expand Down Expand Up @@ -46,6 +44,7 @@ generate_email_notification_json() {
log_info "Generating JSON results file"

# Calculate pass rate and test details
# shellcheck source=/home/runner/work/qubership-testing-platform-common-scripts/qubership-testing-platform-common-scripts/scripts/email-notification/calculate-email-notification-variables.sh
source "$SCRIPT_DIR/calculate-email-notification-variables.sh" "$allure_results_dir"

# Calculate additional metrics
Expand All @@ -60,7 +59,11 @@ generate_email_notification_json() {
EXECUTION_DATE="${EXECUTION_DATE:-$(date '+%Y-%m-%d %H:%M:%S')}"
TEST_COVERAGE="${TEST_COVERAGE:-100.00}"
ATP_REPORT_VIEW_UI_URL="${ATP_REPORT_VIEW_UI_URL:-https://example.com}"
ALLURE_REPORT_URL="${ATP_REPORT_VIEW_UI_URL}/Report/${ENVIRONMENT_NAME}/${CURRENT_DATE}/${CURRENT_TIME}/allure-report/index.html"
if [[ "${ATP_REPORT_VIEW_UI_URL}" == Test\ not\ started* ]]; then
ALLURE_REPORT_URL="${ATP_REPORT_VIEW_UI_URL}"
else
ALLURE_REPORT_URL="${ATP_REPORT_VIEW_UI_URL}/Report/${ENVIRONMENT_NAME}/${CURRENT_DATE}/${CURRENT_TIME}/allure-report/index.html"
fi
TIMESTAMP="${TIMESTAMP:-$(date '+%Y-%m-%d %H:%M:%S UTC')}"

log_info "Building JSON structure..."
Expand Down Expand Up @@ -237,11 +240,10 @@ generate_email_notification_json() {


# Export the JSON content as environment variable for use in other scripts
export GENERATED_JSON="$json_content"
export JSON_FILE="$output_file"

log_info "Environment variables exported: JSON_FILE"
echo "$output_file"
return 0
log_info "Environment variables exported: GENERATED_JSON, JSON_FILE"

# Return the JSON content
# echo "$json_content"
Expand Down
70 changes: 70 additions & 0 deletions error-handler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

# Centralized error handler and exit-trap for graceful pod termination.
#
# fail() — logs the error, stores its message, and exits 1.
# finalize_once() — the single EXIT trap: writes error-state JSON when rc≠0,
# runs all cleanup, then always exits 0 so Argo does not hang.
#
# Register the trap in entrypoint.sh AFTER all scripts are sourced:
# trap 'finalize_once' EXIT

# Stores the fatal error message so finalize_once can embed it in the error JSON.
FAIL_MESSAGE=""
FINALIZE_DONE=false

fail() {
local error_message="${1:-Unknown error}"
echo "❌ FATAL: $error_message"
echo "⚠️ Delegating cleanup to EXIT trap (finalize_once)."
FAIL_MESSAGE="$error_message"
# Catched by EXIT trap and goes to finalize_once()
exit 1
}

#shellcheck disable=SC2329
finalize_once() {
local rc=$?

if [ "$FINALIZE_DONE" != "true" ]; then
FINALIZE_DONE=true
echo "🔄 EXIT trap triggered with rc=$rc"

set +e

# When fail() triggered the exit, write a minimal error-state JSON so
# downstream pipeline stages (e.g. "get ATP report file") receive a valid
# FAILED payload instead of finding no file at all.
if [ "$rc" -ne 0 ]; then
echo "⚠️ Non-zero exit detected — pre-seeding error-state variables for generate_email_notification_json."
# Pre-export the variables that generate_email_notification_json reads.
# calculate-email-notification-variables.sh will bail early (no allure results),
# leaving these values intact so the downstream JSON reflects the fatal error.
export TEST_OVERALL_STATUS="FAILED"
export TEST_PASS_RATE=0
export TEST_PASS_RATE_ROUNDED=0
export TEST_TOTAL_COUNT=0
export TEST_PASSED_COUNT=0
export TEST_FAILED_COUNT=0
export TEST_SKIPPED_COUNT=0
export TEST_COVERAGE=0
export TEST_DETAILS_STRING=""
export EXECUTION_DATE
EXECUTION_DATE="$(date '+%Y-%m-%d %H:%M:%S')"
export TIMESTAMP
TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S UTC')"
export ALLURE_REPORT_URL="Test not started. Please check the logs for more details. $FAIL_MESSAGE. "
export ATP_REPORT_VIEW_UI_URL="Test not started. Please check the logs for more details. $FAIL_MESSAGE. "
fi

generate_email_notification_json || true
save_native_report "$TMP_DIR/${NATIVE_REPORT_DIR:-playwright-report}" || true
finalize_upload || true
sleep 15

set -e
fi

# Always exit 0 so Argo/Kubernetes does not treat this pod as failed and hang.
exit 0
}
Loading
Loading