From 7a379227b85fd8523eb73760252322c7a3dc0157 Mon Sep 17 00:00:00 2001 From: shivam Date: Thu, 7 Sep 2023 11:28:54 +0530 Subject: [PATCH 01/15] add script and action file --- action.yml | 32 ++++++++++++++++++++++++++++++++ script.py | 19 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 action.yml create mode 100644 script.py diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..bfd5514 --- /dev/null +++ b/action.yml @@ -0,0 +1,32 @@ +name: publish-to-twitter +description: "Posts to twitter/X" +author: "IntelOwl" + + +on: + release: + types: [released] + +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 + run: python script.py + env: + TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }} + TWITTER_API_KEY_SECRET: ${{ secrets.TWITTER_API_KEY_SECRET }} + TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} diff --git a/script.py b/script.py new file mode 100644 index 0000000..e354ecb --- /dev/null +++ b/script.py @@ -0,0 +1,19 @@ +import tweepy +import os + + +api_key = os.environ['TWITTER_API_KEY'] +api_key_secret = os.environ['TWITTER_API_KEY_SECRET'] +access_token = os.environ['TWITTER_ACCESS_TOKEN'] +access_token_secret = os.environ['TWITTER_ACCESS_TOKEN_SECRET'] + +# authenticating using tweepy +auth = tweepy.OAuthHandler(api_key, api_key_secret) +auth.set_access_token(access_token, access_token_secret) +api = tweepy.API(auth) + +# tweet content +tweet_content = "Published a new release of my project! #ReleaseNotes" + +# Post the tweet +api.update_status(tweet_content) From 373bb9db9935f29c2648f621aae1ec42eddeddf7 Mon Sep 17 00:00:00 2001 From: shivam Date: Thu, 7 Sep 2023 12:15:13 +0530 Subject: [PATCH 02/15] add test workflow --- .github/workflows/test.yml | 28 ++++++++++++++++++++++++++++ action.yml | 5 ++--- script.py | 19 +++++++------------ 3 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4de7789 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +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 + run: python script.py + env: + TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }} + TWITTER_API_KEY_SECRET: ${{ secrets.TWITTER_API_KEY_SECRET }} + TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} \ No newline at end of file diff --git a/action.yml b/action.yml index bfd5514..12f1a41 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,6 @@ name: publish-to-twitter -description: "Posts to twitter/X" -author: "IntelOwl" - +description: posts tweets on twitter +author: IntelOwl on: release: diff --git a/script.py b/script.py index e354ecb..1d57b81 100644 --- a/script.py +++ b/script.py @@ -2,18 +2,13 @@ import os -api_key = os.environ['TWITTER_API_KEY'] -api_key_secret = os.environ['TWITTER_API_KEY_SECRET'] -access_token = os.environ['TWITTER_ACCESS_TOKEN'] -access_token_secret = os.environ['TWITTER_ACCESS_TOKEN_SECRET'] +client = tweepy.Client( + consumer_key=os.environ['TWITTER_API_KEY'], + consumer_secret=os.environ['TWITTER_API_KEY_SECRET'], + access_token=os.environ['TWITTER_ACCESS_TOKEN'], + access_token_secret=os.environ['TWITTER_ACCESS_TOKEN_SECRET'] +) -# authenticating using tweepy -auth = tweepy.OAuthHandler(api_key, api_key_secret) -auth.set_access_token(access_token, access_token_secret) -api = tweepy.API(auth) -# tweet content tweet_content = "Published a new release of my project! #ReleaseNotes" - -# Post the tweet -api.update_status(tweet_content) +client.create_tweet(text = tweet_content) \ No newline at end of file From e8abd839911e90f8b25d9931f4404cd5f2078134 Mon Sep 17 00:00:00 2001 From: shivam Date: Fri, 8 Sep 2023 11:51:29 +0530 Subject: [PATCH 03/15] modify to support publishing --- action.yml | 49 +++++++++++++++++++++++++------------------------ script.py | 12 +++++------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/action.yml b/action.yml index 12f1a41..2ee4124 100644 --- a/action.yml +++ b/action.yml @@ -2,30 +2,31 @@ name: publish-to-twitter description: posts tweets on twitter author: IntelOwl -on: - release: - types: [released] +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 -jobs: - tweet: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 +outputs: + title: + description: "Post's title" - - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: 3.x +runs: + using: "python3" + main: "twitter_post.py" - - name: Install dependencies - run: | - pip install tweepy - - - name: Run tweet script - run: python script.py - env: - TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }} - TWITTER_API_KEY_SECRET: ${{ secrets.TWITTER_API_KEY_SECRET }} - TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} - TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} +branding: + icon: "message-circle" + color: "blue" \ No newline at end of file diff --git a/script.py b/script.py index 1d57b81..219502b 100644 --- a/script.py +++ b/script.py @@ -1,14 +1,12 @@ import tweepy import os - client = tweepy.Client( - consumer_key=os.environ['TWITTER_API_KEY'], - consumer_secret=os.environ['TWITTER_API_KEY_SECRET'], - access_token=os.environ['TWITTER_ACCESS_TOKEN'], - access_token_secret=os.environ['TWITTER_ACCESS_TOKEN_SECRET'] + consumer_key=os.environ['api_key'], + consumer_secret=os.environ['api_key_secret'], + access_token=os.environ['access_token'], + access_token_secret=os.environ['access_token_secret'] ) - -tweet_content = "Published a new release of my project! #ReleaseNotes" +tweet_content = os.environ['status'] client.create_tweet(text = tweet_content) \ No newline at end of file From 903683ec34ba2f1e6c17c01184ef99f0e7d4a0d5 Mon Sep 17 00:00:00 2001 From: shivam Date: Fri, 8 Sep 2023 12:02:21 +0530 Subject: [PATCH 04/15] Readme.md:add boiler plate for action --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index c5b9d3e..e22d309 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 }} +``` From 97d47f98dc1a6b704c32e351be1dbf44538af132 Mon Sep 17 00:00:00 2001 From: shivam Date: Fri, 8 Sep 2023 12:09:46 +0530 Subject: [PATCH 05/15] readme.md remove extra white spaces --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e22d309..b4295f8 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ jobs: 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 }} + 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}} ``` From ae1377a9f53018d43b79a472bf532f93f4eb14c9 Mon Sep 17 00:00:00 2001 From: shivam Date: Fri, 8 Sep 2023 12:27:22 +0530 Subject: [PATCH 06/15] modify the names --- action.yml | 3 +-- script.py => publish.py | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename script.py => publish.py (100%) diff --git a/action.yml b/action.yml index 2ee4124..eeda555 100644 --- a/action.yml +++ b/action.yml @@ -24,8 +24,7 @@ outputs: description: "Post's title" runs: - using: "python3" - main: "twitter_post.py" + main: "publish.py" branding: icon: "message-circle" diff --git a/script.py b/publish.py similarity index 100% rename from script.py rename to publish.py From 767368840156bb3a5c8574df58abfe0b5fe1d864 Mon Sep 17 00:00:00 2001 From: shivam Date: Fri, 8 Sep 2023 12:30:40 +0530 Subject: [PATCH 07/15] node12 using tag --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index eeda555..5937a9b 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,7 @@ outputs: description: "Post's title" runs: + using: node12 main: "publish.py" branding: From 618aaea22dbad964b7c28668c2de31e4b092169a Mon Sep 17 00:00:00 2001 From: shivam Date: Fri, 8 Sep 2023 12:32:27 +0530 Subject: [PATCH 08/15] correct the syntax --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5937a9b..5d19f9d 100644 --- a/action.yml +++ b/action.yml @@ -24,7 +24,7 @@ outputs: description: "Post's title" runs: - using: node12 + using: "node12" main: "publish.py" branding: From 8d3f159ffc96e02501c831c84bc13cf017658a0d Mon Sep 17 00:00:00 2001 From: shivam Date: Fri, 8 Sep 2023 12:34:31 +0530 Subject: [PATCH 09/15] remove depracated node12 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5d19f9d..5096dda 100644 --- a/action.yml +++ b/action.yml @@ -24,7 +24,7 @@ outputs: description: "Post's title" runs: - using: "node12" + using: "node16" main: "publish.py" branding: From 80054870bc5b505044d2e2f3d4ca0fc3bfd4eb32 Mon Sep 17 00:00:00 2001 From: shivam Date: Wed, 20 Sep 2023 11:18:48 +0530 Subject: [PATCH 10/15] composite action for python script --- action.yml | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 5096dda..f9d2683 100644 --- a/action.yml +++ b/action.yml @@ -1,13 +1,13 @@ name: publish-to-twitter -description: posts tweets on twitter +description: posts tweets on Twitter author: IntelOwl inputs: api_key: - description: "Api key" + description: "API key" required: true api_key_secret: - description: "Api key secret" + description: "API key secret" required: true access_token: description: "Consumer access token" @@ -16,7 +16,7 @@ inputs: description: "Consumer access token secret" required: true status: - description: "Status to be published to twitter" + description: "Status to be published to Twitter" required: true outputs: @@ -24,8 +24,28 @@ outputs: description: "Post's title" runs: - using: "node16" - main: "publish.py" + using: "composite" + steps: + - name: echo the variables + run: echo ${{ inputs.api_key }} + shell: bash + + - 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 script.py ${{ inputs.api_key }} ${{ inputs.api_key_secret }} ${{ inputs.access_token }} ${{ inputs.access_token_secret }}${{ inputs.status }} + shell: bash branding: icon: "message-circle" From ed714606cb0fd8e342de3dc8645fef0409af59c9 Mon Sep 17 00:00:00 2001 From: shivam Date: Wed, 20 Sep 2023 11:24:17 +0530 Subject: [PATCH 11/15] add support for action.yml --- publish.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/publish.py b/publish.py index 219502b..0c87c3b 100644 --- a/publish.py +++ b/publish.py @@ -1,12 +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=os.environ['api_key'], - consumer_secret=os.environ['api_key_secret'], - access_token=os.environ['access_token'], - access_token_secret=os.environ['access_token_secret'] + consumer_key=api_key, + consumer_secret=api_key_secret, + access_token=access_token, + access_token_secret=access_token_secret ) -tweet_content = os.environ['status'] +tweet_content = status # Use the 'status' input variable client.create_tweet(text = tweet_content) \ No newline at end of file From 09825cc1b642b77de0624c6eea50b7a059955cb6 Mon Sep 17 00:00:00 2001 From: shivam Date: Wed, 20 Sep 2023 11:38:18 +0530 Subject: [PATCH 12/15] remove unneccessary steps --- action.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index f9d2683..d287686 100644 --- a/action.yml +++ b/action.yml @@ -25,11 +25,7 @@ outputs: runs: using: "composite" - steps: - - name: echo the variables - run: echo ${{ inputs.api_key }} - shell: bash - + steps: - name: Checkout code uses: actions/checkout@v2 @@ -44,7 +40,7 @@ runs: shell: bash - name: Run tweet script - run: python3 script.py ${{ inputs.api_key }} ${{ inputs.api_key_secret }} ${{ inputs.access_token }} ${{ inputs.access_token_secret }}${{ inputs.status }} + run: python3 script.py ${{ inputs.api_key }} ${{ inputs.api_key_secret }} ${{ inputs.access_token }} ${{ inputs.access_token_secret }} ${{ inputs.status }} shell: bash branding: From e79bbcb3003f6ca35d357711a6f7705b418b93b8 Mon Sep 17 00:00:00 2001 From: shivam Date: Wed, 20 Sep 2023 11:40:33 +0530 Subject: [PATCH 13/15] capture status as a sentence --- action.yml | 2 +- publish.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index d287686..808ddf7 100644 --- a/action.yml +++ b/action.yml @@ -40,7 +40,7 @@ runs: shell: bash - name: Run tweet script - run: python3 script.py ${{ inputs.api_key }} ${{ inputs.api_key_secret }} ${{ inputs.access_token }} ${{ inputs.access_token_secret }} ${{ inputs.status }} + run: python3 publish.py ${{ inputs.api_key }} ${{ inputs.api_key_secret }} ${{ inputs.access_token }} ${{ inputs.access_token_secret }} "${{ inputs.status }}" shell: bash branding: diff --git a/publish.py b/publish.py index 0c87c3b..9c647b4 100644 --- a/publish.py +++ b/publish.py @@ -15,5 +15,5 @@ access_token_secret=access_token_secret ) -tweet_content = status # Use the 'status' input variable +tweet_content = status client.create_tweet(text = tweet_content) \ No newline at end of file From cc262fc543590c423dc697fc73ef7a38cc2f82fc Mon Sep 17 00:00:00 2001 From: shivam Date: Wed, 20 Sep 2023 11:42:21 +0530 Subject: [PATCH 14/15] update test.yml --- .github/workflows/test.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4de7789..499c4cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,9 +20,10 @@ jobs: pip install tweepy - name: Run tweet script - run: python script.py - env: - TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }} - TWITTER_API_KEY_SECRET: ${{ secrets.TWITTER_API_KEY_SECRET }} - TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} - TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} \ No newline at end of file + 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 }} \ No newline at end of file From b4dab4ab3bd370916f754f80073ef3c4da7c8595 Mon Sep 17 00:00:00 2001 From: shivam Date: Wed, 20 Sep 2023 11:46:11 +0530 Subject: [PATCH 15/15] add empty lines --- .github/workflows/test.yml | 2 +- action.yml | 2 +- publish.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 499c4cf..3f9dfb8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,4 +26,4 @@ jobs: 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 }} \ No newline at end of file + access_token_secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} diff --git a/action.yml b/action.yml index 808ddf7..1ad75ac 100644 --- a/action.yml +++ b/action.yml @@ -45,4 +45,4 @@ runs: branding: icon: "message-circle" - color: "blue" \ No newline at end of file + color: "blue" diff --git a/publish.py b/publish.py index 9c647b4..72f9fb5 100644 --- a/publish.py +++ b/publish.py @@ -16,4 +16,4 @@ ) tweet_content = status -client.create_tweet(text = tweet_content) \ No newline at end of file +client.create_tweet(text = tweet_content)