Skip to content

Instantly share code, notes, and snippets.

@RobinBoers
Forked from dianoetic/README.md
Last active May 3, 2022 10:00
Show Gist options
  • Save RobinBoers/1e0be15b35fba95934a937b19968e3bf to your computer and use it in GitHub Desktop.
Save RobinBoers/1e0be15b35fba95934a937b19968e3bf to your computer and use it in GitHub Desktop.
A GitHub Action for sending webmentions after your site builds

Send Webmentions with GitHub Actions

Action that uses curl to send your webmentions. It gets the most recent addition to a JSON feed (ideally, your latest post), looks for the value of a key called uri (ideally, your post's permalink) and sends webmentions for it.

The services currently in the file are webmention.app and brid.gy, but any service that can be triggered with a POST request will work fine with this.

This workflow file is run once another GitHub Action named "Build" completes successfully.

Usage

Put it in .github/workflows/.

Set a repository secret called URL with your website's JSON feed, e.g. https://dianoetic.me/feed.json.

You don't need to set GITHUB_TOKEN, this is built-in.

(my fork contains a hard-coded URL and runs for 2 feeds. it also only runs when the commit message contains either #en or #nl)

name: Send Webmentions
on:
workflow_run:
workflows: ["Build and deploy to GitHub pages"]
types: [completed]
jobs:
send-nl:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && contains(github.event.head_commit.message, '#nl') }}
steps:
- name: Send Webmentions (dutch blog)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL: "https://blog.geheimesite.nl/index.json
run: |
NEW=$(curl --silent $URL | jq -r first.uri)
curl -X POST https://webmention.app/check?url="$NEW"
send-en:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && contains(github.event.head_commit.message, '#en') }}
steps:
- name: Send Webmentions (english blog)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL: "https://blog.geheimesite.nl/en/index.json
run: |
NEW=$(curl --silent $URL | jq -r first.uri)
curl -X POST https://webmention.app/check?url="$NEW"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment