Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: extract composite tweet article action #2

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions actions/tweet-article/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Tweet article

inputs:
rss-author:
description: The article author
required: true
rss-categories:
description: The article categories
required: true
rss-link:
description: The article link
required: true
rss-title:
description: The article title
required: true
twitter-authentication-access-token:
description: The Twitter authentication access token
required: true
twitter-authentication-access-token-secret:
description: The Twitter authentication access token secret
required: true
twitter-consumer-api-key:
description: The Twitter consumer API key
required: true
twitter-consumer-api-key-secret:
description: The Twitter consumer API key secret
required: true

runs:
using: composite

steps:
- name: Map RSS categories to hashtags
uses: actions/github-script@v5
id: categories-to-tags
env:
categories: ${{ on.rss.outputs.categories }}
with:
script: |
return (process.env?.categories ?? [])
.split(',')
.map(tag => `#${tag}`)
.join(' ');
result-encoding: string
- name: Tweet about article
uses: ethomson/send-tweet-action@v1
with:
status: |
"${{ inputs.rss-title }}" by ${{ inputs.rss-author }} ${{ steps.categories-to-tags.outputs.result }}
${{ inputs.rss-link }}
consumer-key: ${{ inputs.twitter-consumer-api-key }}
consumer-secret: ${{ inputs.twitter-consumer-api-key-secret }}
access-token: ${{ inputs.twitter-authentication-access-token }}
access-token-secret: ${{ inputs.twitter-authentication-access-token-secret }}
39 changes: 15 additions & 24 deletions workflows/this-is-angular-rss.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
on:
rss:
url: https://dev.to/feed/this-is-angular
url: https://dev.to/feed/this-is-learning

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know why URL is incorrect 😅

concurrency: this-is-angular-rss

jobs:
Tweet:
name: Tweet
tweet:
name: Tweet article
runs-on: ubuntu-latest
steps:
- name: categories to tags
uses: actions/github-script@v4
id: categories-to-tag
env:
categories: ${{ on.rss.outputs.categories }}
with:
script: |
if(!process.env?.categories) {
return "";
}
return process.env.categories.split(",").map(t => `#${t}`).join(" ");
result-encoding: string
- name: Post To This is Angular
uses: ethomson/send-tweet-action@v1
- name: Tweet about article
uses: this-is-learning/twitter-feed/actions/tweet-article@refactor/refactor-tweet-workflows
with:
status: |
"${{ on.rss.outputs.title }}" by ${{ on.rss.outputs.author }} ${{steps.categories-to-tag.outputs.result}}
${{ on.rss.outputs.link }}
consumer-key: ${{ secrets.TIA_TWITTER_CONSUMER_KEY }}
consumer-secret: ${{ secrets.TIA_TWITTER_CONSUMER_SECRET }}
access-token: ${{ secrets.TIA_TWITTER_ACCESS_TOKEN }}
access-token-secret: ${{ secrets.TIA_TWITTER_ACCESS_SECRET }}
rss-author: ${{ on.rss.outputs.author }}
rss-categories: ${{ on.rss.outputs.categories }}
rss-link: ${{ on.rss.outputs.link }}
rss-title: ${{ on.rss.outputs.title }}
twitter-authentication-access-token: ${{ secrets.TIA_TWITTER_ACCESS_TOKEN }}
twitter-authentication-access-token-secret: ${{ secrets.TIA_TWITTER_ACCESS_SECRET }}
twitter-consumer-api-key: ${{ secrets.TIA_TWITTER_CONSUMER_KEY }}
twitter-consumer-api-key-secret: ${{ secrets.TIA_TWITTER_CONSUMER_SECRET }}
37 changes: 14 additions & 23 deletions workflows/this-is-learning-rss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@ on:
rss:
url: https://dev.to/feed/this-is-learning

concurrency: this-is-learning-rss

jobs:
Tweet:
name: Tweet
tweet:
name: Tweet article
runs-on: ubuntu-latest
steps:
- name: categories to tags
uses: actions/github-script@v4
id: categories-to-tag
env:
categories: ${{ on.rss.outputs.categories }}
with:
script: |
if(!process.env?.categories) {
return "";
}
return process.env.categories.split(",").map(t => `#${t}`).join(" ");
result-encoding: string
- name: Post to This is Learning
uses: ethomson/send-tweet-action@v1
- name: Tweet about article
uses: this-is-learning/twitter-feed/actions/tweet-article@refactor/refactor-tweet-workflows
with:
status: |
"${{ on.rss.outputs.title }}" by ${{ on.rss.outputs.author }} ${{steps.categories-to-tag.outputs.result}}
${{ on.rss.outputs.link }}
consumer-key: ${{ secrets.TIL_TWITTER_CONSUMER_KEY }}
consumer-secret: ${{ secrets.TIL_TWITTER_CONSUMER_SECRET }}
access-token: ${{ secrets.TIL_TWITTER_ACCESS_TOKEN }}
access-token-secret: ${{ secrets.TIL_TWITTER_ACCESS_SECRET }}
rss-author: ${{ on.rss.outputs.author }}
rss-categories: ${{ on.rss.outputs.categories }}
rss-link: ${{ on.rss.outputs.link }}
rss-title: ${{ on.rss.outputs.title }}
twitter-authentication-access-token: ${{ secrets.TIL_TWITTER_ACCESS_TOKEN }}
twitter-authentication-access-token-secret: ${{ secrets.TIL_TWITTER_ACCESS_SECRET }}
twitter-consumer-api-key: ${{ secrets.TIL_TWITTER_CONSUMER_KEY }}
twitter-consumer-api-key-secret: ${{ secrets.TIL_TWITTER_CONSUMER_SECRET }}