railyard/apps/rithub-server/scripts/explore-featured-refresh.sh
caelum0x 6801c08af9
Some checks failed
ci / cargo test (abacus) (push) Has been cancelled
ci / cargo test (agent-runtime) (push) Has been cancelled
ci / cargo test (context-passport) (push) Has been cancelled
ci / cargo test (game-economy) (push) Has been cancelled
ci / cargo test (ledgerline) (push) Has been cancelled
ci / cargo test (mint) (push) Has been cancelled
ci / cargo test (rago) (push) Has been cancelled
ci / cargo test (relay) (push) Has been cancelled
ci / node suites (push) Has been cancelled
ci / cargo test (toolgate) (push) Has been cancelled
ci / cargo test (turnstile) (push) Has been cancelled
ci / cargo test (vend) (push) Has been cancelled
feat(RIT-OPS,RIT-BRD): rename gitea -> rit everywhere we control, deployed + live-verified
apps/gitea -> apps/rithub-server; compose services/containers renamed
(rithub-server-app/postgres/act-runner) with explicit project name and
volume names pinned to the exact existing Docker volumes (no data loss);
our own GITEA_* compose/env var names -> RIT_*; new rit-admin CLI wrapper
on railyard-box; giteaSession.mjs/giteaOAuth.mjs/giteaInfo.mjs ->
ritSession/ritOAuth/ritInfo across 6 apps; GiteaForgeAdapter -> RitForgeAdapter
+ giteaSyncService/importGiteaRepos/syncGiteaRepos -> rit* in ritgram
(tsc clean); apps/console/lib/gitea.ts -> lib/ritProvision.ts; Go
internal/giteaclient -> internal/ritclient in rithub-async-import (go
build/test clean); new /auth/rit + /forges/rit/connect routes with
/gitea back-compat aliases; locale/swagger/footer/captcha template text
scrubbed of remaining "Gitea" strings.

Deployed to railyard-box: old containers stopped/removed, /srv/railyard-gitea
renamed to /srv/rithub-server with a symlink kept, docker compose up -d from
the new path, act_runner network-alias fix for its persisted instance URL.
Live-verified: docker compose config diff showed zero unintended value
changes, DB row counts unchanged (19 users, 635 repos), full route
regression 200/expected, 0 "gitea" in headers/bodies on every checked page,
real git clone+push over HTTPS and SSH with a disposable account (deleted
after). Deferred on purpose (documented in plans/railyard.md): the forge
discriminator / DB column names / Postgres role+volume names (data
migrations, not a naming change) and the upstream GITEA__ env-to-ini keys
and X-Gitea-* wire headers (hardcoded in the vendored engine binary).

See plans/railyard.md RIT-OPS/RIT-BRD entry for the full old->new map and
live evidence.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-12-01 16:34:39 +03:00

196 lines
8.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Rithub UI round 2 (owner task, 2026-11-19): regenerate the curated
# "Featured" section at the top of Explore
# (rithub-beat-github-2026-11-18.md finding #3 -- "Explore should lead
# with the best real public repos").
#
# The repo list itself is a real, Jev-scored editorial pin (see
# PINNED_REPO_NAMES below and plans/railyard.md for the score table) --
# stars are 0 across the board right now (too early a product for that
# signal), so a one-time quality judgment picked the set, not a nightly
# heuristic. What this script does on every run is refresh that fixed
# set against live data:
# 1. Fetch each pinned repo's current description/stars/push-time from
# the live API.
# 2. Drop any that are now private/empty (gone/retired since pinning).
# 3. Re-sort the (still-fixed) set by live star count, then most
# recently pushed.
# 4. Render plain static HTML cards and rewrite the content between
# the RITHUB-FEATURED markers in custom/templates/explore/featured.tmpl.
# 5. If the file actually changed, restart the Rithub container so the
# new static content is picked up -- the engine runs RUN_MODE=prod,
# which caches custom templates in memory for the process lifetime,
# so a template-file edit alone has no effect until restart. This
# follows the exact same load1<6 / no-other-build self-gate as
# oauth-auto-import.sh in this same directory -- skips quietly and
# retries next tick if the box is busy, never forces it.
#
# No engine/Go code change: this is pure data (template content) churn.
#
# Install (one-time, on railyard-box -- installed under the real `deploy`
# user's own crontab, same as oauth-auto-import.sh actually runs despite
# that script's header comment saying `-u git`; there is no `git` system
# user on this box):
# (crontab -l 2>/dev/null; echo "17 4 * * * /srv/rithub-server/scripts/explore-featured-refresh.sh >> /var/log/rithub-explore-featured-refresh.log 2>&1") | crontab -
# Installed live 2026-11-19 (UI round 2) -- `crontab -l` on railyard-box
# confirmed both this line and the pre-existing oauth-auto-import.sh one.
set -euo pipefail
LOCK_FILE="/var/lock/rithub-explore-featured.lock"
RIT_CONTAINER="rithub-server-app"
RITHUB_HOST="${RITHUB_HOST:-rithub.dev}"
RITHUB_BASE_URL="${RITHUB_BASE_URL:-https://${RITHUB_HOST}}"
CUSTOM_DIR="${RITHUB_CUSTOM_DIR:-/srv/rithub-server/custom}"
FEATURED_TMPL="${CUSTOM_DIR}/templates/explore/featured.tmpl"
TOP_N="${RITHUB_FEATURED_COUNT:-8}"
exec 9>"$LOCK_FILE"
if ! flock -n 9; then
exit 0
fi
if [ ! -f "$FEATURED_TMPL" ]; then
echo "explore-featured-refresh: $FEATURED_TMPL not found, skipping" >&2
exit 0
fi
before_hash=$(md5sum "$FEATURED_TMPL" 2>/dev/null | cut -d' ' -f1 || echo "")
python3 -I - "$RITHUB_BASE_URL" "$FEATURED_TMPL" "$TOP_N" <<'PYEOF'
import sys, json, html, re, urllib.request
base_url, featured_path, top_n = sys.argv[1], sys.argv[2], int(sys.argv[3])
top_n = max(1, min(top_n, 24))
REPO_ICON_SVG = (
'<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">'
'<path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75'
'h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.5 2.5 0 0 1 '
'2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.5 2.5 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 '
'.25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.25.25 0 0 0-.3 0L5.4 '
'15.7a.25.25 0 0 1-.4-.2Z"/></svg>'
)
# The actual curated pin list (chosen 2026-11-19, UI round 2): every
# public repo was Jev-scored ("how strong a flagship example is this
# repo to feature on Explore" -- a real/credible-product judgment, not a
# toy/tutorial/placeholder one -- plans/railyard.md has the full score
# table) against the live catalog of 172 real (non-"stars/*"/"forks/*"
# mirror) public repos; stars are currently 0 across the board (too
# early for that signal to differentiate), so quality-of-description was
# the real signal Jev used. Top 8, kept diverse across orgs rather than
# every rithub/scribase repo in a row. This script does NOT re-run that
# judgment on a schedule -- it only refreshes each pinned repo's live
# stars/description/push-time from the API and re-sorts this fixed set
# by that live data, so the page always shows current numbers without a
# human/Jev re-curation pass every night.
PINNED_REPO_NAMES = [
"rithub/railyard",
"scribase/scribase-mail-studio",
"caelum0x/qie-forge",
"caelum0x/menivor",
"scribase/scribase-hermes-plugin",
"caelum0x/umpirix",
"scribase/schemaproof",
"rithub/rit",
]
def fetch_repo(base_url, full_name):
url = f"{base_url}/api/v1/repos/{full_name}"
req = urllib.request.Request(url, headers={"User-Agent": "rithub-explore-featured-refresh/1"})
with urllib.request.urlopen(req, timeout=20) as r:
return json.load(r)
def _to_epoch(ts):
if not ts:
return 0
try:
import datetime
return int(datetime.datetime.fromisoformat(ts.replace("Z", "+00:00")).timestamp())
except Exception:
return 0
def render_card(repo):
full_name = repo["full_name"]
owner, name = full_name.split("/", 1)
desc = (repo.get("description") or "").strip()
desc = desc[:160] + ("…" if len(desc) > 160 else "")
href = f"/{html.escape(owner)}/{html.escape(name)}"
return (
f'<a class="rithub-featured-card" href="{href}">'
f'<div class="rithub-featured-card-head">{REPO_ICON_SVG}'
f'<span class="rithub-featured-card-name">{html.escape(owner)}/{html.escape(name)}</span>'
f'</div>'
f'<div class="rithub-featured-card-desc">{html.escape(desc)}</div>'
f'</a>'
)
picked = []
for full_name in PINNED_REPO_NAMES:
try:
repo = fetch_repo(base_url, full_name)
except Exception as e:
print(f"explore-featured-refresh: {full_name} fetch failed ({e}), skipping it this run", file=sys.stderr)
continue
if repo.get("private") or repo.get("empty"):
print(f"explore-featured-refresh: {full_name} is now private/empty, skipping it this run", file=sys.stderr)
continue
picked.append(repo)
picked.sort(key=lambda r: (-r.get("stars_count", 0), -_to_epoch(r.get("updated_at"))))
picked = picked[:top_n]
if not picked:
print("explore-featured-refresh: no pinned repos resolved live, leaving featured.tmpl untouched", file=sys.stderr)
sys.exit(0)
cards_html = "\n\t\t".join(render_card(r) for r in picked)
new_block = f"<!-- RITHUB-FEATURED:BEGIN -->\n\t\t{cards_html}\n\t\t<!-- RITHUB-FEATURED:END -->"
content = open(featured_path, encoding="utf-8").read()
updated = re.sub(
r"<!-- RITHUB-FEATURED:BEGIN -->.*?<!-- RITHUB-FEATURED:END -->",
new_block.replace("\\", "\\\\"),
content,
flags=re.S,
)
if updated == content:
print("explore-featured-refresh: no change")
sys.exit(0)
open(featured_path, "w", encoding="utf-8").write(updated)
print(f"explore-featured-refresh: wrote {len(picked)} featured repos: " +
", ".join(r["full_name"] for r in picked))
PYEOF
after_hash=$(md5sum "$FEATURED_TMPL" 2>/dev/null | cut -d' ' -f1 || echo "")
if [ "$before_hash" = "$after_hash" ]; then
echo "explore-featured-refresh: featured.tmpl unchanged, no restart needed"
exit 0
fi
# Content changed on disk -- the engine (RUN_MODE=prod) caches custom templates
# in memory, so this needs a restart to actually show up. Same load1<6 /
# no-other-build self-gate as oauth-auto-import.sh; skip quietly and pick
# it up on the next scheduled run rather than forcing it.
load1=$(cut -d' ' -f1 /proc/loadavg)
if awk "BEGIN{exit !($load1>=6)}"; then
echo "explore-featured-refresh: load1=$load1 >= 6, skipping restart this tick (content updated on disk, will take effect on next successful restart)"
exit 0
fi
if pgrep -f "docker.*build|buildx|next build" >/dev/null 2>&1; then
echo "explore-featured-refresh: a build is running, skipping restart this tick"
exit 0
fi
docker compose -f /srv/rithub-server/docker-compose.yml restart app >/dev/null 2>&1 \
|| docker restart "$RIT_CONTAINER" >/dev/null 2>&1 \
|| true
echo "explore-featured-refresh: restarted $RIT_CONTAINER to pick up refreshed Explore content"