Skip to content

Commit d9d6507

Browse files
committed
chore(ci): fully test docs url
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent baa18c9 commit d9d6507

1 file changed

Lines changed: 63 additions & 1 deletion

File tree

build/verify-index.php

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
* - Template placeholders are replaced
77
* - Version sections exist
88
* - Links are properly formatted
9-
* - External links are accessible
9+
* - Relative documentation links point to existing files
10+
*
11+
* Environment Variables:
12+
* - VERIFY_DOCS_BASE_URL: Base URL for documentation files (default: https://docs.nextcloud.com)
13+
* Set to empty string to skip file existence checks
1014
*/
1115

1216
$html_file = 'build/index.html';
17+
$base_url = getenv('VERIFY_DOCS_BASE_URL') ?: 'https://docs.nextcloud.com';
1318

1419
if (!file_exists($html_file)) {
1520
fwrite(STDERR, "⚠️ $html_file not found\n");
@@ -109,5 +114,62 @@
109114
exit(1);
110115
}
111116

117+
// Test documentation file existence on deployed site (if base URL is configured)
118+
if ($base_url) {
119+
fprintf(STDERR, "\nVerifying documentation files on %s...\n", $base_url);
120+
121+
$relative_docs = array_filter($relative_links, fn($l) => preg_match('~^server/(latest|stable|\d+)/~', $l));
122+
123+
if (!empty($relative_docs)) {
124+
$missing_files = [];
125+
$timeout_files = [];
126+
127+
foreach ($relative_docs as $relative_path) {
128+
$full_url = rtrim($base_url, '/') . '/' . $relative_path;
129+
130+
$context = stream_context_create([
131+
'http' => [
132+
'method' => 'HEAD',
133+
'timeout' => 5,
134+
'ignore_errors' => true,
135+
'user_agent' => 'Mozilla/5.0'
136+
]
137+
]);
138+
139+
$response = @get_headers($full_url, true, $context);
140+
141+
if ($response === false) {
142+
$timeout_files[] = $relative_path;
143+
fprintf(STDERR, " ⚠️ %s - timeout/offline\n", $relative_path);
144+
} else {
145+
$status_line = $response[0] ?? '';
146+
if (preg_match('/\d{3}/', $status_line, $match)) {
147+
$status = (int)$match[0];
148+
if ($status === 404) {
149+
$missing_files[] = $relative_path;
150+
fprintf(STDERR, " ✗ %s - 404 Not Found\n", $relative_path);
151+
} else if ($status >= 400) {
152+
fprintf(STDERR, " ⚠️ %s - HTTP %d\n", $relative_path, $status);
153+
} else if ($status === 200 || $status === 301 || $status === 302) {
154+
fprintf(STDERR, " ✓ %s\n", $relative_path);
155+
}
156+
}
157+
}
158+
}
159+
160+
if (!empty($missing_files)) {
161+
fprintf(STDERR, "\n❌ ERROR: %d documentation files not found:\n", count($missing_files));
162+
foreach ($missing_files as $file) {
163+
fprintf(STDERR, " - %s\n", $file);
164+
}
165+
exit(1);
166+
}
167+
168+
if (count($timeout_files) >= count($relative_docs) / 2) {
169+
fprintf(STDERR, "\n⚠️ WARNING: %d/%d files timed out (site may be offline)\n", count($timeout_files), count($relative_docs));
170+
}
171+
}
172+
}
173+
112174
fprintf(STDERR, "\n✓ index.html validation passed\n");
113175
exit(0);

0 commit comments

Comments
 (0)