Automating Sending WebSub Requests from a Static Site
In “Sending WebSub Notifications” I mentioned that I triggered the request to send WebSub notifications from an iOS/iPadOS/macOS shortcut. I have now finally automated this, so that the CI pipeline on GitLab does so by itself, each time the site(s) is/are build.
Here’s the relevant snipped from the .gitlab-ci.yml:
post_deploy:
stage: deploy
image: curlimages/curl:latest
before_script: []
script:
- >
curl --silent --output /dev/null --write-out "WebSub: %{http_code}\n"
--request POST "https://pubsubhubbub.superfeedr.com/"
--data "hub.mode=publish"
--data "hub.url=https://polaroids.danielpietzsch.com/feed.atom"
- >
curl --silent --output /dev/null --write-out "Trigger homepage build: %{http_code}\n"
--request POST
--form "token=$HOMEPAGE_TRIGGER_TOKEN"
"https://gitlab.com/api/v4/projects/[PROJECT_ID]/ref/master/trigger/pipeline"
needs: ["pages"]
only:
- main
This is the post_deploy stage for the pipeline of my Polaroids site.
The first curl command sends the WebSub request (and leaves a result HTTP status code in the log).
The needs parameter makes sure that the pages stage was already run, which is responsible for building and deploying the site. Without waiting for this task to finish, there’s no updated feed, and hence no point in sending out a WebSub notification.
To further automate my site builds, the second curl command triggers a build of my main site’s build pipeline. Since I included posts from the Polaroid site in my main feed (and also show the latest Polaroid on my homepage), this makes sure this site and its feed are updated, too.
Then, the pipeline configuration regarding WebSub requests for my main site is the same (with a different hub.url parameter) and so this will send out WebSub notifications, too, after it’s built.
This chain has been working for a while now, and takes care of notifying supporting RSS feed clients as soon as I publish or update a post. No need for me to manually push a button each time.