WIP: Set up the test job to debug Mailcoach blog announcements #25
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "WIP: Test RSS check job" | |
on: [push] | |
jobs: | |
check-blog-changes: | |
name: Check for new blog posts to announce | |
runs-on: ubuntu-latest | |
container: httptoolkit/act-build-base:v3.0.0 | |
outputs: | |
new-blog-post: ${{ steps.detect-changes.outputs.new-blog-post }} | |
steps: | |
- id: detect-changes | |
name: 'Check for RSS differences' | |
run: | | |
echo "new-blog-post=debug-failing-docker-container" >> "$GITHUB_OUTPUT" | |
announce-blog-changes: | |
name: Announce new blog posts | |
if: github.event_name == 'push' && needs.check-blog-changes.outputs.new-blog-post != '' | |
runs-on: ubuntu-latest | |
container: httptoolkit/act-build-base:v3.0.0 | |
needs: | |
- check-blog-changes | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Send an email about the new blog post with Mailcoach | |
run: | | |
set -x | |
SLUG="${{ needs.check-blog-changes.outputs.new-blog-post }}" | |
URL="https://httptoolkit.com/blog/$SLUG/" | |
MARKDOWN=$(cat "src/posts/$SLUG.md") | |
echo "Parsing markdown..." | |
FRONTMATTER=$(echo "$MARKDOWN" | sed -n '/^---$/,/^---$/p') | |
# Get the title - stripping any surrounding quotes if required | |
TITLE=$(echo "$FRONTMATTER" | | |
sed -n 's/^title: //p' | | |
sed 's/^"//; s/"$//' | | |
sed "s/^'//; s/'$//" | |
) | |
# Get the post content, stripping out frontmatter: | |
CONTENT=$(echo "$MARKDOWN" | sed '0,/^---$/d; 0,/^---$/d') | |
API_ENDPOINT="https://http-toolkit.mailcoach.app/api/campaigns" | |
echo "Creating campaign..." | |
# Create a Mailcoach campaign for this blog post email: | |
CAMPAIGN_ID=$( | |
curl \ | |
-f -X POST $API_ENDPOINT \ | |
-H "Authorization: Bearer $MAILCOACH_TOKEN" \ | |
-H 'Accept: application/json' \ | |
-H 'Content-Type: application/json' \ | |
-d '{ | |
"name": "Blog post: "'$TITLE'", | |
"email_list_uuid": "'$MAILING_LIST_UUID'", | |
"template_uuid": "'$EMAIL_TEMPLATE_ID'", | |
"fields": [ | |
{ | |
"url": "'$URL'", | |
"title": "'$TITLE'", | |
"content": '$(echo "$CONTENT" | jq -R -r -s @json)' | |
} | |
] | |
}' | |
) | |
echo "Sending test email..." | |
# Send a test email with this content immediately: | |
curl -f -X POST "$API_ENDPOINT/$CAMPAIGN_ID/send-test" \ | |
-H "Authorization: Bearer $MAILCOACH_TOKEN" \ | |
-H 'Accept: application/json' \ | |
-H 'Content-Type: application/json' \ | |
-d '{"email":"'$TEST_EMAIL'"}' | |
echo "Scheduling mailing list email..." | |
# Schedule the email to send in 3 hours: | |
curl -X PUT "$API_ENDPOINT/$CAMPAIGN_ID" \ | |
-H "Authorization: Bearer $MAILCOACH_TOKEN" \ | |
-H 'Accept: application/json' \ | |
-H 'Content-Type: application/json' \ | |
-d '{"schedule_at":"'$(date -u -d "3 hours" +"%Y-%m-%d %H:%M:%S")'"}' | |
env: | |
MAILCOACH_TOKEN: ${{ secrets.MAILCOACH_TOKEN }} | |
EMAIL_TEMPLATE_ID: ${{ vars.BLOG_POST_EMAIL_TEMPLATE_ID }} | |
MAILING_LIST_UUID: ${{ vars.BLOG_POST_MAILING_LIST_UUID }} | |
TEST_EMAIL: ${{ vars.BLOG_POST_TEST_EMAIL }} |