2026-05-13 20:13:02 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
report_date_value() {
|
|
|
|
|
printf '%s\n' "${1:-$(date +%Y-%m-%d)}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_output_dir() {
|
2026-05-29 18:48:48 +08:00
|
|
|
printf '%s\n' "$(report_output_root)"
|
2026-05-13 20:13:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_html_dir() {
|
2026-05-29 18:48:48 +08:00
|
|
|
printf '%s\n' "$(report_html_root)"
|
2026-05-13 20:13:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_markdown_path() {
|
|
|
|
|
local report_date
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
printf '%s\n' "$(report_output_dir)/daily_report_${report_date}.md"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_html_path() {
|
|
|
|
|
local report_date
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
printf '%s\n' "$(report_html_dir)/daily_report_${report_date}.html"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_archive_dir() {
|
|
|
|
|
local report_date
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
printf '%s\n' "$(report_output_dir)/${report_date:0:4}/${report_date:5:2}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_archive_markdown_path() {
|
|
|
|
|
local report_date
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
printf '%s\n' "$(report_archive_dir "$report_date")/daily_report_${report_date}.md"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_archive_html_path() {
|
|
|
|
|
local report_date
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
printf '%s\n' "$(report_archive_dir "$report_date")/daily_report_${report_date}.html"
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-29 18:48:48 +08:00
|
|
|
report_output_root() {
|
|
|
|
|
printf '%s\n' "${REPORT_OUTPUT_DIR:-reports/daily}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_html_root() {
|
|
|
|
|
printf '%s\n' "$(report_output_root)/html"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_ad_hoc_dir() {
|
|
|
|
|
local report_date run_kind trigger_source
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
run_kind="${2:-manual}"
|
|
|
|
|
trigger_source="${3:-cli}"
|
|
|
|
|
printf '%s\n' "reports/ad_hoc/${report_date}/${run_kind}/${trigger_source}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_ad_hoc_markdown_path() {
|
|
|
|
|
local report_date run_kind trigger_source
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
run_kind="${2:-manual}"
|
|
|
|
|
trigger_source="${3:-cli}"
|
|
|
|
|
printf '%s\n' "$(report_ad_hoc_dir "$report_date" "$run_kind" "$trigger_source")/daily_report_${report_date}.md"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report_ad_hoc_html_path() {
|
|
|
|
|
local report_date run_kind trigger_source
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
run_kind="${2:-manual}"
|
|
|
|
|
trigger_source="${3:-cli}"
|
|
|
|
|
printf '%s\n' "$(report_ad_hoc_dir "$report_date" "$run_kind" "$trigger_source")/html/daily_report_${report_date}.html"
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-13 20:13:02 +08:00
|
|
|
archive_report_artifacts() {
|
|
|
|
|
local report_date markdown_path html_path archive_dir
|
|
|
|
|
report_date="$(report_date_value "${1:-}")"
|
|
|
|
|
markdown_path="$(report_markdown_path "$report_date")"
|
|
|
|
|
html_path="$(report_html_path "$report_date")"
|
|
|
|
|
archive_dir="$(report_archive_dir "$report_date")"
|
|
|
|
|
|
|
|
|
|
mkdir -p "$archive_dir"
|
|
|
|
|
cp "$markdown_path" "$(report_archive_markdown_path "$report_date")"
|
|
|
|
|
cp "$html_path" "$(report_archive_html_path "$report_date")"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
track_report_state() {
|
2026-05-14 16:17:39 +08:00
|
|
|
local db_url report_date status model_count summary_md output_path error_message run_kind trigger_source is_official_daily
|
2026-05-13 20:13:02 +08:00
|
|
|
db_url="$1"
|
|
|
|
|
report_date="$2"
|
|
|
|
|
status="$3"
|
|
|
|
|
model_count="${4:-}"
|
|
|
|
|
summary_md="${5:-}"
|
|
|
|
|
output_path="${6:-}"
|
|
|
|
|
error_message="${7:-}"
|
2026-05-14 16:17:39 +08:00
|
|
|
run_kind="${8:-manual}"
|
|
|
|
|
trigger_source="${9:-cli}"
|
|
|
|
|
is_official_daily="${10:-false}"
|
2026-05-13 20:13:02 +08:00
|
|
|
|
2026-05-22 07:33:45 +08:00
|
|
|
if [[ "$is_official_daily" == "true" ]]; then
|
|
|
|
|
psql "$db_url" \
|
|
|
|
|
-v ON_ERROR_STOP=1 \
|
|
|
|
|
--set=report_date="$report_date" \
|
|
|
|
|
--set=status="$status" \
|
|
|
|
|
--set=model_count="$model_count" \
|
|
|
|
|
--set=summary_md="$summary_md" \
|
|
|
|
|
--set=output_path="$output_path" \
|
|
|
|
|
--set=error_message="$error_message" \
|
|
|
|
|
--set=run_kind="$run_kind" \
|
|
|
|
|
--set=trigger_source="$trigger_source" \
|
|
|
|
|
--set=is_official_daily="$is_official_daily" <<'SQL'
|
2026-05-13 20:13:02 +08:00
|
|
|
INSERT INTO daily_report (
|
|
|
|
|
report_date,
|
|
|
|
|
status,
|
|
|
|
|
model_count,
|
|
|
|
|
summary_md,
|
|
|
|
|
output_path,
|
|
|
|
|
error_message,
|
2026-05-14 16:17:39 +08:00
|
|
|
run_kind,
|
|
|
|
|
trigger_source,
|
|
|
|
|
is_official_daily,
|
2026-05-13 20:13:02 +08:00
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
VALUES (
|
|
|
|
|
:'report_date',
|
|
|
|
|
:'status',
|
|
|
|
|
NULLIF(:'model_count', '')::INTEGER,
|
|
|
|
|
NULLIF(:'summary_md', ''),
|
|
|
|
|
NULLIF(:'output_path', ''),
|
|
|
|
|
NULLIF(:'error_message', ''),
|
2026-05-14 16:17:39 +08:00
|
|
|
NULLIF(:'run_kind', ''),
|
|
|
|
|
NULLIF(:'trigger_source', ''),
|
|
|
|
|
NULLIF(:'is_official_daily', '')::BOOLEAN,
|
2026-05-13 20:13:02 +08:00
|
|
|
NOW(),
|
|
|
|
|
NOW()
|
|
|
|
|
)
|
|
|
|
|
ON CONFLICT (report_date) DO UPDATE SET
|
|
|
|
|
status = EXCLUDED.status,
|
|
|
|
|
model_count = COALESCE(EXCLUDED.model_count, daily_report.model_count),
|
|
|
|
|
summary_md = COALESCE(EXCLUDED.summary_md, daily_report.summary_md),
|
|
|
|
|
output_path = COALESCE(EXCLUDED.output_path, daily_report.output_path),
|
|
|
|
|
error_message = EXCLUDED.error_message,
|
2026-05-22 07:33:45 +08:00
|
|
|
run_kind = EXCLUDED.run_kind,
|
|
|
|
|
trigger_source = EXCLUDED.trigger_source,
|
|
|
|
|
is_official_daily = TRUE,
|
2026-05-13 20:13:02 +08:00
|
|
|
updated_at = NOW();
|
2026-05-22 07:33:45 +08:00
|
|
|
SQL
|
|
|
|
|
fi
|
2026-05-13 20:13:02 +08:00
|
|
|
|
2026-05-22 07:33:45 +08:00
|
|
|
psql "$db_url" \
|
|
|
|
|
-v ON_ERROR_STOP=1 \
|
|
|
|
|
--set=report_date="$report_date" \
|
|
|
|
|
--set=status="$status" \
|
|
|
|
|
--set=summary_md="$summary_md" \
|
|
|
|
|
--set=output_path="$output_path" \
|
|
|
|
|
--set=error_message="$error_message" \
|
|
|
|
|
--set=run_kind="$run_kind" \
|
|
|
|
|
--set=trigger_source="$trigger_source" \
|
|
|
|
|
--set=is_official_daily="$is_official_daily" <<'SQL'
|
2026-05-13 20:13:02 +08:00
|
|
|
INSERT INTO report_runs (
|
|
|
|
|
source,
|
|
|
|
|
report_date,
|
|
|
|
|
status,
|
|
|
|
|
summary_md,
|
|
|
|
|
output_path,
|
2026-05-14 16:17:39 +08:00
|
|
|
error_message,
|
|
|
|
|
run_kind,
|
|
|
|
|
trigger_source,
|
|
|
|
|
is_official_daily
|
2026-05-13 20:13:02 +08:00
|
|
|
)
|
|
|
|
|
VALUES (
|
|
|
|
|
'pipeline',
|
|
|
|
|
:'report_date',
|
|
|
|
|
:'status',
|
|
|
|
|
NULLIF(:'summary_md', ''),
|
|
|
|
|
NULLIF(:'output_path', ''),
|
2026-05-14 16:17:39 +08:00
|
|
|
NULLIF(:'error_message', ''),
|
|
|
|
|
NULLIF(:'run_kind', ''),
|
|
|
|
|
NULLIF(:'trigger_source', ''),
|
|
|
|
|
NULLIF(:'is_official_daily', '')::BOOLEAN
|
2026-05-13 20:13:02 +08:00
|
|
|
);
|
|
|
|
|
SQL
|
|
|
|
|
}
|