File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6161 EOF
6262
6363 - name : Run linkchecker for 404 errors only
64- run : linkchecker --no-warning https://canonical.com
64+ run : |
65+ set -u
66+
67+ # First pass: full crawl. Capture any failed links to a CSV file.
68+ if linkchecker --no-warning -F csv/failed-links.csv https://canonical.com; then
69+ echo "No broken links found."
70+ exit 0
71+ fi
72+
73+ # Extract the failed URLs (valid=False) from the CSV output.
74+ python3 - <<'PY' > failed-urls.txt
75+ import csv
76+
77+ seen = set()
78+ with open("failed-links.csv", newline="") as f:
79+ rows = (line for line in f if not line.startswith("#"))
80+ for row in csv.DictReader(rows, delimiter=";"):
81+ if row.get("valid", "").strip().lower() == "false":
82+ url = row["urlname"]
83+ if url and url not in seen:
84+ seen.add(url)
85+ print(url)
86+ PY
87+
88+ count=$(grep -c . failed-urls.txt || true)
89+ if [ "$count" -eq 0 ]; then
90+ echo "No broken links to retry (all failures were ignored)."
91+ exit 0
92+ fi
93+
94+ echo "Retrying $count failed link(s) after a 60s delay:"
95+ cat failed-urls.txt
96+ sleep 60
97+
98+ # Second pass: re-check only the previously failed links.
99+ linkchecker --no-warning --recursion-level=0 $(cat failed-urls.txt)
65100
66101 - name : Send message on failure
67102 if : failure()
You can’t perform that action at this time.
0 commit comments