This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow-steward.git


The following commit(s) were added to refs/heads/main by this push:
     new a9dbf6a  fix(check-tool-updates): replace GNU-only `tac` and `date -d 
<RFC>` so socat lookup works on macOS (#26)
a9dbf6a is described below

commit a9dbf6a9ff94dba66b9c6b2d48ca1dc288742c22
Author: Jarek Potiuk <[email protected]>
AuthorDate: Fri May 1 17:37:58 2026 +0200

    fix(check-tool-updates): replace GNU-only `tac` and `date -d <RFC>` so 
socat lookup works on macOS (#26)
    
    Two pre-existing GNU-isms in the socat upstream-lookup helper
    broke the script on macOS BSD coreutils:
    
    - `tac` (used to walk a sorted version list newest-to-oldest)
      is not in BSD coreutils. Folded the reversal into the
      preceding `sort` invocation: `sort -uV` + `tac` becomes
      `sort -uVr`. Identical output, no extra binary needed.
    
    - `date -d "$mtime"` (used to parse the server's
      `Last-Modified` HTTP header into an epoch timestamp) is
      GNU-only. BSD `date(1)` accepts only `-jf <format>` for
      arbitrary parsing and does not understand RFC 2822 / RFC 7231
      date strings out of the box. Delegated parsing to python3's
      `email.utils.parsedate_to_datetime`, which is the stdlib
      HTTP-date parser and is available everywhere python3 is.
      Same module is already used elsewhere in this script.
    
    Verified end-to-end on macOS — `socat` now reports
    `✓ up to date` instead of `upstream lookup failed (rate limit
    / network)`.
    
    Generated-by: Claude Code (Opus 4.7)
---
 tools/agent-isolation/check-tool-updates.sh | 30 ++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/tools/agent-isolation/check-tool-updates.sh 
b/tools/agent-isolation/check-tool-updates.sh
index c98d07a..0c60b3a 100755
--- a/tools/agent-isolation/check-tool-updates.sh
+++ b/tools/agent-isolation/check-tool-updates.sh
@@ -92,6 +92,14 @@ for r in json.load(sys.stdin):
 
 # socat upstream is a static HTML index; scrape the highest version
 # tarball whose mtime is older than `cooldown_days`.
+#
+# Implementation note — portability. Both `tac` (used to reverse a
+# sorted list) and `date -d <RFC-2822-string>` (used to parse the
+# server's Last-Modified header) are GNU-only. macOS ships BSD
+# coreutils which have neither. The version reversal is folded into
+# `sort -uVr` (descending unique versions); date parsing is delegated
+# to python3's `email.utils.parsedate_to_datetime`, which is the
+# stdlib HTTP-date parser and is available everywhere python3 is.
 socat_latest_aged() {
   local cooldown_days="$1"
   local cutoff=$(( now_epoch - cooldown_days * 86400 ))
@@ -100,9 +108,9 @@ socat_latest_aged() {
   # `Last-Modified` (per HEAD) is older than the cutoff.
   local index versions
   index="$(curl -fsSL http://www.dest-unreach.org/socat/download/)" || return 1
-  versions=$(echo "$index" | grep -oE 
'socat-[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' | sort -uV)
-  for v in $(echo "$versions" | tac); do
-    local ver mtime mtime_epoch
+  versions=$(echo "$index" | grep -oE 
'socat-[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' | sort -uVr)
+  for v in $versions; do
+    local ver mtime parsed mtime_epoch mtime_date
     ver="${v#socat-}"
     ver="${ver%.tar.gz}"
     mtime=$(curl -sI "http://www.dest-unreach.org/socat/download/${v}"; \
@@ -110,9 +118,21 @@ socat_latest_aged() {
     if [[ -z "$mtime" ]]; then
       continue
     fi
-    mtime_epoch=$(date -d "$mtime" +%s 2>/dev/null) || continue
+    parsed=$(MTIME="$mtime" python3 <<'PY' || true
+import os
+from email.utils import parsedate_to_datetime
+try:
+    dt = parsedate_to_datetime(os.environ["MTIME"])
+    print(f"{int(dt.timestamp())}\t{dt.strftime('%Y-%m-%d')}")
+except Exception:
+    raise SystemExit(1)
+PY
+)
+    [[ -z "$parsed" ]] && continue
+    mtime_epoch=${parsed%%$'\t'*}
+    mtime_date=${parsed##*$'\t'}
     if (( mtime_epoch <= cutoff )); then
-      printf '%s\t%s\n' "$ver" "$(date -u -d "$mtime" +%Y-%m-%d)"
+      printf '%s\t%s\n' "$ver" "$mtime_date"
       return 0
     fi
   done

Reply via email to