-
Notifications
You must be signed in to change notification settings - Fork 68
49 lines (48 loc) · 1.81 KB
/
send_tweet.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: send a tweet if PR is merged (and there is a tweet to be sent)
on:
pull_request:
types: [closed]
env:
TWEET_KEYWORD: '__[tweet]__'
TWEET_SENT_KEYWORD: '__[tweet sent]__'
jobs:
publish_tweet:
runs-on: ubuntu-latest
if: github.event.pull_request.merged
steps:
- name: find the tweet comment matching the keyword env.TWEET_KEYWORD
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{github.event.pull_request.number}}
comment-author: github-actions[bot]
body-includes: ${{env.TWEET_KEYWORD}}
- name: if tweet CI comment is found, extract tweet from comment body
id: extract-tweet
if: ${{steps.fc.outputs.comment-id != null}}
env:
COMMENT_BODY: ${{steps.fc.outputs.comment-body}}
run: |
body=$(echo "$COMMENT_BODY" | sed '1d' | sed 's/> //')
# escape file content to preserve new lines
# (see example in https://github.com/peter-evans/create-or-update-comment)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: tweet the message
if: ${{steps.fc.outputs.comment-id != null}}
uses: ethomson/send-tweet-action@v1
with:
status: ${{steps.extract-tweet.outputs.body}}
consumer-key: ${{secrets.TWITTER_API_KEY}}
consumer-secret: ${{secrets.TWITTER_API_SECRET_KEY}}
access-token: ${{secrets.TWITTER_ACCESS_TOKEN}}
access-token-secret: ${{secrets.TWITTER_ACCESS_TOKEN_SECRET}}
- name: clear tweet keyword
if: ${{steps.fc.outputs.comment-id != null}}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{steps.fc.outputs.comment-id}}
edit-mode: replace
body: ${{env.TWEET_SENT_KEYWORD}}