Skip to content

Commit 0d16e99

Browse files
authored
feat(check-links): add cron job check compatibilty links (#6423)
Signed-off-by: samzong <[email protected]>
1 parent 6fd0d48 commit 0d16e99

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Check Compatibility Links
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0' # 每周日午夜运行
6+
workflow_dispatch: # 支持手动触发
7+
8+
jobs:
9+
check-links:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: '3.x'
18+
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install requests pyyaml tabulate
23+
24+
- name: Check links
25+
run: |
26+
python scripts/check_links.py > check-results.txt
27+
env:
28+
DOCS_BASE_URL: "https://docs.daocloud.io"
29+
30+
- name: Create issue
31+
uses: peter-evans/create-issue-from-file@v5
32+
with:
33+
title: 'Compatibility Links Check Report'
34+
content-filepath: ./check-results.txt
35+
labels: |
36+
report
37+
automated-check

scripts/check_links.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import yaml
3+
import requests
4+
from datetime import datetime
5+
from tabulate import tabulate
6+
7+
def check_url(base_url, path):
8+
url = f"{base_url}{path}"
9+
try:
10+
resp = requests.get(url, timeout=10, allow_redirects=True)
11+
return resp.status_code < 400, resp.status_code
12+
except requests.RequestException:
13+
return False, 0
14+
15+
def main():
16+
with open('resources/links-on-ui.yaml', 'r') as f:
17+
config = yaml.safe_load(f)
18+
19+
base_url = os.getenv('DOCS_BASE_URL', 'https://docs.daocloud.io')
20+
results = []
21+
22+
for url in config.get('compatibility_links', []):
23+
cn_valid, cn_code = check_url(base_url, url)
24+
en_valid, en_code = check_url(f"{base_url}/en", url)
25+
26+
cn_url = f"{base_url}{url}"
27+
en_url = f"{base_url}/en{url}"
28+
29+
cn_status = '✅' if cn_valid else f'❌ ({cn_code})'
30+
en_status = '✅' if en_valid else f'❌ ({en_code})'
31+
32+
# If both are wrong, use cn_url; if only English, use en_url
33+
if not cn_valid and not en_valid:
34+
formatted_url = f"[{url}]({cn_url})"
35+
elif not en_valid:
36+
formatted_url = f"[{url}]({en_url})"
37+
else:
38+
formatted_url = f"[{url}]({cn_url})"
39+
40+
print(formatted_url, cn_status, en_status)
41+
results.append([formatted_url, cn_status, en_status])
42+
43+
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
44+
report = [
45+
f"# Compatibility Links Check Report\n",
46+
f"Check Time: {current_time}\n",
47+
"## Results\n\n",
48+
tabulate(
49+
results,
50+
headers=['URL', 'Chinese', 'English'],
51+
tablefmt='github'
52+
)
53+
]
54+
55+
print('\n'.join(report))
56+
57+
if __name__ == '__main__':
58+
main()

0 commit comments

Comments
 (0)