Triggering a GitHub workflow on post creation/update

Hi, I’m using Ghost headless, paired with a Gatsby site. I’d like to setup a GitHub workflow that once it’s triggered it builds the site and deploys it to Firebase hosting. Such workflow should run when a post on my Ghost app is created/updated.

As far as I understand, I would be able to fire a webhook from Ghost. However, the only way I found to take advantage of external events on GitHub is by firing a repository_dispatch event, which is a POST request.

Is it possible to that with Ghost? Or maybe, is there a good way to trigger a GitHub workflow on specific Ghost events?


Edit: that wasn’t really clear. What I meant was setting custom headers (like Authorization) and a body content. For what I can see, this is what I get when the webhook is fired:

headers {
  'user-agent': 'Ghost/3.14.0 (',
  'content-length': '2',
  'content-type': 'application/json',
  'accept-encoding': 'gzip, deflate',
  host: 'localhost:3000',
  connection: 'close'

body {}

Hey @justandrea,
Really cool that you’re using Gatsby with Ghost :zap:. Are you using Firebase hosting for a specific reason? Just asking because you might be able to save yourself some headache by using Netlify to host your static Gatsby site. They have built in tooling to listen out fo webhooks, like the webhooks available in Ghost, source your code from GitHub, rebuild your Gatsby site automatically and host it too. Plus they would rebuild your site any time you push a code change to your GitHub repository :fire:

We have a handy integration page for using Netlify with our webhooks if you’re interested:

This is merely a suggestion, but it seems like it would fit better for what you’re trying to achieve. If it’s not right for you then I’m sure a workflow is possible with Firebase hosting :blush:

Hi @DavidDarnes :wave:
Well yes, I’m using Gatsby to channel a bunch of different sources, and the front-end is just a part of a bigger educational platform, where parents can purchase games that teach their kids how to code. Kids play, parents help and track progress. I’m using firebase services extensively, and although I think I could deploy on netlify, that wouldn’t be optimal for this project, and then I would have to make sure I would have no problem with the domain name or anything else.

If I could customize Ghost webhook, that would solve any issue. However, I would have concerns on retrieving Github authorization token from within Ghost. As a workaround, I was thinking of deploying an additional function to mimic Netlify build hooks, then it would be the responsibility of the function to trigger a new build on Github.

Knowing Ghost platform, could you please suggest me a strategy, and/or a way to authenticate a Ghost call? In the context of a serverless function, is there a way I can check calls are genuinely made by my Ghost app, and have not been simply triggered by anything else?

Many thanks for your kind support :pray:

I think your best approach would be to mirror what Netlify are doing in order to deploy your site. You’ll need the Ghost webhook event ‘site changed’ to notify GitHub that there has been a change in content. From there GitHub would run through the build steps, of which the Content API will be part of and will retrieve the content from your Ghost installation. Finally the built application will need to be deployed on your Firebase hosting. Authorisation would be handled by the the API credentials in your Gatsby application and there would be no need to authenticate the Ghost webhook event :slightly_smiling_face:

1 Like

Ok, cool! Sorry, I wasn’t really clear… I meant: when Ghost will call my firebase function, can it also pass a token or anything? For example, stripe implements webhooks too, and it passes a ‘stripe-signature’ header that I can verify in order to ensure the call was made by stripe itself. This is useful since the function is just sitting there waiting for anything to call it.

It appears like Netlify build hooks are just functions with some random name that’s hard to guess, and that’s all there is as far as authentication is concerned. It’s like: if you know the name you probably know what it is about. Is that correct or is there something more to it to mirror the functionality?

Aha I understand now. Sorry for not keeping up. Yes Netlify produces a completely random string that would be hard to guess. The URL string is pretty obscure so it’s going to be impossible for someone, or a bot, to guess it. I’m not that familiar with Firebase but do they not produce the same thing? A unique URL for Ghost to request upon an event trigger?

I don’t think authentication is needed with them, I think with Netlify (and other platforms) they want developers to have an easy time. So copying a URL into another tool is a pretty smooth experience for developers.

1 Like

Great, that was very clear, thank you!

There are different kind of functions in firebase, these would be in http functions category. Functions’ address usually match functions’ names, so I guess some long random string will do the job for me.

1 Like