Skip to content

Workflow Automation with GitHub Actions#

If you're using GitHub Actions to build and deploy your website, you can automate the process of submitting your sitemap to the IndexNow API. This is particularly useful if you have a large number of pages on your site and want to submit them all at once when you deploy your site.

How to Automatically Submit a Sitemap to IndexNow#

Put a YAML workflow file in the .github/workflows directory of your repository. We want the workflow to be triggered every time you push to the master branch or create a pull request to the master branch, and we will then execute the submit_sitemap_to_index_now() method.

Example of a workflow file:

.github/workflows/submit_sitemap_to_index_now.yml
name: Submit sitemap to IndexNow

on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

jobs:
  submit-sitemap:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"
      - name: Install dependencies
        run: pip install index-now-for-python
      - name: Submit sitemap to IndexNow
        uses: jannekem/run-python-script-action@v1
        with:
          script: |
            from index_now import submit_sitemap_to_index_now, IndexNowAuthentication, SearchEngineEndpoint

            authentication = IndexNowAuthentication(
              host="example.com",
              api_key="${{ secrets.INDEX_NOW_API_KEY }}",
              api_key_location="https://example.com/${{ secrets.INDEX_NOW_API_KEY }}.txt",
            )

            submit_sitemap_to_index_now(authentication, "https://example.com/sitemap.xml", endpoint=SearchEngineEndpoint.YANDEX)

Checklist

Before running the workflow, make sure you have done the following:

  • Added the API key INDEX_NOW_API_KEY as a secret to your repository.
  • Uploaded the API key to the location specified in the api_key_location parameter.
  • Updated the sitemap URL in the sitemap_url parameter.
  • Adjusted the host, endpoint, and other parameters to suit your needs.

Event-Triggered Workflows#

Imagine that the sitemap is submitted before a website deployment is complete. We don't want this to happen, otherwise we won't be using the most up-to-date sitemap.

There are several ways to trigger workflows in GitHub Actions. The most common options in this context are:

  • Use needs when having several jobs in the same workflow file.
  • Use workflow_run when you want to trigger jobs in different workflow files.

Tip

If you want to update the workflow example above, simple update the trigger to workflow_run instead of pull_request and push.

.github/workflows/submit_sitemap_to_index_now.yml
3
4
5
6
7
on:
  workflow_run:
    workflows: ["Deploy Website"]
    branches: master
    types: completed

MkDocs and GitHub Pages#

If you are using MkDocs to build a website is hosted on GitHub Pages, it is a good idea to use the workflow_run event to trigger the workflow after deploying your website.

Find an example here.