Skip to content

Commit a0947c4

Browse files
rusackasclaude
andcommitted
ci(country-map): run build_maps.py instead of the retired notebook in update-country-maps
Co-Authored-By: Evan Rusackas <evan@preset.io> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent fb7c265 commit a0947c4

1 file changed

Lines changed: 22 additions & 81 deletions

File tree

‎.github/workflows/update-country-maps.yml‎

Lines changed: 22 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Update Country Maps
22

33
# Regenerates plugins/plugin-chart-country-map's GeoJSON files, countries.ts
44
# and docs/data/countries.json from upstream Natural Earth + community geo
5-
# data, by running the same notebook `npm run update-maps` runs locally.
5+
# data, by running the same `build_maps.py` script `npm run update-maps` runs locally.
66
#
77
# Runs weekly and on workflow_dispatch, but only opens or updates a PR when
88
# the regenerated output actually differs from what's on `master` - most
@@ -12,7 +12,7 @@ name: Update Country Maps
1212
# to a commit where practical; the live WHO ArcGIS query can't be pinned
1313
# (it's a live service, not a repo), so a run can still legitimately pick up
1414
# an unreviewed upstream change there. The job itself fails (separately from
15-
# whether a PR was opened) if the notebook hits a cell error, so a broken
15+
# whether a PR was opened) if build_maps.py errors, so a broken
1616
# upstream source doesn't just quietly go green.
1717
on:
1818
schedule:
@@ -45,86 +45,28 @@ jobs:
4545
with:
4646
python-version: "3.11"
4747

48-
- name: Install notebook dependencies
48+
- name: Install build dependencies
4949
run: |
5050
# Exact versions, with the full resolved set pinned via a constraints
5151
# file, so a diff only moves with upstream data and not with a
5252
# GeoPandas/Shapely/pyogrio change to simplification or serialization.
5353
pip install -c superset-frontend/plugins/plugin-chart-country-map/scripts/requirements-constraints.txt \
54-
jupyter==1.1.1 nbconvert==7.16.6 ipykernel==6.29.5 \
5554
geopandas==1.1.1 shapely==2.1.1 matplotlib==3.10.3 requests==2.32.4
5655
57-
- name: Force speed_run (skip interactive preview rendering)
56+
- name: Run build_maps.py
57+
id: build
5858
working-directory: superset-frontend/plugins/plugin-chart-country-map/scripts
5959
run: |
60-
python3 - <<'PYEOF'
61-
import json
62-
63-
path = "Country Map GeoJSON Generator.ipynb"
64-
with open(path, encoding="utf-8") as f:
65-
nb = json.load(f)
66-
67-
for cell in nb["cells"]:
68-
if cell["cell_type"] != "code":
69-
continue
70-
if "".join(cell["source"]).strip().startswith("speed_run = False"):
71-
cell["source"] = [
72-
"speed_run = True\n",
73-
"# forced True for unattended CI regeneration; not committed back\n",
74-
]
75-
break
76-
else:
77-
raise SystemExit("Could not find the speed_run cell to patch")
78-
79-
with open(".ci-run.ipynb", "w", encoding="utf-8") as f:
80-
json.dump(nb, f)
81-
PYEOF
82-
83-
- name: Run notebook
84-
working-directory: superset-frontend/plugins/plugin-chart-country-map/scripts
85-
run: |
86-
jupyter nbconvert --to notebook --execute --inplace --allow-errors \
87-
--ExecutePreprocessor.timeout=1200 .ci-run.ipynb
88-
89-
- name: Check for cell errors and record a summary
90-
id: notebook
91-
working-directory: superset-frontend/plugins/plugin-chart-country-map/scripts
92-
run: |
93-
python3 - <<'PYEOF' >> "$GITHUB_OUTPUT"
94-
import json
95-
96-
with open(".ci-run.ipynb", encoding="utf-8") as f:
97-
nb = json.load(f)
98-
99-
errors = []
100-
for i, cell in enumerate(nb["cells"]):
101-
for output in cell.get("outputs", []):
102-
if output.get("output_type") == "error":
103-
errors.append(f"cell {i}: {output.get('ename')}: {output.get('evalue')}")
104-
elif output.get("output_type") == "stream":
105-
# Some cells catch download failures and print them
106-
# instead of raising, so they never emit an error output.
107-
for line in "".join(output.get("text", [])).splitlines():
108-
if line.startswith("Unable to download"):
109-
errors.append(f"cell {i}: {line}")
110-
111-
if errors:
112-
print("had_errors=true")
113-
summary = "\n".join(f"- {e}" for e in errors[:20])
114-
else:
115-
print("had_errors=false")
116-
summary = ""
117-
118-
with open("notebook-errors.txt", "w", encoding="utf-8") as f:
119-
f.write(summary)
120-
PYEOF
121-
rm -f .ci-run.ipynb
122-
if [ -s notebook-errors.txt ]; then
123-
echo "::warning::Notebook hit cell errors; generated data may be stale."
124-
{
125-
echo "### Country map notebook cell errors"
126-
cat notebook-errors.txt
127-
} >> "$GITHUB_STEP_SUMMARY"
60+
# Capture the exit status instead of failing here, so the drift/PR
61+
# steps below still run; the final step fails the job on error.
62+
set +e
63+
python3 build_maps.py --data-dir "$RUNNER_TEMP/natural-earth"
64+
status=$?
65+
if [ "$status" -ne 0 ]; then
66+
echo "had_errors=true" >> "$GITHUB_OUTPUT"
67+
echo "::warning::build_maps.py failed (exit $status); generated data may be stale."
68+
else
69+
echo "had_errors=false" >> "$GITHUB_OUTPUT"
12870
fi
12971
13072
- name: Check for drift
@@ -142,7 +84,7 @@ jobs:
14284
env:
14385
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14486
BRANCH: chore/update-country-maps-automated
145-
HAD_ERRORS: ${{ steps.notebook.outputs.had_errors }}
87+
HAD_ERRORS: ${{ steps.build.outputs.had_errors }}
14688
run: |
14789
git config user.name "GitHub Action"
14890
git config user.email "action@github.com"
@@ -151,15 +93,14 @@ jobs:
15193
superset-frontend/plugins/plugin-chart-country-map/src/countries.ts \
15294
docs/data/countries.json
15395
git commit -m "chore(country-map): regenerate GeoJSON from upstream sources" \
154-
-m "Automated run of the Country Map GeoJSON Generator notebook (npm run update-maps). Review the rendered diffs before merging - one source (WHO ArcGIS) is a live query, not a pinned commit."
96+
-m "Automated run of build_maps.py (npm run update-maps). Review the rendered diffs before merging - one source (WHO ArcGIS) is a live query, not a pinned commit."
15597
git push --force origin "$BRANCH"
15698
15799
BODY="Automated run of \`npm run update-maps\` against current \`master\`. **Please review the rendered map diffs before merging** - this pulls from several community geo sources plus a live WHO ArcGIS query that can't be pinned to a commit, so an upstream change there hasn't had human eyes on it yet."
158100
if [ "$HAD_ERRORS" = "true" ]; then
159101
BODY="$BODY
160102
161-
⚠️ The notebook run hit cell errors (ran with --allow-errors, so it continued past them - affected countries' data may be stale rather than updated):
162-
$(cat superset-frontend/plugins/plugin-chart-country-map/scripts/notebook-errors.txt)"
103+
⚠️ build_maps.py exited with an error, so the affected countries' data may be stale rather than updated. See the workflow run log."
163104
fi
164105
165106
if gh pr list --repo "$GITHUB_REPOSITORY" --head "$BRANCH" --state open --json number --jq 'length > 0' | grep -q true; then
@@ -172,7 +113,7 @@ jobs:
172113
fi
173114
174115
- name: Close stale sync PR when no drift remains
175-
if: steps.diff.outputs.has_changes == 'false' && steps.notebook.outputs.had_errors != 'true'
116+
if: steps.diff.outputs.has_changes == 'false' && steps.build.outputs.had_errors != 'true'
176117
env:
177118
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
178119
BRANCH: chore/update-country-maps-automated
@@ -182,8 +123,8 @@ jobs:
182123
--comment "Upstream sources no longer differ from \`master\`, so this regenerated data is stale. Closing automatically."
183124
fi
184125
185-
- name: Fail if the notebook hit cell errors
186-
if: steps.notebook.outputs.had_errors == 'true'
126+
- name: Fail if build_maps.py errored
127+
if: steps.build.outputs.had_errors == 'true'
187128
run: |
188-
echo "::error::Notebook hit cell errors - see the job summary above. Any resulting PR update still went out; the data for the affected countries may be stale rather than updated."
129+
echo "::error::build_maps.py failed - see the Run build_maps.py step log. Any resulting PR update still went out; the data for the affected countries may be stale rather than updated."
189130
exit 1

0 commit comments

Comments
 (0)