-
Notifications
You must be signed in to change notification settings - Fork 282
Add pr hyperlink and relative link scan job #2326
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
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a05bd69
add pr hyperlink and relative link scan job
chensuyue 89c0c77
update readme for test
chensuyue 70c9480
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 12c92ba
update for fix
chensuyue a949992
update for fix
chensuyue eac46e0
for debugging
chensuyue 6cf7865
for debugging
chensuyue a3d0899
bug fix for absolute path
chensuyue 69d4b89
bug fix for path
chensuyue b4d055d
fix invalid links
chensuyue 841cd35
Merge branch 'master' into suyue/link_scan
chensuyue 62c1a66
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aa83c85
fix invalid links
chensuyue bb837b0
bug fix
chensuyue ecc52e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dd373ba
bug fix
chensuyue 750b0b3
bug fix
chensuyue f404a70
bug fix
chensuyue c6e4bad
remove log print
chensuyue 98ddbf0
fix invalid links
chensuyue 8caa586
remove sigopt support
chensuyue 776d612
add skip link
chensuyue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,157 @@ | ||
| # Copyright (C) 2025 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| name: Check hyperlinks and relative path validity | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [master] | ||
| types: [opened, reopened, ready_for_review, synchronize] | ||
|
|
||
| jobs: | ||
| check-the-validity-of-hyperlinks-in-README: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Clean Up Working Directory | ||
| run: sudo rm -rf ${{github.workspace}}/* | ||
|
|
||
| - name: Checkout Repo | ||
| uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Check the Validity of Hyperlinks | ||
| env: | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| run: | | ||
| cd ${{github.workspace}} | ||
| delay=1 | ||
| fail="FALSE" | ||
| merged_commit=$(git log -1 --format='%H') | ||
| changed_files="$(git diff --name-status --diff-filter=ARM $BASE_SHA ${merged_commit} | awk '/\.md$/ {print $NF}')" | ||
| if [ -n "$changed_files" ]; then | ||
| for changed_file in $changed_files; do | ||
| # echo $changed_file | ||
| url_lines=$(grep -H -Eo '\]\(http[s]?://[^)]+\)' "$changed_file") || true | ||
| if [ -n "$url_lines" ]; then | ||
| for url_line in $url_lines; do | ||
| # echo $url_line | ||
| url=$(echo "$url_line"|cut -d '(' -f2 | cut -d ')' -f1|sed 's/\.git$//') | ||
| path=$(echo "$url_line"|cut -d':' -f1 | cut -d'/' -f2-) | ||
| if [[ "$url" == "https://platform.openai.com/api-keys"* || "$url" == "https://ai.cloud.intel.com/" ]]; then | ||
| echo "Link "$url" from ${{github.workspace}}/$path needs to be verified by real person." | ||
| else | ||
| sleep $delay | ||
| response=$(curl -L -s -o /dev/null -w "%{http_code}" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" "$url")|| true | ||
| if [ "$response" -ne 200 ]; then | ||
| echo "**********Validation $url failed ($response), try again**********" | ||
| response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url") | ||
| if [ "$response_retry" -eq 200 ]; then | ||
| echo "*****Retry successfully*****" | ||
| else | ||
| echo "******Retry $url failed ($response_retry), add simulated browser requests******" | ||
| response_browser=$(curl -s -o /dev/null -w "%{http_code}" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" "$url") | ||
| if [ "$response_browser" -eq 200 ]; then | ||
| echo "*****Retry successfully*****" | ||
| else | ||
| echo -e "::error:: Invalid link ($response_retry) from ${{github.workspace}}/$(echo "$url_line"|cut -d':' -f1): $url" | ||
| fail="TRUE" | ||
| fi | ||
| fi | ||
| fi | ||
| fi | ||
| done | ||
| fi | ||
| done | ||
| else | ||
| echo "No changed .md file." | ||
| fi | ||
|
|
||
| if [[ "$fail" == "TRUE" ]]; then | ||
| exit 1 | ||
| else | ||
| echo "All hyperlinks are valid." | ||
| fi | ||
| shell: bash | ||
|
|
||
| check-the-validity-of-relative-path: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Clean up Working Directory | ||
| run: sudo rm -rf ${{github.workspace}}/* | ||
|
|
||
| - name: Checkout Repo | ||
| uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Checking Relative Path Validity | ||
| env: | ||
| REPO_NAME: ${{ github.event.pull_request.head.repo.full_name }} | ||
| HEAD_REF: ${{ github.event.pull_request.head.ref }} | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| run: | | ||
| cd ${{github.workspace}} | ||
| delay=1 | ||
| fail="FALSE" | ||
| branch="https://github.com/$REPO_NAME/blob/$HEAD_REF" | ||
|
|
||
| merged_commit=$(git log -1 --format='%H') | ||
| changed_files="$(git diff --name-status --diff-filter=ARM $BASE_SHA ${merged_commit} | awk '/\.md$/ {print $NF}')" | ||
| png_lines=$(grep -Eo '\]\([^)]+\)' --include='*.md' -r .|grep -Ev 'http') | ||
| if [ -n "$png_lines" ]; then | ||
| for png_line in $png_lines; do | ||
| refer_path=$(echo "$png_line"|cut -d':' -f1 | cut -d'/' -f2-) | ||
| png_path=$(echo "$png_line"|cut -d '(' -f2 | cut -d ')' -f1) | ||
|
|
||
| if [[ "${png_path:0:1}" == "/" ]]; then | ||
| check_path=$png_path | ||
chensuyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| elif [[ "$png_path" == *#* ]]; then | ||
| relative_path=$(echo "$png_path" | cut -d '#' -f1) | ||
| if [ -n "$relative_path" ]; then | ||
| check_path=$(dirname "$refer_path")/$relative_path | ||
| png_path=$(echo "$png_path" | awk -F'#' '{print "#" $2}') | ||
| else | ||
| check_path=$refer_path | ||
| fi | ||
| else | ||
| check_path=$(dirname "$refer_path")/$png_path | ||
| fi | ||
|
|
||
| if [ -e "$check_path" ]; then | ||
| real_path=$(realpath $check_path) | ||
| if [[ "$png_line" == *#* ]]; then | ||
| if [ -n "changed_files" ] && echo "$changed_files" | grep -q "^${refer_path}$"; then | ||
| url_dev=$branch$(echo "$real_path" | sed 's|.*/neural-compressor||')$png_path | ||
| sleep $delay | ||
| response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") | ||
| if [ "$response" -ne 200 ]; then | ||
| echo "**********Validation failed ($response), try again**********" | ||
| response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url_dev") | ||
| if [ "$response_retry" -eq 200 ]; then | ||
| echo "*****Retry successfully*****" | ||
| else | ||
| echo -e "::error:: Invalid path ($response_retry) from ${{github.workspace}}/$refer_path: $png_path" | ||
| fail="TRUE" | ||
| fi | ||
| else | ||
| echo "Validation succeed $png_line" | ||
| fi | ||
| fi | ||
| fi | ||
| else | ||
| echo -e "::error:: ${{github.workspace}}/$refer_path:$png_path does not exist" | ||
chensuyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fail="TRUE" | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| if [[ "$fail" == "TRUE" ]]; then | ||
| exit 1 | ||
| else | ||
| echo "All relative path are valid." | ||
| fi | ||
| shell: bash | ||
This file contains hidden or 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
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.