Skip to content

ci: DLT-1479 send blog post notification to #dialtone channel #24

ci: DLT-1479 send blog post notification to #dialtone channel

ci: DLT-1479 send blog post notification to #dialtone channel #24

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"
token_format: "id_token"
id_token_audience: "https://us-central1-dp-dialtone-design-system.cloudfunctions.net/send-sms-to-dialtone-channel"
# - 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.id_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 }}"
# }'