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:
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
.
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.