@@ -23,14 +23,15 @@ jobs:
23
23
- name : Check the Validity of Hyperlinks
24
24
run : |
25
25
cd ${{github.workspace}}
26
+ timeout=15 # max connect timeout
26
27
fail="FALSE"
27
28
retry="FALSE"
28
29
# url_lines=$(grep -Eo '\]\(http[s]?://[^)]+\)' --include='*.md' -r .|grep -Ev 'linkedin')
29
30
merged_commit=$(git log -1 --format='%H')
30
31
changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | awk '/\.md$/ {print $NF}')"
31
32
if [ -n "$changed_files" ]; then
32
33
for changed_file in $changed_files; do
33
- url_lines=$(grep -H -Eo '\]\(http[s]?://[^)]+\)' "$changed_file" | grep -Ev 'linkedin') || true
34
+ url_lines=$(grep -H -Eo '\]\(http[s]?://[^)]+\)' "$changed_file" | sort -u | grep -Ev 'linkedin') || true
34
35
if [ -n "$url_lines" ]; then
35
36
for url_line in $url_lines; do
36
37
url=$(echo "$url_line"|cut -d '(' -f2 | cut -d ')' -f1|sed 's/\.git$//')
@@ -39,10 +40,10 @@ jobs:
39
40
echo "Link "$url" from ${{github.workspace}}/$path need to be verified by a real person."
40
41
retry="FALSE"
41
42
else
42
- response=$(curl -L -s -o /dev/null -w "%{http_code}" "$url")
43
+ response=$(curl --connect-timeout $timeout - L -s -o /dev/null -w "%{http_code}" "$url")
43
44
if [ "$response" -ne 200 ]; then
44
45
echo "**********Validation failed, status code: $response, try again**********"
45
- response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url")
46
+ response_retry=$(curl --connect-timeout $timeout - s -o /dev/null -w "%{http_code}" "$url")
46
47
if [ "$response_retry" -eq 200 ]; then
47
48
echo "*****Retry successful*****"
48
49
else
@@ -105,15 +106,15 @@ jobs:
105
106
fail="FALSE"
106
107
repo_name=${{ github.event.pull_request.head.repo.full_name }}
107
108
if [ "$(echo "$repo_name"|cut -d'/' -f1)" != "opea-project" ]; then
108
- owner =$(echo "${{ github.event.pull_request.head.repo.full_name }}" |cut -d'/' -f1 )
109
- branch="https://github.com/$owner/docs /tree/${{ github.event.pull_request.head.ref }}"
109
+ repo_fork =$(echo "${{ github.event.pull_request.head.repo.full_name }}" |cut -d'/' -f2 )
110
+ branch="https://github.com/$repo_fork /tree/${{ github.event.pull_request.head.ref }}"
110
111
else
111
112
branch="https://github.com/opea-project/docs/blob/${{ github.event.pull_request.head.ref }}"
112
113
fi
113
114
link_head="https://github.com/opea-project/docs/blob/main"
114
115
merged_commit=$(git log -1 --format='%H')
115
116
changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | awk '/\.md$/ {print $NF}')"
116
- png_lines=$(grep -Eo '\]\([^)]+\)' --include='*.md' -r .|grep -Ev 'http'|grep -Ev 'mailto'|grep -Ev 'portal.azure.com')
117
+ png_lines=$(grep -Eo '\]\([^)]+\)' --include='*.md' -r .|sort -u| grep -Ev 'http'|grep -Ev 'mailto'|grep -Ev 'portal.azure.com')
117
118
if [ -n "$png_lines" ]; then
118
119
for png_line in $png_lines; do
119
120
refer_path=$(echo "$png_line"|cut -d':' -f1 | cut -d'/' -f2-)
@@ -138,12 +139,12 @@ jobs:
138
139
url_dev=$branch$(echo "$real_path" | sed 's|.*/docs||')$png_path
139
140
response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev")
140
141
if [ "$response" -ne 200 ]; then
141
- echo "**********Validation failed, try again**********"
142
+ echo "**********Validation failed, status code: $response, try again**********"
142
143
response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url_dev")
143
144
if [ "$response_retry" -eq 200 ]; then
144
145
echo "*****Retry successfully*****"
145
146
else
146
- echo "Invalid path from ${{github.workspace}}/$refer_path: $png_path, link: $url_dev"
147
+ echo "Status code: $response_retry => invalid path from ${{github.workspace}}/$refer_path: $png_path, link: $url_dev"
147
148
fail="TRUE"
148
149
fi
149
150
else
0 commit comments