links.yml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. name: Links
  2. on:
  3. workflow_dispatch:
  4. concurrency:
  5. group: links
  6. cancel-in-progress: false
  7. jobs:
  8. links:
  9. name: Links
  10. runs-on: ubuntu-latest
  11. permissions:
  12. actions: read
  13. packages: read
  14. contents: read
  15. steps:
  16. -
  17. name: Checkout
  18. uses: actions/checkout@v6
  19. with:
  20. fetch-depth: 0
  21. -
  22. name: Validate Links
  23. run: |
  24. errors=0
  25. count=0
  26. host=""
  27. declare -A seen
  28. wget https://github.com/lwthiker/curl-impersonate/releases/download/v0.6.1/curl-impersonate-v0.6.1.x86_64-linux-gnu.tar.gz
  29. tar -xzf curl-impersonate-v0.6.1.x86_64-linux-gnu.tar.gz
  30. sudo cp curl-impersonate-ff /usr/local/bin/
  31. check() {
  32. local url="$1" http
  33. http=$(curl-impersonate-ff -sSL -o /dev/null -w "%{http_code}" --max-time 10 -I -- "$url" 2>&1) || http="000"
  34. [[ "$http" == 2* ]] && return 0
  35. http=$(curl-impersonate-ff -sSL -o /dev/null -w "%{http_code}" --max-time 10 -r "0-0" -- "$url" 2>&1) || http="000"
  36. [[ "$http" == 2* ]]
  37. }
  38. while IFS= read -r line; do
  39. if [[ "$line" =~ ^[[:space:]]*local[[:space:]]+host=\"(https://[^\"]+)\" ]]; then
  40. host="${BASH_REMATCH[1]%/}"
  41. continue
  42. fi
  43. [[ "$line" =~ ^[[:space:]]*url=\"(.+)\" ]] || continue
  44. val="${BASH_REMATCH[1]#/}"
  45. if [[ "$val" == https://* ]]; then
  46. url="$val"
  47. elif [[ -n "$host" ]]; then
  48. url="$host/$val"
  49. else
  50. continue
  51. fi
  52. [[ -v seen[$url] ]] && continue
  53. seen[$url]=1
  54. count=$((count + 1))
  55. if check "$url"; then
  56. echo " OK: $url"
  57. else
  58. echo "FAIL: $url"
  59. errors=$((errors + 1))
  60. fi
  61. done < "src/define.sh"
  62. echo ""
  63. printf '%d/%d links valid\n' "$(( count - errors ))" "$count"
  64. (( errors == 0 ))