diff --git a/actions/tweet-article/action.yml b/actions/tweet-article/action.yml new file mode 100644 index 0000000..5a66121 --- /dev/null +++ b/actions/tweet-article/action.yml @@ -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 }} diff --git a/workflows/this-is-angular-rss.yml b/workflows/this-is-angular-rss.yml index 6e82adb..b223f9a 100644 --- a/workflows/this-is-angular-rss.yml +++ b/workflows/this-is-angular-rss.yml @@ -1,31 +1,22 @@ on: rss: - url: https://dev.to/feed/this-is-angular + url: https://dev.to/feed/this-is-learning + +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 }} \ No newline at end of file + 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 }} diff --git a/workflows/this-is-learning-rss.yml b/workflows/this-is-learning-rss.yml index d604aff..ecdf118 100644 --- a/workflows/this-is-learning-rss.yml +++ b/workflows/this-is-learning-rss.yml @@ -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 }}