#!/usr/bin/env bash # Canonical build metadata is always RFC3339 UTC with a trailing Z. Human # readable tags may use Asia/Shanghai, but must never be used as buildTime. droboticflow_normalize_build_time() { local raw="${1:-}" if [[ -z "${raw//[[:space:]]/}" ]]; then date -u +%Y-%m-%dT%H:%M:%SZ return fi BUILD_TIME_INPUT="$raw" python3 - <<'PY' from datetime import datetime, timezone, timedelta import os raw = os.environ.get("BUILD_TIME_INPUT", "").strip() try: value = datetime.fromisoformat(raw.replace("Z", "+00:00")) except ValueError as exc: raise SystemExit(f"invalid build time {raw!r}: expected RFC3339") from exc if value.tzinfo is None: raise SystemExit("build time must include a timezone offset or Z") value = value.astimezone(timezone.utc) if value > datetime.now(timezone.utc) + timedelta(minutes=5): raise SystemExit("build time is more than five minutes in the future") print(value.isoformat(timespec="seconds").replace("+00:00", "Z")) PY } droboticflow_resolve_build_metadata() { DROBOTICFLOW_BUILD_TIME="$(droboticflow_normalize_build_time "${DROBOTICFLOW_BUILD_TIME:-}")" OPERATOR_RUNNER_BUILD_TIME="$(droboticflow_normalize_build_time "${OPERATOR_RUNNER_BUILD_TIME:-$DROBOTICFLOW_BUILD_TIME}")" export DROBOTICFLOW_BUILD_TIME OPERATOR_RUNNER_BUILD_TIME }