WIP: Set up the test job to debug Mailcoach blog announcements #12
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: Get title & content for the changed post | |
id: read-post | |
run: | | |
SLUG="${{ needs.check-blog-changes.outputs.new-blog-post }}" | |
MARKDOWN=$(cat "src/posts/$SLUG.md") | |
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/'$//" | |
) | |
echo "title=$TITLE" >> "$GITHUB_OUTPUT" | |
echo "title is $TITLE" | |
URL="https://httptoolkit.com/blog/$SLUG/" | |
echo "url=$URL" >> "$GITHUB_OUTPUT" | |
echo "URL is $URL" | |
# Get the post content, stripping out frontmatter: | |
CONTENT=$(echo $MARKDOWN | sed '0,/^---$/d; 0,/^---$/d') | |
{ | |
echo 'content<<EOF_MARKDOWN_CONTENT_EOF' | |
echo $CONTENT | |
echo 'EOF_MARKDOWN_CONTENT_EOF' | |
} >> "$GITHUB_OUTPUT" | |
echo "Content is $CONTENT" | |
echo 'GH OUTPUT is:' | |
cat "$GITHUB_OUTPUT" | |
- name: Log the results for debugging | |
run: | | |
echo "Title: ${{ steps.read-post.outputs.title }}" | |
echo "URL: ${{ steps.read-post.outputs.url }}" | |
echo "Content: ${{ steps.read-post.outputs.content }}" | |
- name: Send an email about the new blog post with Mailcoach | |
run: | | |
API_ENDPOINT="https://http-toolkit.mailcoach.app/api/campaigns" | |
# 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: ${{ steps.read-post.outputs.title }}", | |
"email_list_uuid": "'$MAILING_LIST_UUID'", | |
"template_uuid": "'$EMAIL_TEMPLATE_ID'", | |
"fields": [ | |
{ | |
"title": "${{ steps.read-post.outputs.title }}", | |
"content": "${{ steps.read-post.outputs.content }}", | |
"url": "${{ steps.read-post.outputs.url }}" | |
} | |
] | |
}' | |
) | |
# 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'"}' | |
# 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 }} |