name: Catalog producer on: schedule: - cron: '17 8 * * *' workflow_dispatch: inputs: task: description: 'Verify private producer code, or refresh, publish and deploy catalog JSON' type: choice options: [verify, refresh] required: true default: verify no_enrich: description: 'Skip paid metadata, cover and reader enrichment during refresh' type: boolean required: true default: true allow_outside_window: description: 'Explicit one-run UTC exception for a manual refresh and its deployment' type: boolean required: true default: false permissions: contents: read concurrency: group: catalog-producer cancel-in-progress: false jobs: verify: if: github.repository == 'iamnbutler/shelfgoblin' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.task == 'verify' runs-on: ubuntu-latest timeout-minutes: 15 steps: - name: Check the UTC run window id: window run: | python3 - <<'PY' import datetime, os now = datetime.datetime.now(datetime.timezone.utc) end = now.replace(hour=22, minute=0, second=0, microsecond=0) # Verification has a 15-minute job timeout; it needs no refresh/checkpoint reserve. allowed = now.hour >= 2 and now + datetime.timedelta(minutes=15) <= end with open(os.environ['GITHUB_OUTPUT'], 'a') as output: output.write('allowed=' + str(allowed).lower() + '\n') print('Producer verification may run.' if allowed else 'Producer verification skipped: outside the permitted UTC window or too close to 22:00 UTC.') PY # No caller-controlled ref: only reviewed code on the private repository's main branch. - uses: actions/checkout@v4 if: steps.window.outputs.allowed == 'true' with: repository: iamnbutler/shelfgoblin-data ref: main token: ${{ secrets.CATALOG_DATA_TOKEN }} path: catalog persist-credentials: false - uses: actions/setup-node@v4 if: steps.window.outputs.allowed == 'true' with: node-version: 22 # Tests may print source fixtures. Keep their output on the ephemeral runner, never in public logs/artifacts. - name: Install and verify the private producer without model credentials if: steps.window.outputs.allowed == 'true' working-directory: catalog run: | if ! (npm ci && npm run check:backend && npm test) > "$RUNNER_TEMP/catalog-verification.log" 2>&1; then echo 'Private producer verification failed. Reproduce locally; private test output is not published.' exit 1 fi echo 'Private producer installation, type-check, and tests passed without model credentials.' env: OPENAI_API_KEY: '' TYPESAFE_API_KEY: '' HARDCOVER_API_TOKEN: '' CATALOG_DATA_TOKEN: '' GITHUB_TOKEN: '' refresh: if: github.repository == 'iamnbutler/shelfgoblin' && github.ref == 'refs/heads/main' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.task == 'refresh')) runs-on: ubuntu-latest timeout-minutes: 30 permissions: contents: write outputs: published: ${{ steps.publication.outputs.published }} sha: ${{ steps.publication.outputs.sha }} steps: - name: Check the UTC run window id: window env: CATALOG_ALLOW_OUTSIDE_WINDOW: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_outside_window || false }} run: | python3 - <<'PY' import datetime, os now = datetime.datetime.now(datetime.timezone.utc) end = now.replace(hour=22, minute=0, second=0, microsecond=0) manual_exception = os.environ.get('GITHUB_EVENT_NAME') == 'workflow_dispatch' and os.environ.get('CATALOG_ALLOW_OUTSIDE_WINDOW') == 'true' allowed = manual_exception or (now.hour >= 2 and now + datetime.timedelta(minutes=27) <= end) with open(os.environ['GITHUB_OUTPUT'], 'a') as output: output.write('allowed=' + str(allowed).lower() + '\n') if manual_exception: print('Explicit one-run UTC exception for this manual refresh. Work and checkpoint time limits still apply.') else: print('Catalog refresh may run with its checkpoint reserve.' if allowed else 'Catalog refresh skipped: outside the permitted UTC window or too close to 22:00 UTC.') PY - name: Check out the public app uses: actions/checkout@v4 if: steps.window.outputs.allowed == 'true' with: ref: main path: app persist-credentials: false - name: Check out the private producer uses: actions/checkout@v4 if: steps.window.outputs.allowed == 'true' with: repository: iamnbutler/shelfgoblin-data ref: main token: ${{ secrets.CATALOG_DATA_TOKEN }} path: catalog persist-credentials: false - name: Record the app checkout before publication id: app_base if: steps.window.outputs.allowed == 'true' working-directory: app run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - uses: actions/setup-node@v4 if: steps.window.outputs.allowed == 'true' with: node-version: 22 - name: Install the private producer if: steps.window.outputs.allowed == 'true' working-directory: catalog run: | if ! npm ci > "$RUNNER_TEMP/catalog-install.log" 2>&1; then echo 'Private producer installation failed. Private output is not published.' exit 1 fi # The private checkpoint must finish before any public JSON commit. No raw artifacts or child logs are uploaded. - name: Restore, refresh, checkpoint privately, and publish public JSON if: steps.window.outputs.allowed == 'true' working-directory: catalog # Module-loader failures happen before the worker's sanitized error handler. # Capture the whole entrypoint, including those failures, on the runner. run: | if ! node --import tsx scripts/backend/automation/worker.ts > "$RUNNER_TEMP/catalog-refresh.log" 2>&1; then echo 'Catalog refresh failed. Inspect the private checkpoint before retrying paid work; private output is not published.' exit 1 fi echo 'Catalog refresh finished and private progress was checkpointed.' env: CATALOG_APP_ROOT: ${{ github.workspace }}/app GITHUB_TOKEN: ${{ github.token }} CATALOG_DATA_TOKEN: ${{ secrets.CATALOG_DATA_TOKEN }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} TYPESAFE_API_KEY: ${{ secrets.TYPESAFE_API_KEY }} HARDCOVER_API_TOKEN: ${{ secrets.HARDCOVER_API_TOKEN }} CATALOG_OPENAI_MODEL: gpt-5.6-terra JEV_MODEL: jev-latest COVER_MODEL: gpt-4.1-mini CATALOG_NO_ENRICH: ${{ github.event_name == 'workflow_dispatch' && inputs.no_enrich || false }} CATALOG_ALLOW_OUTSIDE_WINDOW: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_outside_window || false }} # Only the sanitized completion receipt and the public Git history cross the job boundary. - name: Verify checkpoint and exact public commit id: publication if: steps.window.outputs.allowed == 'true' working-directory: app run: node scripts/catalog-deploy.mjs receipt env: CATALOG_BASE_SHA: ${{ steps.app_base.outputs.sha }} CATALOG_REFRESH_LOG: ${{ runner.temp }}/catalog-refresh.log # A GITHUB_TOKEN push does not trigger ordinary push CI. Validate and deploy here, # on a fresh runner containing only the exact public commit, with no private checkout. deploy: needs: refresh if: needs.refresh.outputs.published == 'true' runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: read steps: - name: Recheck the UTC window after refresh and runner delays id: window env: CATALOG_ALLOW_OUTSIDE_WINDOW: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_outside_window || false }} run: | python3 - <<'PY' import datetime, os now = datetime.datetime.now(datetime.timezone.utc) end = now.replace(hour=22, minute=0, second=0, microsecond=0) manual_exception = os.environ.get('GITHUB_EVENT_NAME') == 'workflow_dispatch' and os.environ.get('CATALOG_ALLOW_OUTSIDE_WINDOW') == 'true' # Reserve the entire deployment job, not just its final wrangler command. allowed = manual_exception or (now.hour >= 2 and now + datetime.timedelta(minutes=15) <= end) with open(os.environ['GITHUB_OUTPUT'], 'a') as output: output.write('allowed=' + str(allowed).lower() + '\n') if not allowed: with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as summary: summary.write('Public catalog committed; Cloudflare deployment deferred because its 15-minute job would cross the UTC exclusion window. The live app has not been updated by this run.\n') print('Deployment may run.' if allowed else 'Deployment deferred: outside the permitted UTC window or too close to 22:00 UTC.') PY - name: Check out the exact verified catalog commit uses: actions/checkout@v4 if: steps.window.outputs.allowed == 'true' with: ref: ${{ needs.refresh.outputs.sha }} persist-credentials: false - uses: actions/setup-node@v4 if: steps.window.outputs.allowed == 'true' with: node-version: 22 cache: npm - name: Install the public app without deployment credentials if: steps.window.outputs.allowed == 'true' timeout-minutes: 3 run: npm ci - name: Validate and build the exact public snapshot if: steps.window.outputs.allowed == 'true' timeout-minutes: 6 run: | npm run check npm run check:worker npm test npm run build npx wrangler deploy --dry-run --env="" env: BASE_PATH: '' - name: Deploy the canonical Cloudflare Worker id: cloudflare if: steps.window.outputs.allowed == 'true' timeout-minutes: 5 run: | node scripts/catalog-deploy.mjs guard if [ -z "$CLOUDFLARE_API_TOKEN" ]; then echo 'Cloudflare deployment token is not configured.' exit 1 fi npx wrangler deploy --env="" echo "Cloudflare accepted deployment of [\`$CATALOG_DEPLOY_SHA\`](https://github.com/iamnbutler/shelfgoblin/commit/$CATALOG_DEPLOY_SHA) to https://shelfgobl.in/. The build and app checks used this exact catalog commit." >> "$GITHUB_STEP_SUMMARY" env: # This secret is never present in the private producer or app installation/build. CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CATALOG_DEPLOY_SHA: ${{ needs.refresh.outputs.sha }} CATALOG_ALLOW_OUTSIDE_WINDOW: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_outside_window || false }}