So, as the title says, here is my plan for getting my GitHub Pages site updated: trigger a workflow from Lambda, and have the workflow pull the new updates (either from a remote repo in CodeCommit, an S3 bucket, or maybe an API Gateway). For this last part, I’ll probably use GitHub Push, or a similar action, to commit and push the changes to the GitHub Pages repo.
Manually triggering a GitHub Actions workflow
Using on: workflow_dispatch
we can manually trigger a workflow, either from the GitHub site, or via REST API. We can also provide input values, which is perfect for my plan: publish a new post or update an existing one.
You can manually trigger a workflow run using the GitHub API and from GitHub. For more information, see “Manually running a workflow.” […] To trigger the custom workflow_dispatch webhook event using the REST API, you must send a POST request to a GitHub API endpoint and provide the ref and any required inputs. For more information, see the “Create a workflow dispatch event” REST API endpoint.
To test this, I’ve added the example workflow from the documentation to my GitHub Pages repo.
name: Manually triggered workflow
on:
workflow_dispatch:
inputs:
name:
description: 'Person to greet'
required: true
default: 'Mona the Octocat'
home:
description: 'location'
required: false
default: 'The Octoverse'
jobs:
say_hello:
runs-on: ubuntu-latest
steps:
- run: |
echo "Hello $!"
echo "- in $!"
Trigger from GitHub console
Input parameters can be defined when running the workflow from the GitHub console:
Trigger via REST API
And here is a curl
request to trigger the workflow via REST API, with the parameters needed (PAT token omitted).
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/eneko/eneko.github.io/actions/workflows/4476169/dispatches \
-d '{"ref":"main", "inputs": { "name":"Command Line User", "home":"CLI" }}'
And voila! We can now trigger a workflow via API 🎉
Next steps
The flow is getting close to complete:
- Configure GitHub action to push Issue updates to Amazon SQS (#1) ✅
- Configure an AWS Lambda to process the incoming messages (#2) ✅
- Retrieve entire issue details via GitHub Graph API, or embed in message (#3 & #4) ✅
- Automate creation of blog post on GitHub pages (via direct commit, or pull request)
- Send me a notification via email or SMS with the url of the new blog post (using AWS SNS)
- Potentially store a mapping of GitHub issues to blog URLs (and file paths) on a DynamoDB table
This article was written as an issue on my Blog repository on GitHub (see Issue #7)