Skip to content

Fix

Fix #10

Workflow file for this run

#
# 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