-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sam9111/test-lint
Test lint
- Loading branch information
Showing
4 changed files
with
85 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,6 @@ branding: | |
color: purple | ||
|
||
inputs: | ||
token: | ||
description: "GitHub token" | ||
required: true | ||
default: ${{ github.token }} | ||
|
||
azure_key: | ||
description: "Azure Computer Vision API key" | ||
required: false | ||
|
@@ -25,15 +20,37 @@ inputs: | |
runs: | ||
using: "composite" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Python | ||
uses: actions/setup-python@v2 | ||
|
||
- name: Check Alt Text | ||
id: alt_text_checker | ||
run: | | ||
python ${{ github.action_path }}/alt_text_checker.py ${{ github.workspace }} | ||
shell: bash | ||
|
||
- name: Install dependencies | ||
if: steps.alt_text_checker.outputs.result == 'true' | ||
run: | | ||
pip install -r ${{ github.action_path }}/requirements.txt | ||
shell: bash | ||
|
||
- name: Suggest Alt Text | ||
if: steps.alt_text_checker.outputs.result == 'true' | ||
run: | | ||
python ${{ github.action_path }}/alt_text.py ${{inputs.token}} ${{inputs.azure_key}} ${{inputs.azure_endpoint}} ${{inputs.language}} | ||
python ${{ github.action_path }}/alt_text.py ${{ github.workspace }} ${{inputs.azure_key}} ${{inputs.azure_endpoint}} ${{inputs.language}} | ||
git config user.name github-actions | ||
git config user.email [email protected] | ||
git add . | ||
git commit -m "Suggest alt text for images" | ||
git push | ||
shell: bash | ||
|
||
- uses: DavidAnson/markdownlint-cli2-action@v10 | ||
continue-on-error: true | ||
with: | ||
command: fix | ||
globs: "**/*.md" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
import re | ||
import sys | ||
|
||
|
||
def has_image_without_alt(file_path): | ||
with open(file_path, 'r') as f: | ||
content = f.read() | ||
|
||
# Match all markdown images with empty alt text | ||
matches = re.findall(r'\!\[(.*?)\]\((.*?)\)(?!\(|\w)', content) | ||
for match in matches: | ||
alt_text = match[0] | ||
if not alt_text: | ||
return True | ||
|
||
# Match all img tags with empty alt attribute | ||
pattern = re.compile(r'<img.*?>', re.S) | ||
result = pattern.findall(content) | ||
|
||
for i in result: | ||
alt = re.findall(r'alt="(.*?)"', i) | ||
if not alt: | ||
return True | ||
|
||
return False | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
repo_path = sys.argv[1] | ||
|
||
md_files_without_alt = [] | ||
|
||
for root, dirs, files in os.walk(repo_path): | ||
for filename in files: | ||
if filename.endswith('.md'): | ||
file_path = os.path.join(root, filename) | ||
if has_image_without_alt(file_path): | ||
md_files_without_alt.append(file_path) | ||
|
||
if md_files_without_alt: | ||
print("The following Markdown files contain images without alt text:") | ||
for file_path in md_files_without_alt: | ||
print(file_path) | ||
|
||
result = 'true' | ||
else: | ||
print("All Markdown files have alt text for their images.") | ||
result = 'false' | ||
|
||
with open(os.environ['GITHUB_OUTPUT'], 'w') as output_file: | ||
output_file.write(f'result={result}\n') |