How to trigger a Netlify build of another repo in a module repo's GitHub Action

My thought on how to solve

for my Hugo module in

which I currently have unlinked from the last deploy on: image-handling-mod.netlify.app

since I do not currently have the demo/test site in the same repo (or any repo at the moment).

My thought is to create a new repo with the demo/test for which the image-handling-mod-hugo-dfd triggers a build of the demo/test site (which pulls in the module via Hugo’s wrapper around Go modules) , and requires Netlify return a success deploy results before treat the action successful.

I have three questions:

  1. Is this something that is possible to do (e.g. vie netlify-cli), and
  2. Would it make more sense to use a build script in the image-handling-mod-hugo-dfd repo that grabs the demo/test site repo and uses ‘module replacements’ to use the local (in the runner/build environment) copy of the module instead of pulling GitHub’s version (so that it’s the version being pushed / merged) and builds the demo/test site?
    1. If so, in a Netlify build environment, is the repo that was pushed to trigger the build in a subdirectory of $HOME or does the repo become $HOME?
    2. How stable are things like knowing where the trigger repo is, and in what state, and where any cloned directory, and any build directory are located?
  3. Am I am missing an obvious easier and/or better way to achieve this?

EDIT: I have new idea. Because the demo/test site is a module, and Hugo accepts a --config parameter for custom named config files, in my module I ought to be able have e.g. config-ci.toml which imports the demo/test site and uses the current repo via Hugo’s mounts so that I can deploy a CI-only site on Netlify.

I will let everyone know how it goes in case someone else someday wants to achieve the same thing.

I’ve figured out a variation on the ‘new idea’ in the edit, which I have working. I will do a full write-up later, but for now:

  • In my Hugo module, I add an exampleSite subdirectory which has only a config.toml.
  • To deploy to Netlify:
    • The config.toml uses the demo/test site as a module.
      • When mounting the site, the site’s configs and modules are ignored.
    • It also mounts the module via relative paths (that is, from the perspective of the exampleSite directory ../layouts is mounted on layouts.
    • I use a small shell script which uses a number of command line parameters to the hugo command to control Hugo’s build.

As promised, I have a full write up:

For those who don’t want to read the whole thing, I show the table of contents, which make a nice outline of the steps involved:

  1. Preface
    1. Prerequisites
  2. Moving the large files out of the module
    1. Make a copy of the test site, elsewhere
    2. Make a list of any LFS files you wish to remove
    3. Remove references to unwanted files from CI
    4. Remove unwanted files and references to them
    5. Obliterate the large files
      1. Use git-filter-repo or similar tool
      2. For LFS, have the remote admin remove the LFS files
  3. Create a new Hugo module repo with the site
    1. Make sure the main module repository still works
  4. Use a subdirectory of the module as a ‘site’
    1. Add a site config in a subdirectory of the module
    2. Initialize exampleSite as a Hugo module
    3. Activate any modules from the config.toml
    4. Test with the Hugo local server
  5. Create a build script for use with Netlify
  6. Deploy on Netlify
  7. Set your GitHub branch protection rules to require successful deploy
  8. Remember to git rebase not git merge or git pull any existing branches
  9. Conclusion

I hope this can be of use to others.

Wow this is absolutely awesome @danielfdickinson1 thank you so much for sharing all of this with the community.

1 Like