Skip to content

Commit 26070b1

Browse files
committed
simplified manipulation of comment body
1 parent 7f237f5 commit 26070b1

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

.github/workflows/gen_tweet.yaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,19 @@ jobs:
8383
- name: extract the new tweet message
8484
id: get-comment-body
8585
run: |
86-
echo "${{github.event.comment.body}}" | sed '1 s/#tweet//' | sed '1 s/ //' > tweet.txt
87-
echo ::set-output name=tweet_length::$(cat tweet.txt | tr -d '\n\r%' | wc -c)
88-
sed 's/^/> /' tweet.txt > tweet_quote.txt
89-
# escape file content to preserve new lines
86+
body=$(echo "${{github.event.comment.body}}" | sed '1 s/#tweet//' | sed '1 s/ //')
87+
echo ::set-output name=tweet_length::$(echo $body | tr -d '\n\r%' | wc -c)
88+
body_quote=$(echo $body | sed 's/^/> /')
89+
# escape string content to preserve new lines
9090
# (see example in https://github.com/peter-evans/create-or-update-comment)
91-
body=$(cat tweet.txt)
9291
body="${body//'%'/'%25'}"
9392
body="${body//$'\n'/'%0A'}"
9493
body="${body//$'\r'/'%0D'}"
95-
echo ::set-output name=body::$body
96-
body_quote=$(cat tweet_quote.txt)
9794
body_quote="${body_quote//'%'/'%25'}"
9895
body_quote="${body_quote//$'\n'/'%0A'}"
9996
body_quote="${body_quote//$'\r'/'%0D'}"
97+
echo ::set-output name=body::$body
10098
echo ::set-output name=body_quote::$body_quote
101-
rm tweet.txt tweet_quote.txt
10299
- name: print new tweet CI message in a new comment
103100
uses: peter-evans/create-or-update-comment@v1
104101
with:

.github/workflows/send_tweet.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ jobs:
2222
id: extract-tweet
2323
if: ${{steps.fc.outputs.comment-id != null}}
2424
run: |
25-
echo "${{steps.fc.outputs.comment-body}}" | sed '1d' | sed 's/> //' > tweet.txt
25+
body=$(echo "${{steps.fc.outputs.comment-body}}" | sed '1d' | sed 's/> //')
2626
# escape file content to preserve new lines
2727
# (see example in https://github.com/peter-evans/create-or-update-comment)
28-
body=$(cat tweet.txt)
2928
body="${body//'%'/'%25'}"
3029
body="${body//$'\n'/'%0A'}"
3130
body="${body//$'\r'/'%0D'}"
3231
echo ::set-output name=body::$body
33-
rm tweet.txt
3432
- name: tweet the message
3533
if: ${{steps.fc.outputs.comment-id != null}}
3634
uses: ethomson/send-tweet-action@v1

0 commit comments

Comments
 (0)