I have been having a lot of fun lately writing articles for this blog. So, much fun that I have written quite a few articles. However, I do not want to publish them all at once but every to weeks or so.
Hugo#
I use the static site generator Hugo for this site, and Hugo by default does not publish articles with a future date. So, the Hugo part is straightforward. Just make a bunch of articles and set the date to when it should be published in the future.
But, I do not want to remember to trigger Netlify to build the site on those dates. Therefore, it needs to be automated. Netlify is set up to trigger at build every time a commit is made to the main branch, are pushed on GitHub.
Last Code on GitHub#
This site is the only code I have left on GitHub. I work off my self-hosted Forgejo instance, and it mirrors to GitHub. It is done this way because Netlify has a good integration with GitHub. I am working on another solution to get rid of GitHub entirely but, this works for now.
How-to#
However, that does not work when we want to trigger a build on a specific time. Fortunately, Netlify have build hooks that allow a build to be triggered at any time. Just add a new build hook at Project configuration / Build & deploy / Build hooks This generates a url with a unique ID.
Clicking the build hook URL reveales the command to use.
curl -X POST -d {} https://api.netlify.com/build_hooks/<ID>
Every time that command is run a build will trigger on Netlify.
Now we just need to automate it. Since it just a command that need to be run at a set time there are many ways to automate it. I could just set up a CRON job on my server. But, for me, it made sense to use the Forgejo CICD system because then the automation is with the code.
Create a secret with the unique ID in
Settings / Actions / Secretsso that the secret cannot be leaked by accident. I called mineNETLIFY_CRON_BUILD_HOOKIf they do not exist create the folders
.forgejo/workflowson root. This is where the automation definitions live.Create a
<Automation Name>.ymlfile. I called mine;build.ymlAdd automation to file and use the secret to get the unique ID.
name: Cron Build
run-name: Run Build
on:
schedule:
- cron: "0 6 * * MON"
jobs:
build:
runs-on: docker
container:
image: ubuntu:latest
steps:
- name: apt update
run: apt update
- name: Install curl
run: apt -y install curl
- name: Trigger our build webhook on Netlify
run: curl -X POST -d {} "https://api.netlify.com/build_hooks/${TOKEN}"
env:
TOKEN: ${{ secrets.NETLIFY_CRON_BUILD_HOOK }}
Now a build is triggered every monday at 06:00/6AM UTC and every article where the date is no longer in the future will be published.

