Skip to content
Latchkey

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.xml is 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
          done

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →