Marco Eidinger
Swifty Tech by Marco Eidinger

Swifty Tech by Marco Eidinger

Automatically post a tweet when publishing a release on GitHub

Marco Eidinger's photo
Marco Eidinger
·Feb 15, 2021·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

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 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 github.com/MarcoEidinger/gh-action-send-twe.. repository

tweet.png

Cheers

Did you find this article valuable?

Support Marco Eidinger by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this