Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
public-apis
Commits
2e9088ec
Commit
2e9088ec
authored
Jul 12, 2017
by
Dave Machado
Browse files
Integrate link validation into CI
parent
708f4b7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
build/main.sh
View file @
2e9088ec
...
@@ -3,7 +3,7 @@ echo "running format validation..."
...
@@ -3,7 +3,7 @@ echo "running format validation..."
./validate_format.rb ../README.md
./validate_format.rb ../README.md
if
[[
$?
!=
0
]]
;
then
if
[[
$?
!=
0
]]
;
then
echo
"format validation failed!"
echo
"format validation failed!"
exit
$?
exit
1
else
else
echo
"format validation passed!"
echo
"format validation passed!"
fi
fi
...
@@ -13,7 +13,7 @@ if [ "$TRAVIS_BRANCH" == "master" ]; then
...
@@ -13,7 +13,7 @@ if [ "$TRAVIS_BRANCH" == "master" ]; then
./validate_links.rb ../README.md
./validate_links.rb ../README.md
if
[[
$?
!=
0
]]
;
then
if
[[
$?
!=
0
]]
;
then
echo
"link validation failed!"
echo
"link validation failed!"
exit
$?
exit
1
else
else
echo
"link validation passed!"
echo
"link validation passed!"
fi
fi
...
...
build/validate_links.rb
View file @
2e9088ec
#!/usr/bin/env ruby
#!/usr/bin/env ruby
require
'httparty'
require
'httparty'
require
'ruby-progressbar'
require
'uri'
require
'uri'
allowed_codes
=
[
200
,
302
,
403
]
allowed_codes
=
[
200
,
302
,
403
]
args
=
ARGV
args
=
ARGV
filename
=
args
[
0
]
filename
=
args
[
0
]
fail_flag
=
false
contents
=
File
.
open
(
filename
,
'rb'
)
{
|
f
|
f
.
read
}
contents
=
File
.
open
(
filename
,
'rb'
)
{
|
f
|
f
.
read
}
raw_links
=
URI
.
extract
(
contents
,
[
'http'
,
'https'
])
raw_links
=
URI
.
extract
(
contents
,
[
'http'
,
'https'
])
# Remove trailing ')' from entry URLs
# Remove trailing ')' from entry URLs
...
@@ -23,40 +23,43 @@ if dup.uniq.length > 0
...
@@ -23,40 +23,43 @@ if dup.uniq.length > 0
dup
.
uniq
.
each
do
|
e
|
dup
.
uniq
.
each
do
|
e
|
fails
.
push
(
"Duplicate link:
#{
e
}
"
)
fails
.
push
(
"Duplicate link:
#{
e
}
"
)
end
end
fail_flag
=
true
end
end
# Remove any duplicates from array
# Remove any duplicates from array
links
=
links
.
uniq
links
=
links
.
uniq
count
=
0
count
=
0
total
=
links
.
length
total
=
links
.
length
progressbar
=
ProgressBar
.
create
(
:total
=>
total
)
# GET each link and check for valid response code from allowed_codes
# GET each link and check for valid response code from allowed_codes
links
.
each
do
|
link
|
links
.
each
do
|
link
|
begin
begin
count
+=
1
count
+=
1
puts
"(
#{
count
}
/
#{
total
}
)
#{
link
}
"
res
=
HTTParty
.
get
(
link
,
timeout:
10
)
res
=
HTTParty
.
get
(
link
,
timeout:
10
)
if
res
.
code
.
nil?
fails
.
push
(
"(NIL):
#{
link
}
"
)
next
end
if
!
allowed_codes
.
include?
(
res
.
code
)
if
!
allowed_codes
.
include?
(
res
.
code
)
fails
.
push
(
"(
#{
res
.
code
}
):
#{
link
}
"
)
fails
.
push
(
"(
#{
res
.
code
}
):
#{
link
}
"
)
fail_flag
=
true
else
puts
"
\t
(
#{
res
.
code
}
)"
end
end
rescue
Net
::
ReadTimeout
fails
.
push
(
"(TMO):
#{
link
}
"
)
rescue
OpenSSL
::
SSL
::
SSLError
fails
.
push
(
"(SSL):
#{
link
}
"
)
rescue
SocketError
fails
.
push
(
"(SOK):
#{
link
}
"
)
rescue
rescue
puts
"FAIL: (
#{
res
.
code
}
)
#{
link
}
"
fails
.
push
(
"(ERR):
#{
link
}
"
)
fails
.
push
(
"(
#{
res
.
code
}
):
#{
link
}
"
)
fail_flag
=
true
end
end
progressbar
.
increment
end
end
puts
"
#{
count
}
/
#{
total
}
links checked"
if
fails
.
length
<=
0
if
fails
.
length
<=
0
puts
"all links valid"
puts
"all links valid"
exit
(
0
)
else
else
puts
"-- RESULTS --"
puts
"-- RESULTS --"
end
fails
.
each
do
|
e
|
fails
.
each
do
|
e
|
puts
e
puts
e
end
end
if
fail_flag
exit
(
1
)
exit
(
1
)
else
exit
(
0
)
end
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment