Skip to content

Commit b470adf

Browse files
committed
scrape: skip cleanly in CI when DATABASE_URL secret is absent
The repo doesn't have DATABASE_URL configured yet, so the daily scheduled scrape has been failing red for the last three days even though the scraper code is fine — the workflow just has no way to authenticate to a database that doesn't exist. Two changes: - scripts/scrape-all.mjs: in CI without DATABASE_URL, exit 0 with a workflow ::notice instead of failing. Local runs and any run with SCRAPE_REQUIRE_DB=true still fail loudly, so dev work isn't silenced. - workflow: a 'check secrets' step gates every downstream step on whether DATABASE_URL is set. When unset the run renders one notice in the summary and exits green; when set it runs exactly the way it used to. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
1 parent da2719e commit b470adf

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

.github/workflows/scrape.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,32 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
16+
- name: check secrets
17+
id: secrets
18+
env:
19+
DATABASE_URL: ${{ secrets.DATABASE_URL }}
20+
run: |
21+
if [ -n "$DATABASE_URL" ]; then
22+
echo "has_db=true" >> "$GITHUB_OUTPUT"
23+
else
24+
echo "has_db=false" >> "$GITHUB_OUTPUT"
25+
echo "::notice title=civic-philly scrape skipped::DATABASE_URL secret not configured. Run 'gh secret set DATABASE_URL --repo c-tonneslan/civic-philly' to enable the scheduled scrape."
26+
fi
1627
- uses: actions/setup-node@v4
28+
if: steps.secrets.outputs.has_db == 'true'
1729
with:
1830
node-version: "20"
1931
cache: "npm"
20-
- run: npm ci
32+
- if: steps.secrets.outputs.has_db == 'true'
33+
run: npm ci
2134
- name: run all scrapers
35+
if: steps.secrets.outputs.has_db == 'true'
2236
env:
2337
DATABASE_URL: ${{ secrets.DATABASE_URL }}
38+
SCRAPE_REQUIRE_DB: "true"
2439
run: npm run scrape:all
2540
- name: refresh demolition permits + violations + owners + transfers
41+
if: steps.secrets.outputs.has_db == 'true'
2642
env:
2743
DATABASE_URL: ${{ secrets.DATABASE_URL }}
2844
run: |
@@ -31,12 +47,14 @@ jobs:
3147
npm run load:owners
3248
npm run load:transfers
3349
- name: backfill developer + spatial joins for new rows
50+
if: steps.secrets.outputs.has_db == 'true'
3451
env:
3552
DATABASE_URL: ${{ secrets.DATABASE_URL }}
3653
run: |
3754
npm run backfill:developers
3855
npm run backfill:spatial
3956
- name: send alerts
57+
if: steps.secrets.outputs.has_db == 'true'
4058
env:
4159
DATABASE_URL: ${{ secrets.DATABASE_URL }}
4260
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
@@ -50,10 +68,24 @@ jobs:
5068
runs-on: ubuntu-latest
5169
steps:
5270
- uses: actions/checkout@v4
71+
- name: check secrets
72+
id: secrets
73+
env:
74+
DATABASE_URL: ${{ secrets.DATABASE_URL }}
75+
run: |
76+
if [ -n "$DATABASE_URL" ]; then
77+
echo "has_db=true" >> "$GITHUB_OUTPUT"
78+
else
79+
echo "has_db=false" >> "$GITHUB_OUTPUT"
80+
echo "::notice title=civic-philly digest skipped::DATABASE_URL secret not configured."
81+
fi
5382
- uses: actions/setup-node@v4
83+
if: steps.secrets.outputs.has_db == 'true'
5484
with: { node-version: "20", cache: "npm" }
55-
- run: npm ci
85+
- if: steps.secrets.outputs.has_db == 'true'
86+
run: npm ci
5687
- name: send weekly digests
88+
if: steps.secrets.outputs.has_db == 'true'
5789
env:
5890
DATABASE_URL: ${{ secrets.DATABASE_URL }}
5991
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}

scripts/scrape-all.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Run every scraper in sequence. Used by the scheduled job (cron / GH Action).
22
//
33
// node scripts/scrape-all.mjs
4+
//
5+
// In CI without a DATABASE_URL secret configured the script exits 0 with a
6+
// workflow notice instead of failing every scheduled run. Set
7+
// SCRAPE_REQUIRE_DB=true to force a hard fail (useful for manual
8+
// workflow_dispatch runs once the secret is in place, and for local dev).
49

510
import { spawn } from "node:child_process";
611
import { fileURLToPath } from "node:url";
@@ -9,6 +14,19 @@ import { dirname, join } from "node:path";
914
const here = dirname(fileURLToPath(import.meta.url));
1015
const scripts = ["scrape-housing.mjs", "scrape-zoning.mjs", "scrape-infrastructure.mjs", "scrape-septa.mjs"];
1116

17+
if (!process.env.DATABASE_URL) {
18+
const inCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true";
19+
const required = process.env.SCRAPE_REQUIRE_DB === "true";
20+
if (inCI && !required) {
21+
const msg =
22+
"DATABASE_URL is not set. Configure the repository secret to enable the scheduled scrape (gh secret set DATABASE_URL --repo c-tonneslan/civic-philly).";
23+
console.log(`::notice title=civic-philly scrape skipped::${msg}`);
24+
process.exit(0);
25+
}
26+
console.error("DATABASE_URL is not set.");
27+
process.exit(1);
28+
}
29+
1230
function run(script) {
1331
return new Promise((resolve) => {
1432
const path = join(here, script);

0 commit comments

Comments
 (0)