Skip to content

Commit

Permalink
Merge pull request #1 from shivam-Purohit/twitterapi
Browse files Browse the repository at this point in the history
Auto Twitter Post On release #1825
  • Loading branch information
mlodic authored Oct 6, 2023
2 parents 72d2628 + b4dab4a commit 5d76c66
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: publish-to-twitter

on:
workflow_dispatch:

jobs:
tweet:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.x

- name: Install dependencies
run: |
pip install tweepy
- name: Run tweet script
uses: ./
with:
status: publish to twitter
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 }}
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# twitter_post
Twitter Post Action Repo

## Example usage

```yaml
name: publish-to-twitter
on: [release]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.x

- name: Install dependencies
run: |
pip install tweepy
- name: Publish tweet
uses: intelowlproject/twitter-post
with:
status: Add publish notes here
api_key: ${{ secrets.TWITTER_API_KEY}}
api_key_secrets: ${{ secrets.TWITTER_API_KEY_SECRET}}
access_token: ${{ secrets.TWITTER_ACCESS_TOKEN}}
access_token_secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET}}
```
48 changes: 48 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: publish-to-twitter
description: posts tweets on Twitter
author: IntelOwl

inputs:
api_key:
description: "API key"
required: true
api_key_secret:
description: "API key secret"
required: true
access_token:
description: "Consumer access token"
required: true
access_token_secret:
description: "Consumer access token secret"
required: true
status:
description: "Status to be published to Twitter"
required: true

outputs:
title:
description: "Post's title"

runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependencies
run: |
pip install tweepy
shell: bash

- name: Run tweet script
run: python3 publish.py ${{ inputs.api_key }} ${{ inputs.api_key_secret }} ${{ inputs.access_token }} ${{ inputs.access_token_secret }} "${{ inputs.status }}"
shell: bash

branding:
icon: "message-circle"
color: "blue"
19 changes: 19 additions & 0 deletions publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import tweepy
import os
import sys

api_key = sys.argv[1]
api_key_secret = sys.argv[2]
access_token = sys.argv[3]
access_token_secret = sys.argv[4]
status = sys.argv[5]

client = tweepy.Client(
consumer_key=api_key,
consumer_secret=api_key_secret,
access_token=access_token,
access_token_secret=access_token_secret
)

tweet_content = status
client.create_tweet(text = tweet_content)

0 comments on commit 5d76c66

Please sign in to comment.