Skip to content

Commit 0fdd8ed

Browse files
author
Felix Exner
committed
Add a URL check to CI
This way we should find our earlier if a link breaks.
1 parent 0650a0e commit 0fdd8ed

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

.github/helpers/check_urls.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
#Find URLs in code:
6+
urls=$(grep -oP "(http|ftp|https):\/\/([a-zA-Z0-9_-]+(?:(?:\.[a-zA-Z0-9_-]+)+))([a-zA-Z0-9_.,@?^=%&:\/~+#-]*[a-zA-Z0-9_@?^=%&\/~+#-])?" "$@")
7+
8+
fail_counter=0
9+
10+
FAILED_LINKS=()
11+
for item in $urls; do
12+
# echo $item
13+
filename=$(echo "$item" | cut -d':' -f1)
14+
url=$(echo "$item" | cut -d':' -f2-)
15+
echo -n "Checking $url from file $filename"
16+
if ! curl --head --silent --fail "$url" 2>&1 > /dev/null; then
17+
echo -e " \033[0;31mNOT FOUND\033[32m\n"
18+
FAILED_LINKS+=("$url from file $filename")
19+
((fail_counter=fail_counter+1))
20+
else
21+
printf " \033[32mok\033[0m\n"
22+
fi
23+
done
24+
25+
echo "Failed files:"
26+
printf '%s\n' "${FAILED_LINKS[@]}"
27+
exit $fail_counter

.github/workflows/check_links.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Check Links
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
check_links:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Check URLs
15+
run: |
16+
.github/helpers/check_urls.sh -rI \
17+
--exclude-dir=.git \
18+
--exclude-dir=build/ \
19+
--exclude=package.xml \
20+
--exclude-dir=CMakeModules \
21+
--exclude-dir=debian \
22+
--exclude=ursim_docker.rst \

0 commit comments

Comments
 (0)