Each time I write something for this site there are several steps that I go through to make sure that the post makes it's way to where people can see it.
- Run
make html
to generate the SQLite database that powers my site's search tool1 - Run
make vercel
to deploy the SQLite database to vercel - Run
git add <filename>
to add post to be committed to GitHub - Run
git commit -m <message>
to commit to GitHub - Post to Twitter with a link to my new post
If there's more than 2 things to do, I'm totally going to forget to do one of them.
The above steps are all automat-able, but the one I wanted to tackle first was the automated tweet. Last night I figured out how to tweet with a GitHub action.
There were a few things to do to get the auto tweet to work:
- Find a GitHub in the Market Place that did the auto tweet (or try to write one if I couldn't find one)
- Set up a twitter app with Read and Write privileges
- Set the necessary secrets for the report (API Key, API Key Secret, Access Token, Access Token Secret, Bearer)
- Test the GitHub Action
The action I chose was send-tweet-action. It's got easy to read documentation on what is needed. Honestly the hardest part was getting a twitter app set up with Read and Write privileges.
I'm still not sure how to do it, honestly. I was lucky enough that I already had an app sitting around with Read and Write from the WordPress blog I had previously, so I just regenerated the keys for that one and used them.
The last bit was just testing the action and seeing that it worked as expected. It was pretty cool running an action and then seeing a tweet in my timeline.
The TIL for this was that GitHub Actions can have conditionals. This is important because I don't want to generate a new tweet each time I commit to main. I only want that to happen when I have a new post.
To do that, you just need this in the GitHub Action:
if: "contains(github.event.head_commit.message, '<String to Filter on>')"
In my case, the <String to Filter on>
is New Post:
.
The send-tweet-action
has a status
field which is the text tweeted. I can use the github.event.head_commit.message
in the action like this:
${{ github.event.head_commit.message }}
Now when I have a commit message that starts 'New Post:' against main
I'll have a tweet get sent out too!
This got me to thinking that I can/should automate all of these steps.
With that in mind, I'm going to work on getting the process down to just having to run a single command. Something like:
make publish "New Post: Title of my Post https://www.ryancheley.com/yyyy/mm/dd/slug/"
make vercel
actually runsmake html
so this isn't really a step that I need to do. ↩︎
This post is part 1 of the "Auto Deploying my Words" series: