Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/check-md-links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Check links in markdown files

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "*" ]

jobs:
check-md-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Check md files in root directory
run: python3 scripts/check-md-files.py -d . -i external
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ E.g. if `--metrics-filter = "cwnd/.*"`, NoNS measures only CWND values, if `--me

## Resuls of simulations

Metrics of all simulation runs deploys to [gihub pages](https://cloud-storage-team.github.io/algnet/main). If you want to see results on all branches, visit [root site](https://cloud-storage-team.github.io/algnet).
Metrics and results of load testing of all simulation runs deploys to [gihub pages](https://cloud-storage-team.github.io/algnet)
2 changes: 1 addition & 1 deletion configuration_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ links:

### Examples images

[Images](images) of topologies are generated using the [generate.py](images/generator.py) script.
You may generate images of topologies using the [generator](../scripts/generate_image.py) script.
55 changes: 55 additions & 0 deletions scripts/check-md-files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import argparse
import os
import sys
import subprocess

SCRIPT_DIR_PATH = os.path.dirname(__file__)
CHECK_SCRIPT = os.path.join(SCRIPT_DIR_PATH, "check-md-links.py")

# Return true or false
def main(dir : str, ignore_prefix : str):
incorrect_files = []
for root, dirs, files in os.walk(dir):
relpath = os.path.relpath(root, dir)
for file in files:
if not file.endswith('.md'):
continue
if relpath.startswith(ignore_prefix):
continue

file = os.path.join(relpath, file)

print(f"Start to check file {file}:")

run_args = [
"python3",
CHECK_SCRIPT,
"-f",
file
]

print(f"args: {run_args}")
result = subprocess.run(run_args, capture_output=True, text=True, check=False)
print(result.stdout)
if result.returncode != 0:
incorrect_files.append((file, result.stderr))
if len(incorrect_files) == 0:
print("All mardown files are correct!")
return True
print("Check failed for those files:", file=sys.stderr)
for file, stderr in incorrect_files:
print(f"File: {file}", file=sys.stderr)
print("stderr:", file=sys.stderr)
print(stderr, file=sys.stderr)
print("==================================", file=sys.stderr)
return False

if __name__== "__main__":
parser = argparse.ArgumentParser(
description="Check are all mardown files in given directory and its subdirectories are correct"
)
parser.add_argument("-d", "--directory", help="Path to the directory to be checked", required=True)
parser.add_argument("-i", "--ignore_prefix", help="Directories prefix", required=True)
args = parser.parse_args()
if not main(args.directory, args.ignore_prefix):
exit(-1)
60 changes: 60 additions & 0 deletions scripts/check-md-links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import re
import requests
import os
import argparse
import sys

# Returns true if all links are correct, false otherwise
def check_links_in_markdown(file_path : str):
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()

# Change directory to given file directory for
# correct check of relative lins
file_dir = os.path.dirname(file_path)
if file_dir != "":
os.chdir(file_dir)
# Regular expression matches markdown links
# Part [^\[^\(]* that repeats twice
# parses any string that do not contain [ or (
pattern = r'\[[^\[^\(]*\]\([^\[^\(]*\)'
links = re.findall(pattern, content)

incorrect_links = []

for link in links:
print()
link_path = link[link.index('(') + 1 :link.index(')')]
print(f"Processing link {link_path}")
if os.path.exists(link_path):
print(f"{link_path} is path to a file")
continue
# Check path as a link
link_url = link_path
try:
response = requests.head(link_url, allow_redirects=True)
if response.status_code != 200:
raise requests.exceptions.ConnectionError(f"Can not access to {link_url}")
print(f"{link_url} is link to an avaliable site")
except requests.exceptions.RequestException:
incorrect_links.append(link_url)
if len(incorrect_links) == 0:
print()
print("All links are correct!")
return True
print("Found incorrect links. Each of them is neither the correct path to a file nor a link to an avaliable site:", file=sys.stderr)
for link in incorrect_links:
print(f"link: {link}", file=sys.stderr)
print("====================", file=sys.stderr)
return False
def main():
parser = argparse.ArgumentParser(
description="Check that all the links in given markdown file are correct pathes to some files or the links to the avaliable sites"
)
parser.add_argument("-f", "--file", help="Path to the file to be checked", required=True)
args = parser.parse_args()
if not(check_links_in_markdown(args.file)):
exit(-1)

if __name__ == "__main__":
main()