CI: auto-fix hostname resolution for sudo
Some checks failed
Deploy / deploy (push) Failing after 4s

This commit is contained in:
Jeremie Fraeys 2026-01-23 14:37:56 -05:00
parent c7bb43219f
commit 5bd54fc595
No known key found for this signature in database

View file

@ -87,6 +87,35 @@ jobs:
exit 1
fi
HOSTNAME_SHORT=\"$(hostname)\"
if ! getent hosts \"$HOSTNAME_SHORT\" >/dev/null 2>&1; then
sudo -n /usr/bin/python3 - <<'PY'
import os
from pathlib import Path
hostname = os.popen("hostname").read().strip()
hosts_path = Path("/etc/hosts")
text = hosts_path.read_text(encoding="utf-8") if hosts_path.exists() else ""
lines = text.splitlines()
def has_hostname() -> bool:
for line in lines:
s = line.strip()
if not s or s.startswith("#"):
continue
if hostname in s.split():
return True
return False
if not has_hostname():
if text and not text.endswith("\n"):
text += "\n"
text += f"127.0.1.1 {hostname}\n"
hosts_path.write_text(text, encoding="utf-8")
PY
fi
sudo -n mkdir -p /opt/infra-controller /etc/infra-controller /var/lib/infra-controller /var/log/infra-controller
if [ ! -d /opt/infra-controller/.git ]; then