Skip to content

Publish scheduled events #74

Publish scheduled events

Publish scheduled events #74

name: Publish scheduled events
# Hobby Vercel only allows once-daily crons (±1 hour). GitHub Actions polls every
# 5 minutes instead and hits the existing /api/cron/publish-events route.
on:
schedule:
# UTC; ~every 5 minutes (GitHub may delay slightly under load)
- cron: "*/5 * * * *"
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Publish due scheduled events
env:
CRON_SECRET: ${{ secrets.CRON_SECRET }}
APP_URL: ${{ secrets.APP_URL }}
run: |
set -euo pipefail
if [ -z "${CRON_SECRET:-}" ] || [ -z "${APP_URL:-}" ]; then
echo "Missing CRON_SECRET or APP_URL repository secrets."
exit 1
fi
# Trim trailing slash
BASE="${APP_URL%/}"
# Do not follow redirects: middleware redirects look like success otherwise.
BODY="$(mktemp)"
HTTP_CODE="$(curl -sS -o "${BODY}" -w '%{http_code}' \
-H "Authorization: Bearer ${CRON_SECRET}" \
-H "Accept: application/json" \
"${BASE}/api/cron/publish-events")"
echo "HTTP ${HTTP_CODE}"
cat "${BODY}"
echo
if [ "${HTTP_CODE}" != "200" ]; then
echo "Cron endpoint returned HTTP ${HTTP_CODE} (expected 200)."
exit 1
fi
if ! grep -q '"published"' "${BODY}"; then
echo "Response was not a publish JSON payload."
exit 1
fi
workflow-keepalive:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: liskin/gh-workflow-keepalive@v1