All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 3s
Build & Deploy / 🧪 QA (push) Successful in 2m1s
Build & Deploy / 🏗️ Build (push) Successful in 2m38s
Build & Deploy / 🚀 Deploy (push) Successful in 12s
Build & Deploy / 🧪 Post-Deploy Verification (push) Successful in 3m23s
Build & Deploy / 🔔 Notify (push) Successful in 1s
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import axios from "axios";
|
|
import * as cheerio from "cheerio";
|
|
|
|
const targetUrl =
|
|
process.argv[2] ||
|
|
process.env.NEXT_PUBLIC_BASE_URL ||
|
|
"http://localhost:3000";
|
|
const gatekeeperPassword = process.env.GATEKEEPER_PASSWORD || "lassmichrein";
|
|
|
|
async function main() {
|
|
console.log(`\n🚀 Starting HTTP Sitemap Validation for: ${targetUrl}\n`);
|
|
|
|
try {
|
|
const sitemapUrl = `${targetUrl.replace(/\/$/, "")}/sitemap.xml`;
|
|
console.log(`📥 Fetching sitemap from ${sitemapUrl}...`);
|
|
|
|
const response = await axios.get(sitemapUrl, {
|
|
headers: { Cookie: `mintel_gatekeeper_session=${gatekeeperPassword}` },
|
|
validateStatus: (status) => status < 400,
|
|
});
|
|
|
|
const $ = cheerio.load(response.data, { xmlMode: true });
|
|
let urls = $("url loc")
|
|
.map((i, el) => $(el).text())
|
|
.get();
|
|
|
|
const urlPattern = /https?:\/\/[^\/]+/;
|
|
urls = [...new Set(urls)]
|
|
.filter((u) => u.startsWith("http"))
|
|
.map((u) => u.replace(urlPattern, targetUrl.replace(/\/$/, "")))
|
|
.sort();
|
|
|
|
console.log(`✅ Found ${urls.length} target URLs in sitemap.`);
|
|
|
|
if (urls.length === 0) {
|
|
console.error("❌ No URLs found in sitemap. Is the site up?");
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`\n🔍 Verifying HTTP Status Codes (Limit: None)...`);
|
|
let hasErrors = false;
|
|
|
|
// Run fetches sequentially to avoid overwhelming the server during CI
|
|
for (let i = 0; i < urls.length; i++) {
|
|
const u = urls[i];
|
|
try {
|
|
const res = await axios.get(u, {
|
|
headers: {
|
|
Cookie: `mintel_gatekeeper_session=${gatekeeperPassword}`,
|
|
},
|
|
validateStatus: null, // Don't throw on error status
|
|
});
|
|
|
|
if (res.status >= 400) {
|
|
console.error(`❌ ERROR ${res.status}: ${res.statusText} -> ${u}`);
|
|
hasErrors = true;
|
|
} else {
|
|
console.log(`✅ OK ${res.status} -> ${u}`);
|
|
}
|
|
} catch (error) {
|
|
const err = error as Error;
|
|
console.error(`❌ NETWORK ERROR: ${err.message} -> ${u}`);
|
|
hasErrors = true;
|
|
}
|
|
}
|
|
|
|
if (hasErrors) {
|
|
console.error(
|
|
`\n❌ HTTP Sitemap Validation Failed. One or more pages returned an error.`,
|
|
);
|
|
process.exit(1);
|
|
} else {
|
|
console.log(
|
|
`\n✨ Success: All ${urls.length} pages are healthy! (HTTP 200)`,
|
|
);
|
|
process.exit(0);
|
|
}
|
|
} catch (e) {
|
|
const error = e as Error;
|
|
console.error(`\n❌ Critical Error during Sitemap Fetch:`, error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|