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
17 changes: 8 additions & 9 deletions email-notification/README-email-notification-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ This set of scripts is designed to analyze test results from the `allure-results

After executing `generate-email-notification-json.sh`, the following environment variables are available:

- `GENERATED_JSON` - Content of the generated JSON file
- `JSON_FILE` - Path to the JSON results file
- `JSON_FILE` - Path to the JSON results file (read content with `jq`/`cat`; not exported as env to avoid ARG_MAX limits)

Full JSON content is **not** exported as an environment variable; use `$JSON_FILE`.

## Environment Variables

Expand All @@ -62,7 +63,7 @@ The script uses the following environment variables for JSON generation:
- `REPORT_VIEW_HOST_URL` - Host for viewing reports
- `ALLURE_REPORT_URL` - Path to reports folder
- `TIMESTAMP` - Timestamp
- `TEST_DETAILS_STRING` - String with details of all tests (converted to JSON array)
- `TEST_DETAILS_STRING` - String with details of all tests (used during generation only; not exported — large runs would exceed ARG_MAX)

## Generated JSON Structure

Expand Down Expand Up @@ -117,9 +118,9 @@ json_content=$(generate_email_notification_json)
# Use the result
echo "$json_content"

# Or use exported variables
# Or use exported path and read file
echo "JSON file: $JSON_FILE"
echo "Content: $GENERATED_JSON"
jq . "$JSON_FILE"

# File will be saved to: ../email-notification-generated/email-notification-results-generated.json
```
Expand All @@ -134,10 +135,8 @@ The `generate_email_notification_json` function does not accept parameters.

### Return Values

The function returns:
- **Generated JSON content** (output to stdout)
- **Environment variable `GENERATED_JSON`** - JSON content
- **Environment variable `JSON_FILE`** - path to JSON file
The function writes JSON to disk and exports:
- **Environment variable `JSON_FILE`** - path to JSON file (consumers read file; JSON is not stored in env)

## Differences from Text Version

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ for test_detail in "${test_details[@]}"; do
TEST_DETAILS_STRING="$test_detail"
fi
done
export TEST_DETAILS_STRING="$TEST_DETAILS_STRING"

# Display summary
echo ""
Expand Down
4 changes: 1 addition & 3 deletions email-notification/generate-email-notification-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,9 @@ generate_email_notification_json() {
log_success "JSON generated successfully: $output_file"


# 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: GENERATED_JSON, JSON_FILE"
log_info "Environment variables exported: JSON_FILE"

# Return the JSON content
# echo "$json_content"
Expand Down
32 changes: 16 additions & 16 deletions push-metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Push test result metrics to Prometheus Pushgateway / VictoriaMetrics
#
# Reads from:
# - $GENERATED_JSON (env var set by generate_email_notification_json)
# - $JSON_FILE (path set by generate_email_notification_json)
# - /tmp/clone/allure-results/*-result.json (individual Allure result files)
#
# Feature toggle:
Expand Down Expand Up @@ -167,26 +167,26 @@ push_metrics() {
return 1
fi

if [[ -z "${GENERATED_JSON:-}" ]]; then
echo "❌ push_metrics: GENERATED_JSON is not set. Run generate_email_notification_json first."
if [[ -z "${JSON_FILE:-}" ]] || [[ ! -f "${JSON_FILE}" ]]; then
echo "❌ push_metrics: JSON_FILE is not set or missing. Run generate_email_notification_json first."
return 1
fi

local allure_results_dir="/tmp/clone/allure-results"
local env="${ENVIRONMENT_NAME:-unknown}"

# -------------------------------------------------------------------------
# Parse scope-level statistics from GENERATED_JSON
# Parse scope-level statistics from JSON_FILE
# -------------------------------------------------------------------------
local pass_rate total passed failed skipped overall_status
pass_rate=$(echo "$GENERATED_JSON" | jq -r '.test_results.pass_rate // 0')
total=$(echo "$GENERATED_JSON" | jq -r '.test_results.total_count // 0')
passed=$(echo "$GENERATED_JSON" | jq -r '.test_results.passed_count // 0')
failed=$(echo "$GENERATED_JSON" | jq -r '.test_results.failed_count // 0')
skipped=$(echo "$GENERATED_JSON" | jq -r '.test_results.skipped_count // 0')
overall_status=$(echo "$GENERATED_JSON" | jq -r '.test_results.overall_status // "UNKNOWN"')

echo "GENERATED_JSON content parsing results:"
pass_rate=$(jq -r '.test_results.pass_rate // 0' "$JSON_FILE")
total=$(jq -r '.test_results.total_count // 0' "$JSON_FILE")
passed=$(jq -r '.test_results.passed_count // 0' "$JSON_FILE")
failed=$(jq -r '.test_results.failed_count // 0' "$JSON_FILE")
skipped=$(jq -r '.test_results.skipped_count // 0' "$JSON_FILE")
overall_status=$(jq -r '.test_results.overall_status // "UNKNOWN"' "$JSON_FILE")

echo "JSON content parsing results:"
echo "pass_rate: $pass_rate"
echo "total: $total"
echo "passed: $passed"
Expand Down Expand Up @@ -304,13 +304,13 @@ push_metrics() {
payload+="atp_test_case_duration_seconds{test_name=\"${safe_name}\",environment=\"${env}\",suite=\"${safe_suite}\"} ${duration}\n"
done
else
echo "⚠️ push_metrics: allure-results not found or empty, falling back to GENERATED_JSON test_details"
echo "⚠️ push_metrics: allure-results not found or empty, falling back to JSON_FILE test_details"
local count
count=$(echo "$GENERATED_JSON" | jq '.test_details | length')
count=$(jq '.test_details | length' "$JSON_FILE")
for ((i=0; i<count; i++)); do
local test_name status result_val safe_name
test_name=$(echo "$GENERATED_JSON" | jq -r ".test_details[$i].test_name")
status=$(echo "$GENERATED_JSON" | jq -r ".test_details[$i].status" | tr '[:upper:]' '[:lower:]')
test_name=$(jq -r ".test_details[$i].test_name" "$JSON_FILE")
status=$(jq -r ".test_details[$i].status" "$JSON_FILE" | tr '[:upper:]' '[:lower:]')
result_val=0
[[ "$status" == "passed" ]] && result_val=1
safe_name="${test_name//\"/\\\"}"
Expand Down
Loading