Skip to content

Link Verifier Changes #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 5, 2023
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
53 changes: 47 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,61 @@ jobs:
config: ./memory_statistics_config.json
output: ./size_table_new.html
check_against: ./size_table_expected.html

test-link-verifier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup python environment
uses: actions/setup-python@v2
uses: actions/setup-python@v3

- env:
stepName: "Functional | Success | Link Verifier Works & Excludes Directory"
name: ${{ env.stepName }}
id: link-verifier-success-case
uses: ./link-verifier
with:
python-version: '3.11.0'
- name: Test link verifier action
path: ./
exclude-dirs: complexity, formatting, badFiles
allowlist-file: link-verifier/badUrls.md

- env:
stepName: "Functional | Success | Link being Excluded"
name: ${{ env.stepName }}
id: link-verifier-exclude-url-success-case
uses: ./link-verifier
with:
path: ./
exclude-dirs: complexity,formatting
include-file-types: .c,.html
exclude-dirs: complexity, formatting
exclude-urls: https://dummy-url.com/ota.bin, https://dummy-url.com/ota.com, https://dummy-url-three.com/ota.bin, https://github.com/FreeRTOS/A-Repo-That-Wins-You-The-Lottery

- env:
stepName: "Functional | Failure | Link Does Not Exist"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test not just a subset of Functional | Success | Link Verifier Works & Excludes Directory? Looks like both are checking the same badUrls.md file

name: ${{ env.stepName }}
id: link-verifier-fail-case
continue-on-error: true
uses: ./link-verifier
with:
path: ./
exclude-dirs: complexity, formatting

- env:
stepName: Check Failure Test Case
name: ${{ env.stepName }}
id: check-failure-test-cases
shell: bash
run: |
# ${{ env.stepName }}
exitStatus=0
if [ "${{ steps.link-verifier-fail-case.outcome}}" = "failure" ]; then
echo -e "${{ env.bashPass }} Functional | Failure | Link Does Not Exist | Had Expected "failure" ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} Functional | Failure | Link Does Not Exist | Had Unexpected "success" ${{ env.bashEnd }}"
exitStatus=1
fi
exit $exitStatus

test-manifest-verifier:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 5 additions & 0 deletions link-verifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ The `--user-agent` option allows specifying a specific user agent string to be u
| `-k`, `--keep` | *None* | Option to keep temporary HTML files instead of deleting them. Only useful for debugging. |
| `-v`, `--verbose` | *None* | Increase verbosity to print all files and links tested, instead of only errors. |
| `-u`, `--user-agent`| A User-Agent string | User agent string to use for HTTP requests. |

## Tests
The various files that live inside of this directory are used in the PR checks
for this repository. The relevant tests for this action can be found inside of
[test.yml](../.github/workflows/test.yml)
89 changes: 68 additions & 21 deletions link-verifier/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,112 @@ inputs:
include-file-types:
description: 'Comma-separated list of file type patters in repository to test. (Eg .c, .h)'
required: false
default: '.c .h .dox'
default: '.c, .h, .dox, .md, .html'
allowlist-file:
description: 'Path to file containing allowlist of URLs.'
required: false
default: ''
exclude-urls:
description: 'Comma separated list of URLS not to check'
required: false
user-agent:
description: 'User agent string to use when making http requests.'
required: false
default: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36'
runs:
using: "composite"
steps:
- name: Install pandoc
- name: Setup Python for link verifier action
uses: actions/setup-python@v3

- env:
# The bash escape character is \033
# At time of writing, you can't add a global environment
# to an action file. If this gets changed please move this
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
stepName: Install Dependencies
name: ${{ env.stepName }}
shell: bash
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"

wget https://github.com/jgm/pandoc/releases/download/2.11/pandoc-2.11-1-amd64.deb -O pandoc.deb
sudo dpkg -i pandoc.deb

rm pandoc.deb
sudo apt install debsums

sudo debsums pandoc
shell: bash
- name: Install ghcurl
run: |
sudo type -p curl >/dev/null || sudo apt install curl -y
shell: bash
- name: Install gh
run: |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null

sudo apt update
sudo apt install -y gh
shell: bash
- name: Install python dependencies
run: |
sudo apt install pandoc -y
sudo apt-get install -y python3-setuptools python3-pip

python3 -m pip install -r $GITHUB_ACTION_PATH/requirements.txt

echo -e "::endgroup::"
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd}}"

- env:
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
stepName: Check Links in Files
name: ${{ env.stepName }}
working-directory: ${{ inputs.path }}
shell: bash
- name: Run link verifier script
run: |
args="--verbose --test-markdown"
# ${{ env.stepName }}
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
args="--test-markdown"
if [ -n "${{ inputs.exclude-dirs }}" ]; then
dirs="${{ inputs.exclude-dirs }}"
dirs="${dirs//,/ }"
args+=" --exclude-dirs ${dirs}"
fi

if [ -n "${{ inputs.include-file-types }}" ]; then
file_types="${{ inputs.include-file-types }}"
file_types="${file_types//,/ }"
args+=" --include-file-types ${file_types}"
fi

if [ -n "${{ inputs.allowlist-file }}" ]; then
allowlist_file="${{ inputs.allowlist-file }}"
allowlist_file="${allowlist_file//,/ }"
args+=" --allowlist-file ${allowlist_file}"
touch allowList.txt
cat ${{ inputs.allowlist-file }} >> allowList.txt
fi

if [[ "${{ inputs.exclude-urls }}" != "" ]]; then
touch allowList.txt
exclude_urls="${{ inputs.exclude-urls }}"
exclude_urls="${exclude_urls//,/ }"
for url in ${exclude_urls[@]}; do echo -e "$url" >> allowList.txt; done
fi
echo "Running verify-links.py ${args} --user-agent \"${{ inputs.user-agent }}\""
if python3 ${GITHUB_ACTION_PATH}/verify-links.py ${args} --user-agent "${{ inputs.user-agent }}"; then
exit 0

if [ -n "${{ inputs.allowlist-file }}" ] || [ -n "${{ inputs.exclude-urls }}" ]; then
args+=" --allowlist-file allowList.txt"
fi

echo -e "${{ env.bashInfo }} Running: verify-links.py ${args} --user-agent \"${{ inputs.user-agent }}\" ${{ env.bashEnd }}"
set +e
python3 ${GITHUB_ACTION_PATH}/verify-links.py ${args} --user-agent "${{ inputs.user-agent }}";
exitStatus=$?
set -e

echo -e "::endgroup::"
if [ $exitStatus -eq 1 ]; then
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
exit 1
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
fi
shell: bash
exit $exitStatus
4 changes: 0 additions & 4 deletions link-verifier/allowlist.txt

This file was deleted.

3 changes: 3 additions & 0 deletions link-verifier/badUrls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://dummy-url.com/ota.bin
https://dummy-url.com/ota.com
https://dummy-url-three.com/ota.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# I am a test file to make sure the regex name replacement only replaces files
# that end in .md, not all files with md in their name.
# I also exit to make sure we skip files that don't end in .[c, h, dox, md, html]
# When using the default input
# Here are two links that exist
[verify-links.py](../../verify-links.py)
[CI-CD-Github-Actions](https://github.com/FreeRTOS/CI-CD-Github-Actions]

# Here's a link that doesn't exist that should cause us to fail if searched
# But since we aren't searched by default this broken link should not cause an error
[Incredible link](https://github.com/FreeRTOS/A-Repo-That-Wins-You-The-Lottery)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# I am a test file to make sure the regex name replacement only replaces files
# that end in .md, not all files with md in their name.
# I also exit to make sure we skip files that don't end in .[c, h, dox, md, html]
# When using the default input
# Here are two links that exist
[verify-links.py](../../verify-links.py)
[CI-CD-Github-Actions](https://github.com/FreeRTOS/CI-CD-Github-Actions]

# Here's a link that doesn't exist that should cause us to fail if searched
# But since we aren't searched by default this broken link should not cause an error
[Incredible link](https://github.com/FreeRTOS/A-Repo-That-Wins-You-The-Lottery)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# I am a test file to make sure the regex name replacement only replaces files
# that end in .md, not all files with md in their name.
# I also exit to make sure we skip files that don't end in .[c, h, dox, md, html]
# When using the default input
# Here are two links that exist
[verify-links.py](../../verify-links.py)
[CI-CD-Github-Actions](https://github.com/FreeRTOS/CI-CD-Github-Actions]

# Here's a link that doesn't exist that should cause us to fail if searched
# But since we aren't searched by default this broken link should not cause an error
[Incredible link](https://github.com/FreeRTOS/A-Repo-That-Wins-You-The-Lottery)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# I am a test file to make sure the regex name replacement only
# replaces files that end in .md, not all files with md in their name.
# Here's a random link for it to test as well
[verify-links.py](../../verify-links.py)
[CI-CD-Github-Actions](https://github.com/FreeRTOS/CI-CD-Github-Actions)
5 changes: 5 additions & 0 deletions link-verifier/fileTests/goodFiles/fileWithMDIntheName.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# I am a test file to make sure the regex name replacement only
# replaces files that end in .md, not all files with md in their name.
# Here's a random link for it to test as well
[verify-links.py](../../verify-links.py)
[CI-CD-Github-Actions](https://github.com/FreeRTOS/CI-CD-Github-Actions)
8 changes: 8 additions & 0 deletions link-verifier/fileTests/goodFiles/fileWithMDIntheName.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# I am a test file to make sure the regex name replacement only replaces files
# that end in .md, not all files with md in their name.
# As this would cause the python script to fail

# When using the default input
# Here are two links that exist
[verify-links.py](../../verify-links.py)
[CI-CD-Github-Actions](https://github.com/FreeRTOS/CI-CD-Github-Actions]
2 changes: 1 addition & 1 deletion link-verifier/verify-links.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def parse_file(html_file):
return HtmlFile(html_file)

def html_name_from_markdown(filename):
md_pattern = re.compile('.md', re.IGNORECASE)
md_pattern = re.compile('\.md', re.IGNORECASE)
return md_pattern.sub('.html', filename)

def create_html(markdown_file):
Expand Down