get-runner-geoip.ts 802 B

123456789101112131415161718192021222324252627282930
  1. import { $$fetch } from './fetch-retry';
  2. export interface RunnerGeoIP {
  3. ip: string,
  4. country: string,
  5. region: string,
  6. city: string,
  7. asn: number,
  8. asOrg: string,
  9. longitude: number,
  10. latitude: number,
  11. timezone: string,
  12. cfEdgeIP: string
  13. }
  14. /**
  15. * Fetch the current machine's egress IP and geo info. Used to confirm that
  16. * each matrix shard landed on a different GitHub-hosted runner region / egress
  17. * IP — the premise that lets sharding spread DoH load and dodge rate limits.
  18. *
  19. * Returns `null` on any failure so it never aborts the actual domain check.
  20. */
  21. export async function getRunnerGeoIP(): Promise<RunnerGeoIP | null> {
  22. try {
  23. const res = await $$fetch('https://ip.api.skk.moe/cf-geoip');
  24. return await res.json() as RunnerGeoIP;
  25. } catch {
  26. return null;
  27. }
  28. }