forked from BgLUG/bglug.it
url check #2
71
.gitea/workflows/external_links.yaml
Normal file
71
.gitea/workflows/external_links.yaml
Normal file
@ -0,0 +1,71 @@
|
||||
---
|
||||
name: External links check
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "30 18 * * 2"
|
||||
|
||||
jobs:
|
||||
scan:
|
||||
name: Check all external links
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
|
||||
steps:
|
||||
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true # Fetch Hugo themes (true OR recursive)
|
||||
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
|
||||
|
||||
- name: restore resources from cache
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: |
|
||||
resources
|
||||
key: bglug-it-hugo-resources
|
||||
|
||||
- name: update git hash
|
||||
run: |
|
||||
H=$(git rev-parse --short=10 HEAD)
|
||||
echo "commit: $H"
|
||||
sed -i "s/AbbreviatedHash\:.*$/AbbreviatedHash: ${H}/" config/_default/params.yaml
|
||||
|
||||
- name: Build Hugo
|
||||
run: |
|
||||
wget -O - https://github.com/gohugoio/hugo/releases/download/v0.135.0/hugo_extended_0.135.0_linux-amd64.tar.gz | tar zxv
|
||||
./hugo --gc --minify --cleanDestinationDir
|
||||
|
||||
- name: store resources into cache
|
||||
uses: actions/cache/save@v4
|
||||
if: always() # salva in cache anche se la build fallisce
|
||||
with:
|
||||
path: |
|
||||
resources
|
||||
key: bglug-it-hugo-resources
|
||||
|
||||
- name: parse all the links
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Calculating a list of URLs"
|
||||
grep --ignore-case --recursive --only-matching --no-filename \
|
||||
--include \*.html --perl-regexp '(?<=href=")[^"]*' public/ | \
|
||||
grep ^http | \
|
||||
grep --invert-match --extended-regexp \
|
||||
--file .gitea/workflows/extlinks_whitelist_patterns.list | \
|
||||
sort -u > all_links.list
|
||||
echo "List contains $(cat all_links.list | wc -l) URLs"
|
||||
unreachable_count=0
|
||||
while IFS= read -r url; do
|
||||
response_code=$(curl --head --silent --output /dev/null --retry 2 --connect-timeout 2 --write-out "%{http_code}" "$url" || true)
|
||||
if [[ ! $response_code == 200 && ! $response_code =~ 3[0-9]{2} ]]; then
|
||||
echo "UNREACHABLE ($response_code): $url"
|
||||
unreachable_count=$((unreachable_count+1))
|
||||
fi
|
||||
done < all_links.list
|
||||
echo "List parsed. Unreachable URLs: $unreachable_count"
|
||||
if [[ $unreachable_count -gt 0 ]] ; then
|
||||
exit 1
|
||||
fi
|
6
.gitea/workflows/extlinks_whitelist_patterns.list
Normal file
6
.gitea/workflows/extlinks_whitelist_patterns.list
Normal file
@ -0,0 +1,6 @@
|
||||
https?\:\/\/localhost
|
||||
https?\:\/\/(www\.)?bglug\.it
|
||||
https\:\/\/git\.libreschool\.org\/BgLUG\/bglug\.it\/src
|
||||
https?\:\/\/192\.168\.[0-9]+\.[0-9]+
|
||||
https?\:\/\/172\.16\.[0-9]+\.[0-9]+
|
||||
https?\:\/\/10\.[0-9]+\.[0-9]+\.[0-9]+
|
Loading…
x
Reference in New Issue
Block a user