/

Automatically Triggering Deploys on Netlify with Submodules

Automatically Triggering Deploys on Netlify with Submodules

One of my goals was to rebuild my site on Netlify whenever there was a new commit on a Git submodule that was included in the repository.

Unfortunately, Netlify does not natively provide this functionality. It only “watches” the main repository for new commits.

To overcome this limitation, I took the following steps:

  1. I accessed the Deploy settings on Netlify and navigated to “Build hooks.”
  2. I clicked on “Add build hook” to create a unique URL that could be used to trigger the deployment.

Netlify Build Hook

After saving the settings, I obtained a URL like https://api.netlify.com/build_hooks/UNIQUE_STRING.

Next, I created a GitHub Action in the submodule repository to automatically trigger the redeployment:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
name: Trigger redeploy on Netlify
on:
push:
branches: [ "main" ]
jobs:
build:
name: Make POST request
runs-on: ubuntu-latest
steps:
- name: Curl request
shell: bash
env:
UNIQUE_STRING: ${{ secrets.NETLIFY_BUILD_HOOK_UNIQUE_STRING }}
run: curl -X POST -d {} https://api.netlify.com/build_hooks/$UNIQUE_STRING

To use the Netlify UNIQUE_STRING value, you need to add it as an Action secret in your repository’s Settings -> Secrets -> Actions.

After committing the action, the deployment process should start working seamlessly.

Netlify Deployment

Tags: Netlify, Git submodule, GitHub Actions, Deployment triggers