How to Validate sitemap.xml in GitHub Actions
A sitemap check confirms the file is well-formed XML and that each listed URL actually resolves.
After building, confirm sitemap.xml parses as XML with xmllint, then check that the URLs it lists return a successful status.
Steps
- Build the site so
sitemap.xmlis generated. - Validate it is well-formed with
xmllint --noout. - Extract the
<loc>URLs and confirm each resolves.
Workflow
.github/workflows/ci.yml
jobs:
sitemap:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci && npm run build
- run: xmllint --noout dist/sitemap.xml
- run: |
grep -oP '(?<=<loc>)[^<]+' dist/sitemap.xml | while read -r url; do
code=$(curl -s -o /dev/null -w '%{http_code}' "$url")
echo "$code $url"
[ "$code" -lt 400 ] || exit 1
doneGotchas
- xmllint ships in the libxml2-utils package, which is preinstalled on ubuntu-latest runners.
- Skip the live URL check for preview builds where the production URLs are not yet deployed.
Related guides
How to Check for Broken Links With lychee in GitHub ActionsFind broken links in docs and HTML in GitHub Actions with the lychee-action, scanning files for dead URLs and…
How to Validate Open Graph and Meta Tags in GitHub ActionsAssert required Open Graph and meta tags exist in GitHub Actions by parsing built HTML with cheerio, failing…