Skip to content

Commit b4a338c

Browse files
author
Ofir Gordon
committed
test links checker
1 parent 32791b2 commit b4a338c

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

.github/workflows/link_checker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ concurrency:
1717

1818
jobs:
1919
link-checker:
20+
if: github.repository == 'sony/model_optimization'
2021
runs-on: ubuntu-latest
2122
steps:
2223
- uses: actions/checkout@v4

tests/doc_tests/test_docs_links.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
import time
15+
import os
1616
import unittest
1717
import subprocess
1818
from shutil import rmtree
@@ -30,23 +30,36 @@ class TestDocsLinks(unittest.TestCase):
3030

3131
@staticmethod
3232
def check_link(_url, branch_name):
33-
headers = {'User-Agent': 'Mozilla/5.0'}
34-
try:
35-
response = requests.get(_url, headers=headers, timeout=1)
36-
print(f"[{response.status_code}] {_url}")
33+
if 'sony/model_optimization' in _url:
34+
index = _url.find(f"/{branch_name}/")
3735

38-
if response.status_code == 200:
39-
return True
40-
except Exception as e:
41-
print(f"Error checking link '{_url}': {e}")
36+
if index != -1:
37+
link_path = _url[index + len("/main/"):]
38+
print(link_path)
39+
else:
40+
print("The substring 'main' was not found.")
41+
raise Exception()
4242

43-
try:
44-
_url = _url.replace('/main/', f'/{branch_name}/')
45-
response = requests.get(_url)
46-
if response.status_code == 200:
47-
return True
48-
except Exception as e:
49-
print(f"Error checking link '{_url}': {e}")
43+
repo_root = f'https://github.com/sony/model_optimization/blob/{branch_name}/'
44+
abs_path = os.path.join(repo_root, link_path)
45+
46+
assert os.path.isfile(abs_path), f"Missing file: {link_path}"
47+
else:
48+
try:
49+
response = requests.head(_url)
50+
print(f"[{response.status_code}] {_url}")
51+
if response.status_code == 200:
52+
return True
53+
except Exception as e:
54+
print(f"Error checking link '{_url}': {e}")
55+
56+
# try:
57+
# _url = _url.replace('/main/', f'/{branch_name}/')
58+
# response = requests.get(_url)
59+
# if response.status_code == 200:
60+
# return True
61+
# except Exception as e:
62+
# print(f"Error checking link '{_url}': {e}")
5063

5164
return False
5265

0 commit comments

Comments
 (0)