DEV Community

Schedule Netlify Builds with GitHub Actions, Cron, and Webhooks

chantastic on January 29, 2021

Instructions Add this GitHub Action to your repo at .github/workflows/schedule-netlify-build.yml # .github/workflows/schedule-netlify...
Collapse
 
michaelcurrin profile image
Michael Currin • Edited

The default for POST is to send form field data rather than JSON - so you can do -d 'foo=bar fizz=buzz.

Which means you can simplify to '' payload. Plus POST is implied.

Example here using simpler syntax and the env variable secret you mentioned

run: curl -d '' {{ NETLIFY_BUILD_HOOK }}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
chantastic profile image
chantastic

thanks!
when i generate the build hook in Netlify, it includes the whole curl command. I left it as provided to prevent confusion but you are correct, the simplified version would work all the same

Collapse
 
michaelcurrin profile image
Michael Currin

Ah ok makes sense

Collapse
 
michaelcurrin profile image
Michael Currin

For interest, how to expand on the Netlify hook:

You could add workflow_dispatch under on, then you get run now kind of button. Which is similar to a button that already exists in Netlify.

If you have another service that supports looks, you could use the URL there instead of GH Actions.

E.g. maybe you build or find a service that can trigger a web hook when content changes. Like a new blog post on a blog site, a new commit in your repo which contains markdown web pages, or a new tweet is made. At the danger that high activity will cause rapid rebuilds on Netlify. If you are going to pull in fast changing data then one is better off with pulling in content on the frontend like Instagram, or a server side HTML with PHP/Python rather than static site.

Another easy trigger to setup would be with IFTT.com - you can set it up to listen to a ton of events like a tweet is created or your phone enters a certain GPS location, then cause an event like send an email or add to a Google Spreadsheet or ping any given URL. Such as the Netlify one. I mean you can even use a thermometer or motion sensor in your smart home IoT setup to trigger an event if you really want.

Collapse
 
chantastic profile image
chantastic

yeah! it's really interesting to think of the possibilities. how we might integrate it with some of our social accounts and trigger updates (say, after a stream ends) would be very cool.

Collapse
 
michaelcurrin profile image
Michael Currin

Thanks. I have be thinking about this idea for a long time but this is the first time I've seen someone do it.

Collapse
 
ajcwebdev profile image
ajcwebdev

That's great to hear, when Michael mentioned he was trying to do this I thought, "How can this be a thing that hasn't been done a million times?" Yet we found very little prior art on it.

Collapse
 
michaelcurrin profile image
Michael Currin

The case is you have external content driving your Netlify site. Maybe not many people need that.

You can use a local cron job assuming your laptop is always connected to the internet and awake.

GH Actions is the obvious choice for me, if one knows it exists and it supports schedule.

Maybe there are some other free services which do the same. You could use Datadog or some other monitoring platform even to hit your private URL daily.

Thread Thread
 
ajcwebdev profile image
ajcwebdev • Edited

I know of two projects that are aimed at providing a wide range of different background job and scheduling features that I think would include this kind of use case. I haven't used either but I know the creators of each from their work on Redwood (Rob Cameron) and Blitz (Simon Knott) respectively.

Repeater

Described as being a Job Queue as a Service that is aimed at Background job processing for the Jamstack.

Common uses include:

  • Send emails & notifications
  • Check for heartbeat
  • Image processing
  • Data transformations
  • PDF generation

Quirrel

Described as job queueing for serverless.

Jobs include:

  • Delayed Jobs
  • Fanout Jobs
  • Recurring Jobs
  • Cron Jobs
Collapse
 
chantastic profile image
chantastic

thanks for reading it!
I find GitHub Actions to be a great place for this. I love that anyone in the project can edit and submit a PR to change the schedule.

Collapse
 
michaelcurrin profile image
Michael Currin

BTW you link to Environment variables doc which is about setting and use shell variables in a build.

Rather link to the secrets doc for setting and using secrets.

Collapse
 
chantastic profile image
chantastic

omg. thank you for the proper link!

Collapse
 
michaelcurrin profile image
Michael Currin

PS your article title would be better as Cron, not Chron. Though the body is fine.

Collapse
 
chantastic profile image
chantastic

thanks! updated 🙏

Collapse
 
michaelcurrin profile image
Michael Currin

I've taken your file as inspiration and done my own guide here. I've linked back to your post.

michaelcurrin.github.io/code-cookb...

Collapse
 
chantastic profile image
chantastic

Yes! Love that you took it and made it your own.
We found maybe two articles on the subject. So the more the merrier :)