Skip to main content

Command Palette

Search for a command to run...

Automatically post a tweet when publishing a release on GitHub

Published
2 min read
M

I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸

I often post a tweet on Twitter whenever I publish a new release of one of my open-source projects. This task, as many others, can be automated with GitHub actions.

First, I signed up on https://developer.twitter.com and then created a Twitter application. This allows me to programmatically authenticate to the Twitter API and send a tweet. The process is straightforward with one little caveat. Per default the app gets created with read-only access. Change permission to Read and Write before you generate access token & secret.

twitterdeveloper.png

Then I store the Twitter API key & secret as well as the access key & secret as repository secrets in the GitHub repository for which I want to send tweets.

twittersecrets.png

Finally I can define the GitHub workflow by leveraging the existing, reusable GitHub action,

Here is the final workflow:

name: tweet-release
on:
  release:
    types: [published]
jobs:
  tweet:
    runs-on: ubuntu-latest    
    steps:
      - uses: ethomson/send-tweet-action@v1
        with:
          status: "New ${{ github.event.repository.name }} release ${{ github.event.release.tag_name }} at ${{ github.event.release.html_url }}"
          consumer-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }}
          consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }}
          access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
          access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}

And this is the tweet, which was automatically sent when I created release 1.0.0 for https://github.com/MarcoEidinger/gh-action-send-tweet-test repository

tweet.png

Cheers

More from this blog

Dev blog post potpourri by senior software engineer Marco Eidinger

149 posts

Hello 👋🏻 , I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸