PHPnews.io

Scheduling Deploys with GitHub Actions

Written by Bram.us / Original link on Sep. 13, 2019

1568030958-github-secrets.jpg

Leveraging GitHub Workflows’ Scheduled Events (read: cronjobs that run on GitHub) the folks at De Voorhoede let their static site automatically be rebuilt overnight. They do this because they have some external content, which doesn’t get committed into the repo, included on their site.

Static websites don’t update by themselves. In case of code changes (git push) and content changes (CMS publish event) a user triggers an update. But what if an external system (regularly) updates but can’t be configured to trigger an update? Enter cron jobs.

As their site is deployed onto Netlify, they let GitHub perform a curl request to Netlify’s Deploy Webhook, thus rebuilding and redeploying their site.

Their workflow file .github/workflows/nightly-build.yml is straightforward:

name: Scheduled build
on:
  schedule:
  - cron: '30 3 * * *'
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Trigger our build webhook on Netlify
      run: curl -s -X POST "https://api.netlify.com/build_hooks/${TOKEN}"
      env:
        TOKEN: ${{ secrets.NETLIFY_CRON_BUILD_HOOK }}

The required NETLIFY_CRON_BUILD_HOOK is stored a GitHub Secret into the repo

Scheduling Netlify deploys with GitHub Actions →

1f481-200d-2642-fe0f.png Here’s a writeup I’ve done on deploying a static site onto Netlify, in case you’re looking for info on how to get started with Netlify.

cronjob elsewhere link laravelnews deploy netlify bram

« text-decoration-* CSS Properties Coming to Firefox - Automatically compress images to your Pull Requests with this GitHub Action »