From 6dbfba86277d94867f0c85d88da5bd453b29159f Mon Sep 17 00:00:00 2001 From: paspo Date: Fri, 25 Oct 2024 21:28:06 +0200 Subject: [PATCH 1/2] url check --- .gitea/workflows/external_links.yaml | 72 +++++++++++++++++++ .../extlinks_whitelist_patterns.list | 6 ++ 2 files changed, 78 insertions(+) create mode 100644 .gitea/workflows/external_links.yaml create mode 100644 .gitea/workflows/extlinks_whitelist_patterns.list diff --git a/.gitea/workflows/external_links.yaml b/.gitea/workflows/external_links.yaml new file mode 100644 index 0000000..651491b --- /dev/null +++ b/.gitea/workflows/external_links.yaml @@ -0,0 +1,72 @@ +--- +name: External links check + +on: + schedule: + - cron: "29 21 * * *" + pull_request: + +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 diff --git a/.gitea/workflows/extlinks_whitelist_patterns.list b/.gitea/workflows/extlinks_whitelist_patterns.list new file mode 100644 index 0000000..6caffcd --- /dev/null +++ b/.gitea/workflows/extlinks_whitelist_patterns.list @@ -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]+ -- 2.47.2 From 530bfe3a911ddbb00eeac4bc90288ecfa84244cf Mon Sep 17 00:00:00 2001 From: paspo Date: Fri, 25 Oct 2024 23:30:13 +0200 Subject: [PATCH 2/2] una volta a settimana --- .gitea/workflows/external_links.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitea/workflows/external_links.yaml b/.gitea/workflows/external_links.yaml index 651491b..6120980 100644 --- a/.gitea/workflows/external_links.yaml +++ b/.gitea/workflows/external_links.yaml @@ -3,8 +3,7 @@ name: External links check on: schedule: - - cron: "29 21 * * *" - pull_request: + - cron: "30 18 * * 2" jobs: scan: -- 2.47.2