diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3f9dfb8 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/README.md b/README.md index c5b9d3e..b4295f8 100644 --- a/README.md +++ b/README.md @@ -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}} +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1ad75ac --- /dev/null +++ b/action.yml @@ -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" diff --git a/publish.py b/publish.py new file mode 100644 index 0000000..72f9fb5 --- /dev/null +++ b/publish.py @@ -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)