All Articles

Github action for adding a post to Twitter

Tweet with ease

I’ve just published a new CI code snippet, which helps to make a tweet directly from Github Actions.

Use cases

The good question - Why I need tweet-action? Here are several use cases where it can be applied:

  • blogging system, to automate the process of tweeting of new articles
  • release updates, when a new release (tag) is created it can tweet a news message about it

Setup steps

  • Register as a Twitter app developer in here. Usually, it takes up to 1 week. If you already have access, go to the next step.
  • Create a new Twitter application in this section. Copy API key, API secret key somewhere.
  • At the bottom of the page, press get user tokens, and then press Access token & secret for @username generate button. Copy Access token, Access token secret somewhere.
  • Go to the app settings section and change App permissions over there to Read and Write
  • Now you need to get into a Github repository
  • Go to the repository settings page and add secrets with previously saved keys.
TWITTER_API_KEY="API key" TWITTER_API_KEY_SECRET="API secret key" TWITTER_ACCESS_TOKEN="Access token" TWITTER_ACCESS_TOKEN_SECRET="Access token secret" name: Tweeting from Gtihub Actions on: push jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: infraway/[email protected] with: status: "Hello World, delivered from Github Actions 🚀" api_key: ${{ secrets.TWITTER_API_KEY }} api_key_secret: ${{ secrets.TWITTER_API_KEY_SECRET }} access_token: ${{ secrets.TWITTER_ACCESS_TOKEN }} access_token_secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
  • When the following code snippet is added, you can push anything into the repo and see the tweet delivered to Twitter.

Interested in giving it a try?

Find more useful DevOps automation tools at:

Of course, all the source code is open-sourced.

Any feedback, contribution, or help is highly appreciated. Thanks for your time and have a nice coding!

Clap

Resources