# Automatically post a tweet when publishing a release on GitHub

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](https://cdn.hashnode.com/res/hashnode/image/upload/v1613331110645/f9tN0_xNh.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1613331183610/vB7hOAiEI.png)

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

%[https://github.com/marketplace/actions/send-tweet-action]

Here is the final workflow:

```xml
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](https://cdn.hashnode.com/res/hashnode/image/upload/v1613331425693/1_17-VXMe.png)

Cheers
