Post a Tweet from a GitHub Action workflow, with Twitter REST API for Version 2 endpoint.
Before anything else, you must follow this tutorial.
- Request approval for a developer account;
- Once your developer account is approved, you will need to create a Project;
- Enable read/write access for your Twitter app;
- Generate Consumer Keys and Authentication Tokens;
- Retrieve your Keys and Tokens from the Twitter Developer portal.
Configure the authentication keys and tokens for your Twitter app as secrets in your repository. I recommend using the TWITTER_CONSUMER_API_KEY
, TWITTER_CONSUMER_API_SECRET
, TWITTER_ACCESS_TOKEN
, and TWITTER_ACCESS_TOKEN_SECRET
secrets.
Configure your workflow to use noweh/post-tweet-v2-action@v1
, and provide the tweet you want to send as the status
input.
Provide the authentication keys and tokens for your Twitter app
as the account-id
and bearer-token
inputs.
For example:
name: Send a Tweet
on: [push]
jobs:
tweet:
runs-on: ubuntu-latest
steps:
- uses: noweh/[email protected]
with:
message: "Hi, this is a test!"
consumer-key: ${{ secrets.TWITTER_CONSUMER_KEY }}
consumer-secret: ${{ secrets.TWITTER_CONSUMER_SECRET }}
access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
Now whenever you push something to your repository, GitHub Actions will tweet on your behalf.