#!/usr/bin/env bash # Publish every plugin release to the marketplace catalogue. Meant for cron, on the ONE machine that # publishes. # # ── Why a timer at all, when a webhook would be instant ── # # The sync reads bare mirrors at their newest tag, so running it on a schedule cannot publish anything # that was not pushed — which is exactly what made a timer unsafe before, and is no longer true. A Gitea # webhook would cut the delay from a minute to a second, and it would also mean a public write route, a # shared secret, and a second path into the same code. A minute is not the problem anybody had: the # complaint that started this was a release that never appeared at all. # # ── What it costs ── # # About 2.7s per tick with nothing to do — one query, one fetch per repository, no writes. Gitea is on # this same machine, so none of that leaves the box. # # ── The log ── # # One timestamped summary line per tick, ALWAYS, including the ticks that do nothing. A fresh timestamp # is the only thing that distinguishes "nothing to publish" from "the timer died". Plugin-level lines # appear only for a plugin that actually moved, which is what `--quiet` buys. set -uo pipefail PLATFORM="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" LOG="${MARKETPLACE_SYNC_LOG:-$(dirname "$PLATFORM")/marketplace-sync.log}" LOCK="/tmp/officer-marketplace-sync.lock" # Cron's PATH is three entries and bun is in none of them. export PATH="$HOME/.bun/bin:/usr/local/bin:/usr/bin:/bin" cd "$PLATFORM" || exit 1 # Skip rather than queue. A tick that finds the previous one still running has nothing to add — the run # in progress will publish whatever this one would have. exec 9>"$LOCK" flock -n 9 || exit 0 bun --env-file=.env scripts/marketplace-sync.ts --quiet >>"$LOG" 2>&1 # Bounded without logrotate, because this is one file on one machine and a config file for it would be # more moving parts than the thing it manages. if [ "$(wc -l <"$LOG")" -gt 20000 ]; then tail -n 5000 "$LOG" >"$LOG.tmp" && mv "$LOG.tmp" "$LOG" fi