Skip to content

Instantly share code, notes, and snippets.

@dianoetic
Last active July 14, 2023 01:32
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dianoetic/b45466a7c04fa47cf80905b182dbda3c to your computer and use it in GitHub Desktop.
Save dianoetic/b45466a7c04fa47cf80905b182dbda3c 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.

name: Send Webmentions
on:
workflow_run:
workflows: ["Build"] # Name of your build workflow
types: [completed]
jobs:
send:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Send Webmentions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL: ${{ secrets.URL }}
run: |
NEW=$(curl --silent $URL | jq -r first.uri)
curl -X POST https://webmention.app/check?url="$NEW"
curl -H "Content-Type: application/x-www-form-urlencoded" --request POST \
-d source="$NEW" \
-d target="https://brid.gy/publish/twitter" \
"https://brid.gy/publish/webmention"
curl -H "Content-Type: application/x-www-form-urlencoded" --request POST \
-d source="$NEW" \
-d target="https://brid.gy/publish/mastodon" \
"https://brid.gy/publish/webmention"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment