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:
- I accessed the Deploy settings on Netlify and navigated to “Build hooks.”
- I clicked on “Add build hook” to create a unique URL that could be used to trigger the deployment.
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:
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.
Tags: Netlify, Git submodule, GitHub Actions, Deployment triggers