Skip to content

Commit

Permalink
WIP: Set up the test job to debug Mailcoach blog announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Nov 2, 2023
1 parent 8dddc85 commit 3fd6f53
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 245 deletions.
245 changes: 0 additions & 245 deletions .github/workflows/ci.yml

This file was deleted.

96 changes: 96 additions & 0 deletions .github/workflows/test-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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 }}

0 comments on commit 3fd6f53

Please sign in to comment.