Skip to content

Publish Alerts

Publish Alerts #955

Workflow file for this run

name: Publish Alerts
on:
# run everyday at 12:20 utf ( 8:20 am est) to alert on new posts
schedule:
- cron: '40 12 * * *'
workflow_dispatch:
jobs:
build-website:
name: Build Alert List
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/github-env-vars-action@v2
- name: Checkout code
uses: actions/checkout@v2
## Write into published.txt what's been published
## Write into steps.published_check.outputs the outputs
- name: Has new published documents
id: published_check
run: |-
if [ "$CI_ACTION_REF_NAME" == "main" ]; then
pattern=$(date '+%Y-%m-%d')
if test -n "$(find ./blog/_posts -maxdepth 1 -name "*$pattern*" -print)"
then
echo "Setting Publish Flag"
echo "PUBLISHED=1" >> $GITHUB_ENV
echo "Writing blog paths to posts.txt"
find ./blog/_posts -maxdepth 1 -name "*$pattern*" -print > posts.txt
echo "Writing list of post urls to PUBLISHED_LIST for future steps"
echo 'PUBLISHED_LIST<<EOF' >> $GITHUB_ENV
awk '{ print "https://earthly.dev/blog/"substr( $0, 26, length($0)-28 ) }' < posts.txt | tr '\n' "," | sed 's/,/\\n/g' >> $GITHUB_ENV
echo '\n' >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
fi
fi
## Check output value for whether file exists
- name: Check file existence
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "posts.txt"
# Output published list
- name: Slack Notification
id: slack1
if: steps.check_files.outputs.files_exists == 'true'
run: |-
echo "Community Blog Alert"
curl -X POST -H 'Content-type: application/json' --data '{"text":"${{ env.PUBLISHED_LIST }}"}' $SLACK_WEBHOOK_URL
env:
## Zapier web hook (which controls formatting)
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# Output blog post for
- name: Slack Community Notification
id: slack2
if: steps.check_files.outputs.files_exists == 'true'
run: |-
echo "Community Blog Alert"
curl -X POST -H 'Content-type: application/json' --data '{"text":"${{ env.PUBLISHED_LIST }}"}' $SLACK_WEBHOOK_URL
env:
## Zapier web hook (which controls formatting)
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_COMMUNITY_BLOG_WEBHOOK_URL }}