Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

docs: automate weekly star coverage updates

Joshua Yin Junxi7534fe0dbc58
diff --git a/.github/workflows/star-coverage.yml b/.github/workflows/star-coverage.yml
new file mode 100644
index 00000000..cba0d587
--- /dev/null
+++ b/.github/workflows/star-coverage.yml
@@ -0,0 +1,46 @@
+name: Weekly Star Coverage
+
+on:
+ schedule:
+ - cron: '0 1 * * 1'
+ workflow_dispatch:
+
+permissions:
+ contents: write
+
+concurrency:
+ group: weekly-star-coverage
+ cancel-in-progress: false
+
+jobs:
+ update:
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ - name: Download pinned Natural Earth map data
+ run: >-
+ curl -fsSL --retry 3
+ -o "$RUNNER_TEMP/natural-earth-countries.geojson"
+ https://raw.githubusercontent.com/nvkelso/natural-earth-vector/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_50m_admin_0_countries.geojson
+ - name: Refresh coverage from public GitHub profile locations
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+ run: |
+ node scripts/update-star-coverage.mjs "$RUNNER_TEMP/natural-earth-countries.geojson"
+ node scripts/generate-star-coverage-map.mjs "$RUNNER_TEMP/natural-earth-countries.geojson"
+ - name: Commit changes when coverage grows
+ run: |
+ git add README.md docs/*/README.md docs/star-coverage.json docs/images/star-coverage-map.svg
+ if git diff --cached --quiet; then
+ echo 'No new countries or regions.'
+ exit 0
+ fi
+ git diff --cached --check
+ git config user.name 'github-actions[bot]'
+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
+ git commit -m 'docs: refresh star coverage'
+ git push
diff --git a/docs/star-coverage.json b/docs/star-coverage.json
new file mode 100644
index 00000000..3ec3c026
--- /dev/null
+++ b/docs/star-coverage.json
@@ -0,0 +1,103 @@
+{
+ "codes": [
+ "ARE",
+ "ARG",
+ "ARM",
+ "AUS",
+ "AUT",
+ "AZE",
+ "BEL",
+ "BGD",
+ "BGR",
+ "BIH",
+ "BLR",
+ "BRA",
+ "CAN",
+ "CHE",
+ "CHL",
+ "CHN",
+ "CIV",
+ "COL",
+ "CRI",
+ "CYP",
+ "CZE",
+ "DEU",
+ "DNK",
+ "DOM",
+ "DZA",
+ "ECU",
+ "EGY",
+ "ESP",
+ "EST",
+ "FIN",
+ "FRA",
+ "GAB",
+ "GBR",
+ "GEO",
+ "GHA",
+ "GRC",
+ "HKG",
+ "HUN",
+ "IDN",
+ "IND",
+ "IRL",
+ "IRN",
+ "ISL",
+ "ISR",
+ "ITA",
+ "JOR",
+ "JPN",
+ "KAZ",
+ "KEN",
+ "KHM",
+ "KOR",
+ "KWT",
+ "LKA",
+ "LTU",
+ "LVA",
+ "MAC",
+ "MAR",
+ "MEX",
+ "MLT",
+ "MMR",
+ "MNG",
+ "MYS",
+ "NGA",
+ "NIC",
+ "NLD",
+ "NOR",
+ "NPL",
+ "NZL",
+ "PAK",
+ "PER",
+ "PHL",
+ "POL",
+ "PRI",
+ "PRT",
+ "PRY",
+ "PSE",
+ "QAT",
+ "ROU",
+ "RUS",
+ "SAU",
+ "SEN",
+ "SGP",
+ "SOM",
+ "SRB",
+ "SVK",
+ "SWE",
+ "THA",
+ "TUN",
+ "TUR",
+ "TWN",
+ "TZA",
+ "UGA",
+ "UKR",
+ "USA",
+ "UZB",
+ "VNM",
+ "XKX",
+ "YEM",
+ "ZAF"
+ ]
+}
diff --git a/scripts/generate-star-coverage-map.mjs b/scripts/generate-star-coverage-map.mjs
index 9d4b4612..7993e290 100644
--- a/scripts/generate-star-coverage-map.mjs
+++ b/scripts/generate-star-coverage-map.mjs
@@ -2,20 +2,11 @@ import { readFileSync, writeFileSync } from 'node:fs';
// Natural Earth 1:50m admin-0 countries (public domain), pinned at:
// https://github.com/nvkelso/natural-earth-vector/tree/ca96624a56bd078437bca8184e78163e5039ad19
-// Coverage: September 21, 2026 website snapshot, plus Senegal (starred September 22).
-const starredCodes = new Set(`
- ARE ARG ARM AUS AUT AZE BEL BGD BGR BIH BLR BRA CAN CHE CHL CHN CIV
- COL CRI CYP CZE DEU DNK DOM DZA ECU EGY ESP EST FIN FRA GAB GBR GEO
- GHA GRC HKG HUN IDN IND IRL IRN ISL ISR ITA JOR JPN KAZ KEN KHM
- KOR KWT LKA LTU LVA MAC MAR MEX MLT MMR MNG MYS NGA NIC NLD NOR
- NPL NZL PAK PER PHL POL PRI PRT PRY PSE QAT ROU RUS SAU SEN SGP
- SOM SRB SVK SWE THA TUN TUR TWN TZA UGA UKR USA UZB VNM YEM ZAF
- XKX
-`.trim().split(/\s+/));
+const starredCodes = new Set(JSON.parse(readFileSync('docs/star-coverage.json', 'utf8')).codes);
const sourcePath = process.argv[2];
if (!sourcePath) throw new Error('Usage: node scripts/generate-star-coverage-map.mjs <Natural Earth GeoJSON>');
-if (starredCodes.size !== 99) throw new Error(`Expected 99 regions, found ${starredCodes.size}`);
+if (starredCodes.size < 99) throw new Error(`Coverage cannot fall below the 99-region baseline: ${starredCodes.size}`);
const { features } = JSON.parse(readFileSync(sourcePath, 'utf8'));
const width = 1120;
@@ -101,7 +92,7 @@ const markers = [
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" role="img" aria-labelledby="title desc">
<title id="title">OpenCreator Star coverage around the world</title>
- <desc id="desc">At least 99 countries and regions with GitHub users who have starred OpenCreator are highlighted.</desc>
+ <desc id="desc">At least ${starredCodes.size} countries and regions with GitHub users who have starred OpenCreator are highlighted.</desc>
<rect width="${width}" height="${height}" rx="12" fill="#edf5f4"/>
<g fill="none" stroke="#d8e9e6" stroke-width="1">
${grid}
diff --git a/scripts/update-star-coverage.mjs b/scripts/update-star-coverage.mjs
new file mode 100644
index 00000000..56c2c4da
--- /dev/null
+++ b/scripts/update-star-coverage.mjs
@@ -0,0 +1,176 @@
+import { readFileSync, writeFileSync } from 'node:fs';
+import { spawnSync } from 'node:child_process';
+import { pathToFileURL } from 'node:url';
+
+const readmePaths = ['README.md', ...['zh', 'ja', 'ko', 'id', 'es', 'fr', 'de', 'pt', 'ru', 'ar', 'th']
+ .map(locale => `docs/${locale}/README.md`)];
+
+const query = `
+ query StarLocations($cursor: String) {
+ repository(owner: "krillinai", name: "OpenCreator") {
+ stargazers(first: 100, after: $cursor) {
+ totalCount
+ pageInfo { hasNextPage endCursor }
+ edges { node { location } }
+ }
+ }
+ }
+`;
+
+const normalize = value => value.normalize('NFKD')
+ .replace(/\p{M}/gu, '')
+ .replace(/\p{Regional_Indicator}/gu, '')
+ .toLowerCase()
+ .replace(/[^\p{L}\p{N}]+/gu, ' ')
+ .trim();
+
+export function createCountryLookup(features) {
+ const lookup = new Map();
+ const validCodes = new Set();
+ const displayNames = ['en', 'zh', 'ja', 'ko', 'id', 'es', 'fr', 'de', 'pt', 'ru', 'ar', 'th']
+ .map(locale => new Intl.DisplayNames([locale], { type: 'region' }));
+ const add = (name, code) => {
+ if (!name) return;
+ const key = normalize(name);
+ if (!key) return;
+ if (!lookup.has(key)) lookup.set(key, code);
+ else if (lookup.get(key) !== code) lookup.set(key, null);
+ };
+
+ for (const { properties } of features) {
+ if (properties.ADMIN === 'Antarctica') continue;
+ const code = properties.ADMIN === 'Kosovo' ? 'XKX'
+ : properties.ISO_A3 === '-99' ? properties.ADM0_A3 : properties.ISO_A3;
+ validCodes.add(code);
+ for (const name of [properties.ADMIN, properties.NAME, properties.NAME_LONG, properties.FORMAL_EN]) {
+ add(name, code);
+ }
+ add(properties.ISO_A3, code);
+ const twoLetterCode = [properties.ISO_A2, properties.ISO_A2_EH]
+ .find(value => /^[A-Z]{2}$/.test(value));
+ if (twoLetterCode) {
+ for (const names of displayNames) add(names.of(twoLetterCode), code);
+ }
+ }
+
+ const aliases = {
+ USA: ['USA', 'US', 'U.S.A.', 'America'],
+ GBR: ['UK', 'U.K.', 'Britain', 'England', 'Scotland', 'Wales'],
+ ARE: ['UAE'],
+ KOR: ['South Korea'],
+ PRK: ['North Korea'],
+ CHN: ['PRC', 'Mainland China'],
+ CIV: ['Ivory Coast'],
+ CZE: ['Czech Republic'],
+ COD: ['DR Congo', 'DRC'],
+ COG: ['Republic of the Congo'],
+ XKX: ['Kosovo']
+ };
+ for (const [code, names] of Object.entries(aliases)) {
+ if (!validCodes.has(code)) continue;
+ for (const name of names) add(name, code);
+ }
+ return lookup;
+}
+
+export function countryFromLocation(location, lookup) {
+ if (!location) return null;
+ const segments = location.split(/[,;/|]/).reverse();
+ for (const segment of segments) {
+ const key = normalize(segment).replace(/^(?:based in|living in|from) /, '');
+ const code = lookup.get(key);
+ if (code) return code;
+ }
+ return null;
+}
+
+export async function collectCoverage(fetchPage, lookup, baseline) {
+ const codes = new Set(baseline);
+ let cursor = null;
+ let fetched = 0;
+ let totalCount = 0;
+ for (let page = 0; page < 1000; page++) {
+ const result = await fetchPage(cursor);
+ if (!result || !Array.isArray(result.edges) || !result.pageInfo) {
+ throw new Error('Incomplete GitHub stargazer response');
+ }
+ if (page === 0) totalCount = result.totalCount;
+ fetched += result.edges.length;
+ if ((page + 1) % 20 === 0) console.log(`Checked ${fetched} stargazers...`);
+ for (const edge of result.edges) {
+ const code = countryFromLocation(edge.node?.location, lookup);
+ if (code) codes.add(code);
+ }
+ if (!result.pageInfo.hasNextPage) {
+ if (fetched < totalCount) throw new Error(`Only fetched ${fetched} of ${totalCount} stargazers`);
+ return { codes, fetched };
+ }
+ if (!result.pageInfo.endCursor || result.pageInfo.endCursor === cursor || !result.edges.length) {
+ throw new Error('GitHub stargazer pagination stalled');
+ }
+ cursor = result.pageInfo.endCursor;
+ }
+ throw new Error('GitHub stargazer pagination exceeded 1000 pages');
+}
+
+export function updateReadmeCount(content, oldCount, newCount) {
+ const mapIndex = content.indexOf('star-coverage-map.svg');
+ if (mapIndex < 0) throw new Error('Star coverage map missing from README');
+ const paragraphStart = content.lastIndexOf('<p>', mapIndex);
+ const paragraphEnd = content.indexOf('</p>', paragraphStart) + 4;
+ if (paragraphStart < 0 || paragraphEnd > mapIndex || paragraphEnd < 4) {
+ throw new Error('Star coverage count paragraph missing from README');
+ }
+ const paragraph = content.slice(paragraphStart, paragraphEnd);
+ const numbers = paragraph.match(/\d+/g);
+ if (numbers?.length !== 1 || Number(numbers[0]) !== oldCount) {
+ throw new Error(`Expected one star coverage count of ${oldCount}`);
+ }
+ return content.slice(0, paragraphStart)
+ + paragraph.replace(/\d+/, String(newCount))
+ + content.slice(paragraphEnd);
+}
+
+async function fetchPage(cursor, token) {
+ const config = `header = "Authorization: Bearer ${token}"\nheader = "Content-Type: application/json"\n`;
+ const response = spawnSync('curl', [
+ '-fsS', '--retry', '6', '--retry-all-errors', '--retry-delay', '1',
+ '--connect-timeout', '10', '--max-time', '15',
+ '-K', '-', '-d', JSON.stringify({ query, variables: { cursor } }),
+ 'https://api.github.com/graphql'
+ ], { input: config, encoding: 'utf8', timeout: 130000, maxBuffer: 5 * 1024 * 1024 });
+ if (response.status !== 0) {
+ throw new Error(`GitHub GraphQL request failed: ${response.stderr.trim() || response.error?.message}`);
+ }
+ const payload = JSON.parse(response.stdout);
+ if (payload.errors?.length) throw new Error(`GitHub GraphQL: ${payload.errors[0].message}`);
+ return payload.data?.repository?.stargazers;
+}
+
+async function main() {
+ const token = process.env.GITHUB_TOKEN;
+ if (!token) throw new Error('GITHUB_TOKEN is required');
+ const sourcePath = process.argv[2];
+ if (!sourcePath) throw new Error('Usage: node scripts/update-star-coverage.mjs <Natural Earth GeoJSON>');
+ const features = JSON.parse(readFileSync(sourcePath, 'utf8')).features;
+ const lookup = createCountryLookup(features);
+ const statePath = 'docs/star-coverage.json';
+ const baseline = JSON.parse(readFileSync(statePath, 'utf8')).codes;
+ const { codes, fetched } = await collectCoverage(cursor => fetchPage(cursor, token), lookup, baseline);
+ const additions = [...codes].filter(code => !baseline.includes(code)).sort();
+ console.log(`Checked ${fetched} stargazers; ${baseline.length} known regions; ${additions.length} new regions.`);
+ if (!additions.length) return;
+
+ const next = [...codes].sort();
+ const readmes = readmePaths.map(path => ({
+ path,
+ content: updateReadmeCount(readFileSync(path, 'utf8'), baseline.length, next.length)
+ }));
+ writeFileSync(statePath, `${JSON.stringify({ codes: next }, null, 2)}\n`);
+ for (const { path, content } of readmes) writeFileSync(path, content);
+ console.log(`Added: ${additions.join(', ')}. New lower bound: ${next.length}.`);
+}
+
+if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
+ await main();
+}
diff --git a/scripts/update-star-coverage.test.mjs b/scripts/update-star-coverage.test.mjs
new file mode 100644
index 00000000..ca36a54f
--- /dev/null
+++ b/scripts/update-star-coverage.test.mjs
@@ -0,0 +1,63 @@
+import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
+import test from 'node:test';
+import { collectCoverage, countryFromLocation, createCountryLookup, updateReadmeCount } from './update-star-coverage.mjs';
+
+const features = [
+ { properties: { ADMIN: 'United States of America', NAME: 'United States of America', NAME_LONG: 'United States', ISO_A2: 'US', ISO_A3: 'USA' } },
+ { properties: { ADMIN: 'Germany', NAME: 'Germany', NAME_LONG: 'Germany', ISO_A2: 'DE', ISO_A3: 'DEU' } },
+ { properties: { ADMIN: 'Vanuatu', NAME: 'Vanuatu', NAME_LONG: 'Vanuatu', ISO_A2: 'VU', ISO_A3: 'VUT' } },
+ { properties: { ADMIN: 'Panama', NAME: 'Panama', NAME_LONG: 'Panama', ISO_A2: 'PA', ISO_A3: 'PAN' } },
+ { properties: { ADMIN: 'Vatican City', NAME: 'Vatican City', NAME_LONG: 'Vatican City', ISO_A2: 'VA', ISO_A3: 'VAT' } },
+ { properties: { ADMIN: 'Norway', NAME: 'Norway', NAME_LONG: 'Norway', ISO_A2: '-99', ISO_A2_EH: 'NO', ISO_A3: '-99', ADM0_A3: 'NOR' } },
+ { properties: { ADMIN: 'Kosovo', NAME: 'Kosovo', NAME_LONG: 'Kosovo', ISO_A2: '-99', ISO_A3: '-99', ADM0_A3: 'KOS' } }
+];
+const lookup = createCountryLookup(features);
+
+test('recognizes explicit countries and skips unresolvable locations', () => {
+ assert.equal(countryFromLocation('Berlin, Germany', lookup), 'DEU');
+ assert.equal(countryFromLocation('Remote | USA', lookup), 'USA');
+ assert.equal(countryFromLocation('Vanuatu', lookup), 'VUT');
+ assert.equal(countryFromLocation('Panama', lookup), 'PAN');
+ assert.equal(countryFromLocation('Oslo, Norway', lookup), 'NOR');
+ assert.equal(countryFromLocation('Richmond, VA', lookup), null);
+ assert.equal(countryFromLocation('Philadelphia, PA', lookup), null);
+ assert.equal(countryFromLocation('Kosovo', lookup), 'XKX');
+ assert.equal(countryFromLocation('Somewhere on Earth', lookup), null);
+ assert.equal(countryFromLocation(null, lookup), null);
+});
+
+test('collects every page and keeps previously verified coverage', async () => {
+ const seen = [];
+ const pages = [
+ { totalCount: 3, edges: [{ node: { location: 'Germany' } }, { node: { location: null } }], pageInfo: { hasNextPage: true, endCursor: 'next' } },
+ { totalCount: 3, edges: [{ node: { location: 'Vanuatu' } }], pageInfo: { hasNextPage: false, endCursor: null } }
+ ];
+ const result = await collectCoverage(async cursor => {
+ seen.push(cursor);
+ return pages.shift();
+ }, lookup, ['USA']);
+ assert.deepEqual(seen, [null, 'next']);
+ assert.deepEqual([...result.codes].sort(), ['DEU', 'USA', 'VUT']);
+ assert.equal(result.fetched, 3);
+});
+
+test('rejects incomplete GitHub pagination', async () => {
+ await assert.rejects(
+ collectCoverage(async () => ({ totalCount: 2, edges: [{ node: { location: 'Germany' } }], pageInfo: { hasNextPage: false, endCursor: null } }), lookup, []),
+ /Only fetched 1 of 2/
+ );
+});
+
+test('updates the coverage count in every README without touching other text', () => {
+ const count = JSON.parse(readFileSync('docs/star-coverage.json', 'utf8')).codes.length;
+ const files = ['README.md', ...['zh', 'ja', 'ko', 'id', 'es', 'fr', 'de', 'pt', 'ru', 'ar', 'th']
+ .map(locale => `docs/${locale}/README.md`)];
+ for (const file of files) {
+ const current = readFileSync(file, 'utf8');
+ const updated = updateReadmeCount(current, count, count + 1);
+ assert.ok(updated.includes('star-coverage-map.svg'), file);
+ assert.equal(updateReadmeCount(updated, count + 1, count), current, file);
+ }
+ assert.throws(() => updateReadmeCount(readFileSync(files[0], 'utf8'), count - 1, count + 1), /Expected one star coverage count/);
+});