Skip to content

Commit 2f0aa54

Browse files
authored
Review and Format Output (#59)
- Add support for GitHub automatic annotations.
1 parent 15b9992 commit 2f0aa54

File tree

10 files changed

+113
-71
lines changed

10 files changed

+113
-71
lines changed

.github/dependabot.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
9+
# Maintain dependencies for GitHub Actions
10+
- package-ecosystem: "github-actions"
11+
directory: "/"
12+
schedule:
13+
interval: "weekly"
14+
groups:
15+
github-actions:
16+
patterns:
17+
- "*"
18+
19+
# Maintain dependencies for pip
20+
- package-ecosystem: "pip"
21+
directory: "/"
22+
schedule:
23+
interval: "weekly"
24+
groups:
25+
python-requirements:
26+
patterns:
27+
- "*"

.github/workflows/python-tests.yaml

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ permissions:
1313
contents: read
1414

1515
jobs:
16-
tests-genai-repo:
17-
name: Python Tests on generative-ai-for-beginners
16+
tests-openai-repo:
17+
name: Python Tests on azure-search-openai-demo
1818
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v4
@@ -29,26 +29,27 @@ jobs:
2929
python3 -m pip install -e .
3030
3131
- name: Clone Repo
32-
run: git clone https://github.com/microsoft/generative-ai-for-beginners
32+
run: git clone https://github.com/Azure-Samples/azure-search-openai-demo
3333

34-
- name: Test Check Broken Paths in generative-ai-for-beginners
34+
- name: Test Check Broken Paths in azure-search-openai-demo
3535
if: always()
3636
run: |
37-
cd generative-ai-for-beginners
37+
cd azure-search-openai-demo
3838
markdown-checker -d . -f check_broken_paths -gu ''
39-
- name: Test Check URLs Country locale in generative-ai-for-beginners
39+
- name: Test Check URLs Country locale in azure-search-openai-demo
4040
if: always()
4141
run: |
42-
cd generative-ai-for-beginners
42+
cd azure-search-openai-demo
4343
markdown-checker -d . -f check_urls_locale -gu ''
44-
- name: Test Check Broken URLs in generative-ai-for-beginners
44+
45+
- name: Test Check Broken URLs in azure-search-openai-demo
4546
if: always()
4647
run: |
47-
cd generative-ai-for-beginners
48+
cd azure-search-openai-demo
4849
markdown-checker -d . -f check_broken_urls -gu ''
49-
50-
tests-openai-repo:
51-
name: Python Tests on azure-search-openai-demo
50+
51+
tests-phicookbook-repo:
52+
name: Python Tests on Phi-3CookBook
5253
runs-on: ubuntu-latest
5354
steps:
5455
- uses: actions/checkout@v4
@@ -63,27 +64,26 @@ jobs:
6364
python3 -m pip install -e .
6465
6566
- name: Clone Repo
66-
run: git clone https://github.com/Azure-Samples/azure-search-openai-demo
67+
run: git clone https://github.com/microsoft/Phi-3CookBook
6768

68-
- name: Test Check Broken Paths in azure-search-openai-demo
69+
- name: Test Check Broken Paths in Phi-3CookBook
6970
if: always()
7071
run: |
71-
cd azure-search-openai-demo
72+
cd Phi-3CookBook
7273
markdown-checker -d . -f check_broken_paths -gu ''
73-
- name: Test Check URLs Country locale in azure-search-openai-demo
74+
- name: Test Check URLs Country locale in Phi-3CookBook
7475
if: always()
7576
run: |
76-
cd azure-search-openai-demo
77+
cd Phi-3CookBook
7778
markdown-checker -d . -f check_urls_locale -gu ''
78-
79-
- name: Test Check Broken URLs in azure-search-openai-demo
79+
- name: Test Check Broken URLs in Phi-3CookBook
8080
if: always()
8181
run: |
82-
cd azure-search-openai-demo
82+
cd Phi-3CookBook
8383
markdown-checker -d . -f check_broken_urls -gu ''
84-
85-
tests-phicookbook-repo:
86-
name: Python Tests on Phi-3CookBook
84+
85+
tests-markdown-checker-repo:
86+
name: Python Tests on markdown-checker
8787
runs-on: ubuntu-latest
8888
steps:
8989
- uses: actions/checkout@v4
@@ -97,21 +97,20 @@ jobs:
9797
python3 -m pip install --upgrade pip
9898
python3 -m pip install -e .
9999
100-
- name: Clone Repo
101-
run: git clone https://github.com/microsoft/Phi-3CookBook
102-
103-
- name: Test Check Broken Paths in Phi-3CookBook
100+
- name: Test Check Broken Paths in markdown-checker
104101
if: always()
105102
run: |
106-
cd Phi-3CookBook
107103
markdown-checker -d . -f check_broken_paths -gu ''
108-
- name: Test Check URLs Country locale in Phi-3CookBook
104+
- name: Test Check URLs Country locale in markdown-checker
109105
if: always()
110106
run: |
111-
cd Phi-3CookBook
112107
markdown-checker -d . -f check_urls_locale -gu ''
113-
- name: Test Check Broken URLs in Phi-3CookBook
108+
- name: Test Check Broken URLs in markdown-checker
114109
if: always()
115110
run: |
116-
cd Phi-3CookBook
117111
markdown-checker -d . -f check_broken_urls -gu ''
112+
113+
- name: Set job summary
114+
if: ${{ always() && hashFiles('./comment.md') != '' }}
115+
shell: bash
116+
run: cat ./comment.md >> $GITHUB_STEP_SUMMARY

.github/workflows/python-versions-tests.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,13 @@ jobs:
3131
- name: Clone Testing Repositories
3232
run: |
3333
git clone https://github.com/Azure-Samples/azure-search-openai-demo
34-
git clone https://github.com/microsoft/generative-ai-for-beginners
3534
git clone https://github.com/microsoft/Phi-3CookBook
3635
3736
- name: Test Check Broken Paths in azure-search-openai-demo
3837
if: always()
3938
run: |
4039
cd azure-search-openai-demo
4140
markdown-checker -d . -f check_broken_paths -gu ''
42-
- name: Test Check Broken Paths in generative-ai-for-beginners
43-
if: always()
44-
run: |
45-
cd generative-ai-for-beginners
46-
markdown-checker -d . -f check_broken_paths -gu ''
4741
- name: Test Check Broken Paths in Phi-3CookBook
4842
if: always()
4943
run: |
@@ -55,11 +49,6 @@ jobs:
5549
run: |
5650
cd azure-search-openai-demo
5751
markdown-checker -d . -f check_urls_locale -gu ''
58-
- name: Test Check URLs Country locale in generative-ai-for-beginners
59-
if: always()
60-
run: |
61-
cd generative-ai-for-beginners
62-
markdown-checker -d . -f check_urls_locale -gu ''
6352
- name: Test Check URLs Country locale in Phi-3CookBook
6453
if: always()
6554
run: |
@@ -71,11 +60,6 @@ jobs:
7160
run: |
7261
cd azure-search-openai-demo
7362
markdown-checker -d . -f check_broken_urls -gu ''
74-
- name: Test Check Broken URLs in generative-ai-for-beginners
75-
if: always()
76-
run: |
77-
cd generative-ai-for-beginners
78-
markdown-checker -d . -f check_broken_urls -gu ''
7963
- name: Test Check Broken URLs in Phi-3CookBook
8064
if: always()
8165
run: |

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ All notable changes to this project will be documented in this file.
1212

1313
### Other Changes
1414

15-
## [v0.2.0] 3 Aug 2024
15+
## [v0.2.0] 7 Aug 2024
1616
- Redesign the package.
1717
- Port to using Click instead of arg_parser.
1818
- Expose options for external users to allow for more customization.
@@ -22,6 +22,9 @@ All notable changes to this project will be documented in this file.
2222
- Analyze all web URLs except the ones in skip_domains list.
2323
- Change Syntax of terminal comments to improve readability.
2424
- Add Spinner to indicate that the tool is working (Not compatible with all terminals)
25+
- Add documentation for the new features.
26+
- Use multiprocessing for checking broken urls reducing the execution time by 50%.
27+
- Add support for GitHub automatic annotations.
2528

2629
## [v0.1.5] 8 Jul 2024
2730
- Increase timeout for requests to check web urls alive or not. https://github.com/john0isaac/markdown-checker/pull/52

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pip install markdown-checker
2323

2424
1. Run `pip install markdown-checker`.
2525
2. Run `markdown-checker -d {src} -f {func} -gu {url}`. Replace `{src}` with the directory you want to analyze, `{func}` with the available functions like `check_broken_paths`, `{gu}` with your contribution guidance full URL.
26-
3. The output will be displayed in the terminal and in a `comments.md` file.
26+
3. The output will be displayed in the terminal and in a `comment.md` file.
2727

2828
For more customizations read the docs.
2929

docs/source/advanced.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ To further customize your experience with the Markdown Checker, you can utilize
7070
### `-o`, `--output-file-name`
7171
- **Type**: `str`
7272
- **Description**: Name of the output file.
73-
- **Default**: `comments`
73+
- **Default**: `comment`
7474
- **Required**: Yes
7575

7676

docs/source/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ pip install markdown-checker
1919

2020
1. Run `pip install markdown-checker`.
2121
2. Run `markdown-checker -d {src} -f {func} -gu {url}`. Replace `{src}` with the directory you want to analyze, `{func}` with the available functions like `check_broken_paths`, `{gu}` with your contribution guidance full URL.
22-
3. The output will be displayed in the terminal and in a `comments.md` file.
22+
3. The output will be displayed in the terminal and in a `comment.md` file.

src/markdown_checker/__init__.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import concurrent.futures
8+
import os
89
import platform
910
import sys
1011
from pathlib import Path
@@ -242,7 +243,7 @@ def detect_issues(
242243
"-o",
243244
"--output-file-name",
244245
type=str,
245-
default="comments",
246+
default="comment",
246247
help="Name of the output file.",
247248
required=True,
248249
)
@@ -282,6 +283,7 @@ def main(
282283
formatted_output = ""
283284
all_files_issues: list[Union[MarkdownPath, MarkdownURL]] = []
284285
links_checked_count = 0
286+
github_ci = os.getenv("CI", "false")
285287

286288
# iterate over the files to validate the content
287289
for file_path in files_paths:
@@ -296,7 +298,10 @@ def main(
296298
)
297299
links_checked_count += links_count
298300
if len(detected_issues) > 0:
299-
formatted_output += f"| [`{file_path}`]({file_path}) |" + format_links(detected_issues)
301+
if github_ci == "true":
302+
formatted_output += f"| `{file_path}` |" + format_links(detected_issues)
303+
else:
304+
formatted_output += f"| [`{file_path}`]({file_path}) |" + format_links(detected_issues)
300305
all_files_issues.extend(detected_issues)
301306
click.echo(
302307
click.style(f"\n🔍 Checked {links_checked_count} links in {len(files_paths)} files.", fg="blue"), err=False
@@ -307,14 +312,26 @@ def main(
307312
generator.generate(func, formatted_output)
308313
click.echo(click.style(f"😭 Found {len(all_files_issues)} issues in the following files:", fg="red"), err=True)
309314
for markdown_path in all_files_issues:
310-
click.echo(
311-
click.style(
312-
f"\tFile '{markdown_path.file_path.resolve()}', line {markdown_path.line_number}"
313-
f"\n{markdown_path} {markdown_path.issue}.\n",
314-
fg="red",
315-
),
316-
err=True,
317-
)
315+
if github_ci == "true":
316+
# Ref: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-warning-message
317+
click.echo(
318+
click.style(
319+
f"::error file={markdown_path.file_path},line={markdown_path.line_number}::"
320+
f"File {markdown_path.file_path}, line {markdown_path.line_number}, "
321+
f"Link {markdown_path} {markdown_path.issue}.",
322+
fg="red",
323+
),
324+
err=True,
325+
)
326+
else:
327+
click.echo(
328+
click.style(
329+
f"\tFile '{markdown_path.file_path.resolve()}', line {markdown_path.line_number}"
330+
f"\n{markdown_path} {markdown_path.issue}.\n",
331+
fg="red",
332+
),
333+
err=True,
334+
)
318335
sys.exit(1)
319336
click.echo(click.style("All files are compliant with the guidelines. 🎉", fg="green"), err=False)
320337
sys.exit(0)

src/markdown_checker/reports/md_reports/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MarkdownGenerator(GeneratorBase):
2020

2121
def __init__(
2222
self,
23-
output_file_name: str = "comments",
23+
output_file_name: str = "comment",
2424
contributing_guide_url: str = "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md",
2525
) -> None:
2626
self.output_file_name = output_file_name

src/markdown_checker/utils/format_output.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Module to format the output of the markdown checker.
33
"""
44

5+
import os
56
from typing import Union
67

78
from markdown_checker.paths import MarkdownPath
@@ -18,13 +19,24 @@ def format_links(links: list[Union[MarkdownPath, MarkdownURL]]) -> str:
1819
Returns:
1920
formatted_links (str): The formatted string with numbered bullets.
2021
"""
21-
formatted_links = ""
22-
i = 1
23-
for link in links:
24-
if i == len(links):
25-
formatted_links += f" {i}. `{link}` |\n"
26-
else:
27-
formatted_links += f" {i}. `{link}` <br/>"
28-
i += 1
22+
formatted_links = "<table><thead><tr><th>#</th><th>Link</th><th>Line Number</th></tr></thead><tbody>"
23+
# Ref: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/variables#default-environment-variables
24+
github_ci = os.getenv("CI", "false")
25+
# repo_name = os.getenv("GITHUB_REPOSITORY", "../tree/")
26+
# branch_name = os.getenv("GITHUB_HEAD_REF", os.getenv("GITHUB_REF_NAME", "main"))
27+
# repo name is always target repo in PR not source
28+
# need more work in upcoming release
29+
if github_ci == "true":
30+
for link in range(len(links)):
31+
formatted_links += (
32+
f"<tr><td>{link + 1}</td><td>`{links[link].link}`</td><td>`{links[link].line_number}`</td></tr>"
33+
)
34+
else:
35+
for link in range(len(links)):
36+
formatted_links += (
37+
f"<tr><td>{link + 1}</td><td>`{links[link].link}`</td>"
38+
f"<td>[`{links[link].line_number}`]({links[link].file_path}#L{links[link].line_number})</td></tr>"
39+
)
2940

41+
formatted_links += "</tbody></table>|\n"
3042
return formatted_links

0 commit comments

Comments
 (0)