generated from osc/skins-template
Add .gitea/workflows/test-skins.yml
This commit is contained in:
110
.gitea/workflows/test-skins.yml
Normal file
110
.gitea/workflows/test-skins.yml
Normal file
@@ -0,0 +1,110 @@
|
||||
name: Test Skins
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
link-check:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Validate links and assets
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
RED="\033[31m"
|
||||
GREEN="\033[32m"
|
||||
RESET="\033[0m"
|
||||
|
||||
ERRORS=()
|
||||
|
||||
urldecode() {
|
||||
printf '%b' "${1//%/\\x}"
|
||||
}
|
||||
|
||||
check_http() {
|
||||
local url="$1"
|
||||
# HEAD first
|
||||
if curl -Is --max-time 10 "$url" | head -n 1 | grep -qE "HTTP/.* (200|30[0-9])"; then
|
||||
return 0
|
||||
fi
|
||||
# GET fallback
|
||||
if curl -Is --max-time 10 -X GET "$url" | head -n 1 | grep -qE "HTTP/.* (200|30[0-9])"; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
check_local() {
|
||||
local path="$1"
|
||||
path="${path#/}" # strip leading slash
|
||||
local decoded
|
||||
decoded=$(urldecode "$path")
|
||||
|
||||
if [[ ! -e "$decoded" ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
extract_links() {
|
||||
local file="$1"
|
||||
|
||||
# Markdown links
|
||||
grep -oE '\[[^]]*\]\([^)]*\)' "$file" \
|
||||
| sed -E 's/.*\((.*)\).*/\1/'
|
||||
|
||||
# Image markdown links
|
||||
grep -oE '!\[[^]]*\]\([^)]*\)' "$file" \
|
||||
| sed -E 's/.*\((.*)\).*/\1/'
|
||||
|
||||
# Raw URLs
|
||||
grep -oE 'https?://[^ )"]+' "$file"
|
||||
|
||||
# <img src="">
|
||||
grep -oE '<img[^>]*src="[^"]+"' "$file" \
|
||||
| sed -E 's/.*src="([^"]*)".*/\1/'
|
||||
|
||||
# <video src="">
|
||||
grep -oE '<video[^>]*src="[^"]+"' "$file" \
|
||||
| sed -E 's/.*src="([^"]*)".*/\1/'
|
||||
}
|
||||
|
||||
echo "🔍 Scanning Markdown files..."
|
||||
echo
|
||||
|
||||
while IFS= read -r mdfile; do
|
||||
echo "📄 Checking: $mdfile"
|
||||
|
||||
while IFS= read -r url; do
|
||||
[[ -z "$url" ]] && continue
|
||||
[[ "$url" == mailto:* ]] && continue
|
||||
|
||||
if [[ "$url" == http* ]]; then
|
||||
if ! check_http "$url"; then
|
||||
ERRORS+=("❌ Broken external link: $url (in $mdfile)")
|
||||
fi
|
||||
else
|
||||
if ! check_local "$url"; then
|
||||
ERRORS+=("❌ Missing local file: $url (in $mdfile)")
|
||||
fi
|
||||
fi
|
||||
|
||||
done < <(extract_links "$mdfile")
|
||||
|
||||
echo
|
||||
done < <(find . -type f -name '*.md')
|
||||
|
||||
if (( ${#ERRORS[@]} > 0 )); then
|
||||
echo -e "${RED}✖ Errors found:${RESET}"
|
||||
for e in "${ERRORS[@]}"; do
|
||||
echo "$e"
|
||||
done
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✔ All links OK!${RESET}"
|
||||
Reference in New Issue
Block a user