-
Notifications
You must be signed in to change notification settings - Fork 4
159 lines (144 loc) · 5.08 KB
/
send-blog-communications.yml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Send blog communications
on:
pull_request:
types:
- synchronize
push:
branches:
- production
paths:
- 'apps/dialtone-documentation/docs/about/whats-new/posts/*.md'
env:
HUSKY: 0
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
added-posts:
name: Get added posts
runs-on: ubuntu-latest
outputs:
added_posts: ${{ steps.changed-files.outputs.added_files }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
with:
files: 'apps/dialtone-documentation/docs/about/whats-new/posts/*.md'
json: true
escape_json: false
- name: List all added posts
run: echo '${{ steps.changed-files.outputs.added_files }}'
send-email:
if: false
name: Send email
runs-on: ubuntu-latest
needs: [added-posts]
strategy:
matrix:
files: ${{ fromJSON(needs.added-posts.outputs.added_posts) }}
env:
FROM_MAIL: ${{ secrets.MAIL_ACCOUNT }}
TO_MAIL: julio.ortega@dialpad.com
FILE_PATH: ${{ matrix.files }}
REPLY_TO: dialtone@dialpad.com
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get link from file name
id: get-post-url
run: |
PREFIX="https:\/\/dialtone.dialpad.com"
echo "POST_URL=$(echo $FILE_PATH | sed -e "s/apps\/dialtone-documentation\/docs/$PREFIX/" -e 's/md/html/')" >> $GITHUB_ENV
- name: Get heading from blog post
id: get-heading
run: |
echo "BLOG_POST_HEADING=$(sed -n 's/^heading: *//p' $FILE_PATH)" >> $GITHUB_ENV
# This will do the following:
# - Remove frontmatter.
# - Remove script setup.
# - Remove blog post component.
# - Remove comments.
# - Remove empty lines at the beginning of the file.
# - Replace links paths for their absolute paths (prefixed by https://dialtone.dialpad.com).
# - Ellipsis the article to the first 10 lines.
# - Append the URL of the article at the end of the article.
- name: Process Markdown file
run: >
sed -i -E
-e '/^---$/,/^---$/d'
-e '/^<script setup>$/,/^<\/script>$/d'
-e '/^<\/*BlogPost.*$/d'
-e '/^<!--.*$/d'
-e '/./,$!d'
-e 's_(\[.*\])\(([^)]+)\)_\1(https://dialtone.dialpad.com\2)_g'
$FILE_PATH &&
sed -i 10q $FILE_PATH &&
echo -e "... Read the full article: $POST_URL" >> $FILE_PATH;
- name: Send email
uses: dawidd6/action-send-mail@v3
with:
connection_url: ${{ secrets.MAIL_CONNECTION }}
subject: "[dialtone] New blog post: '${{ env.BLOG_POST_HEADING }}'"
to: ${{ env.TO_MAIL }}
from: Dialtone <${{ env.FROM_MAIL }}>
html_body: file://${{ env.FILE_PATH }}
bcc: ${{ env.FROM_MAIL }}
reply_to: ${{ env.REPLY_TO }}
convert_markdown: true
# Optional nodemailer log: true/false
nodemailerlog: true
# Optional nodemailer debug: true/false
# if true log nodemailer will also be set true
nodemailerdebug: true
send-sms:
name: Send SMS
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
needs: [ added-posts ]
strategy:
matrix:
files: ${{ fromJSON(needs.added-posts.outputs.added_posts) }}
env:
FILE_PATH: ${{ matrix.files }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get link from file name
id: get-post-url
run: |
PREFIX="https:\/\/dialtone.dialpad.com"
echo "POST_URL=$(echo $FILE_PATH | sed -e "s/apps\/dialtone-documentation\/docs/$PREFIX/" -e 's/md/html/')" >> $GITHUB_ENV
- name: Get heading from blog post
id: get-heading
run: |
echo "BLOG_POST_HEADING=$(sed -n 's/^heading: *//p' $FILE_PATH)" >> $GITHUB_ENV
- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.DIALTONE_GCP_WIP }}
service_account: ${{ secrets.DIALTONE_GCP_SA }}
token_format: "access_token"
# - name: Set up Cloud SDK
# uses: google-github-actions/setup-gcloud@v2
- name: Send sms
run: |
curl -m 70 -X POST https://us-central1-dp-dialtone-design-system.cloudfunctions.net/send-sms-to-dialtone-channel \
-H "Authorization: bearer ${{ steps.auth.outputs.access_token }}" \
-H "Content-Type: application/json" \
-d '{
"message": "New blog post: ${{ env.BLOG_POST_HEADING }}, read full article: ${{ env.POST_URL }}"
}'
# - name: Send sms
# run: |
# gcloud functions call send-sms-to-dialtone-channel-v1 \
# --data '{
# "message": "New blog post: ${{ env.BLOG_POST_HEADING }}, read full article: ${{ env.POST_URL }}"
# }'