-
Notifications
You must be signed in to change notification settings - Fork 3
90 lines (77 loc) · 2.68 KB
/
check-mirrors.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# This workflow checks if a mirror is offline or out-of-dated.
#
name: Check Mirrors
on:
push:
branches: [fix-check-mirrors]
# uncomment the 'pull_request' line to enable testing in PRs
# pull_request:
schedule:
# Cron job at 00:00 on first day of month.
- cron: '0 0 1 * *'
jobs:
check-mirror:
name: Check Mirrors
runs-on: ubuntu-latest
steps:
- name: Check if a mirror if offline or outdated
shell: python
id: check
run: |
import os
from datetime import datetime
import requests
mirrorlist = [
"oceania",
"brasil",
"australia",
"china",
"sdsc-opentopography",
"noaa",
"portugal",
"singapore",
"south-africa",
]
error = 0
report = "| Mirror | Status | LastMod |\n"
report += "|---|---|---|\n"
for mirror in mirrorlist:
mirror_url = f"http://{mirror}.generic-mapping-tools.org"
print(stderr, f"Checking {mirror_url}")
try:
r = requests.get(f"{mirror_url}/gmt_data_server.txt", headers={"User-Agent": "Mozilla/5.0"})
except requests.exceptions.ConnectionError:
print("ConnectionError exception"
error += 1
report += f"| [{mirror}]({mirror_url}) | Offline? | NA |\n"
continue
if r.status_code != 200: # Fail to get the file
print(f"Status code is {r.status_code}")
error += 1
report += f"| [{mirror}]({mirror_url}) | Offline? | NA |\n"
continue
lastmod = datetime.strptime(r.headers["Last-Modified"], "%a, %d %b %Y %H:%M:%S GMT")
if mirror == "oceania":
lastmod_ref = lastmod
days = (lastmod_ref - lastmod).days
if days > 14: # 14 days behind the oceanic server
error += 1
report += f"| [{mirror}]({mirror_url}) | Online | {days} days|\n"
# There are errors. Write the report!
if error:
with open("report.md", "w") as f:
f.write(report)
# output the error code
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print(f"error={error}", file=fh)
cat report.md
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
#- name: Create Issue From File
# uses: peter-evans/create-issue-from-file@v4
# with:
# title: Status of GMT mirrors on ${{ steps.date.outputs.date }}
# content-filepath: report.md
# if: steps.check.outputs.error != 0