Skip to content

Commit 4eae985

Browse files
committed
ci: Add workflow to check for new UN geodata
1 parent 110c533 commit 4eae985

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// ArcGIS Portal REST API — Search reference:
2+
// https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
3+
const API_URL =
4+
'https://geoportal.un.org/arcgis/sharing/rest/search?f=json&q=(type:%22geojson%22)%20AND%20(title:%22*geodata*%22)&sortField=modified&sortOrder=desc';
5+
6+
export default async function checkUnGeodata({ github, context, core }) {
7+
// Fetch the UN Geodata API
8+
const res = await fetch(API_URL);
9+
if (!res.ok) throw new Error(`API request failed: ${res.status}`);
10+
const data = await res.json();
11+
const newest = data.results[0];
12+
if (!newest) throw new Error('No results returned from API');
13+
14+
const marker = `<!-- un-geodata-modified:${newest.modified} -->`;
15+
16+
// Check if we already created an issue for this modified timestamp
17+
const { data: issues } = await github.rest.issues.listForRepo({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
labels: 'topojson',
21+
state: 'all',
22+
sort: 'created',
23+
direction: 'desc',
24+
per_page: 100
25+
});
26+
27+
if (issues.some((issue) => issue.body?.includes(marker))) {
28+
core.info('No new updates — issue already exists for this timestamp');
29+
return;
30+
}
31+
32+
// Build the issue body
33+
const summary = data.results
34+
.map((r) => {
35+
const date = new Date(r.modified).toISOString().slice(0, 10);
36+
return `- **${r.title}** (modified: ${date}, id: \`${r.id}\`)`;
37+
})
38+
.join('\n');
39+
40+
const body = [
41+
marker,
42+
'',
43+
`The [UN Geoportal geodata API](${API_URL}) has new or updated artifacts.`,
44+
'',
45+
`### Datasets found (${data.total}):`,
46+
summary,
47+
'',
48+
'### Next steps',
49+
'- Review the updated dataset at the [UN Geoportal](https://geoportal.un.org/)',
50+
'- Determine if `topojson/` sources need updating',
51+
'',
52+
'---',
53+
`*This issue was created automatically by the [Check UN Geodata Updates](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/workflows/check-un-geodata.yml) workflow.*`
54+
].join('\n');
55+
56+
await github.rest.issues.create({
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
title: `UN Geodata update detected: ${newest.title}`,
60+
body,
61+
labels: ['topojson']
62+
});
63+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Check UN Geodata Updates
2+
3+
on:
4+
schedule:
5+
# First day of every month at 09:00 UTC
6+
- cron: '0 9 1 * *'
7+
workflow_dispatch:
8+
9+
permissions:
10+
issues: write
11+
12+
jobs:
13+
check-geodata:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
17+
with:
18+
sparse-checkout: .github/scripts
19+
20+
- name: Check for UN Geodata updates
21+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
22+
with:
23+
script: |
24+
const { default: checkUnGeodata } = await import('${{ github.workspace }}/.github/scripts/check-un-geodata.mjs');
25+
await checkUnGeodata({ github, context, core });

0 commit comments

Comments
 (0)