Skip to content

Commit 14c0f51

Browse files
authored
feat(workflows): refactor social posting to use RSS detection (#18)
1 parent 5dbc446 commit 14c0f51

File tree

4 files changed

+86
-51
lines changed

4 files changed

+86
-51
lines changed

.github/workflows/bluesky-new-post.yml

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: Post New Blog to Bluesky
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
paths:
8-
- 'src/content/blog/**'
4+
workflow_run:
5+
workflows: ["Scheduled Deploy"]
6+
types:
7+
- completed
98
schedule:
109
# 8 AM Eastern: 13:00 UTC (EST) / 12:00 UTC (EDT)
1110
# Using 13:00 UTC = 8 AM EST, 9 AM EDT
@@ -18,34 +17,38 @@ on:
1817
type: string
1918

2019
jobs:
21-
detect:
22-
uses: CodingWithCalvin/.github/.github/workflows/detect-new-blog-post.yml@main
23-
with:
24-
content_path: 'src/content/blog'
25-
post_filename: 'index.md'
26-
site_url: 'https://www.codingwithcalvin.net'
27-
url_prefix: ''
28-
event_name: ${{ github.event_name }}
29-
categories_field: 'categories'
30-
target_date: ${{ inputs.target_date }}
31-
32-
wait-for-deploy:
33-
needs: detect
34-
if: needs.detect.outputs.has_new_post == 'true' && github.event_name == 'push'
20+
check-trigger:
3521
runs-on: ubuntu-latest
22+
outputs:
23+
should_continue: ${{ steps.check.outputs.should_continue }}
3624
steps:
37-
- name: Wait for Cloudflare deployment
25+
- name: Check if we should continue
26+
id: check
3827
run: |
39-
echo "Waiting 5 minutes for Cloudflare to deploy..."
40-
sleep 300
28+
if [ "${{ github.event_name }}" == "workflow_run" ]; then
29+
if [ "${{ github.event.workflow_run.conclusion }}" != "success" ]; then
30+
echo "Scheduled Deploy failed, skipping"
31+
echo "should_continue=false" >> $GITHUB_OUTPUT
32+
exit 0
33+
fi
34+
fi
35+
echo "should_continue=true" >> $GITHUB_OUTPUT
36+
37+
detect:
38+
needs: check-trigger
39+
if: needs.check-trigger.outputs.should_continue == 'true'
40+
uses: CodingWithCalvin/.github/.github/workflows/detect-blog-post-from-rss.yml@main
41+
with:
42+
rss_url: 'https://www.codingwithcalvin.net/rss.xml'
43+
target_date: ${{ inputs.target_date }}
4144

4245
notify:
43-
needs: [detect, wait-for-deploy]
44-
if: always() && needs.detect.outputs.has_new_post == 'true' && needs.detect.result == 'success'
46+
needs: detect
47+
if: needs.detect.outputs.has_posts == 'true'
4548
uses: CodingWithCalvin/.github/.github/workflows/bluesky-post.yml@main
4649
with:
4750
post_text: |
48-
📝 New Blog Post!
51+
New Blog Post!
4952
5053
[${{ needs.detect.outputs.post_title }}](${{ needs.detect.outputs.post_url }})
5154

.github/workflows/linkedin-new-post.yml

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: Post New Blog to LinkedIn
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
paths:
8-
- 'src/content/blog/**'
4+
workflow_run:
5+
workflows: ["Scheduled Deploy"]
6+
types:
7+
- completed
98
schedule:
109
# 8:15 AM Eastern (15 min after Bluesky to stagger)
1110
- cron: '15 13 * * *'
@@ -17,34 +16,38 @@ on:
1716
type: string
1817

1918
jobs:
20-
detect:
21-
uses: CodingWithCalvin/.github/.github/workflows/detect-new-blog-post.yml@main
22-
with:
23-
content_path: 'src/content/blog'
24-
post_filename: 'index.md'
25-
site_url: 'https://www.codingwithcalvin.net'
26-
url_prefix: ''
27-
event_name: ${{ github.event_name }}
28-
categories_field: 'categories'
29-
target_date: ${{ inputs.target_date }}
30-
31-
wait-for-deploy:
32-
needs: detect
33-
if: needs.detect.outputs.has_new_post == 'true' && github.event_name == 'push'
19+
check-trigger:
3420
runs-on: ubuntu-latest
21+
outputs:
22+
should_continue: ${{ steps.check.outputs.should_continue }}
3523
steps:
36-
- name: Wait for Cloudflare deployment
24+
- name: Check if we should continue
25+
id: check
3726
run: |
38-
echo "Waiting 5 minutes for Cloudflare to deploy..."
39-
sleep 300
27+
if [ "${{ github.event_name }}" == "workflow_run" ]; then
28+
if [ "${{ github.event.workflow_run.conclusion }}" != "success" ]; then
29+
echo "Scheduled Deploy failed, skipping"
30+
echo "should_continue=false" >> $GITHUB_OUTPUT
31+
exit 0
32+
fi
33+
fi
34+
echo "should_continue=true" >> $GITHUB_OUTPUT
35+
36+
detect:
37+
needs: check-trigger
38+
if: needs.check-trigger.outputs.should_continue == 'true'
39+
uses: CodingWithCalvin/.github/.github/workflows/detect-blog-post-from-rss.yml@main
40+
with:
41+
rss_url: 'https://www.codingwithcalvin.net/rss.xml'
42+
target_date: ${{ inputs.target_date }}
4043

4144
notify:
42-
needs: [detect, wait-for-deploy]
43-
if: always() && needs.detect.outputs.has_new_post == 'true' && needs.detect.result == 'success'
45+
needs: detect
46+
if: needs.detect.outputs.has_posts == 'true'
4447
uses: CodingWithCalvin/.github/.github/workflows/linkedin-post.yml@main
4548
with:
4649
post_text: |
47-
📝 New Blog Post!
50+
New Blog Post!
4851
4952
${{ needs.detect.outputs.post_title }}
5053

.github/workflows/scheduled-deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Scheduled Deploy
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'src/content/blog/**'
49
schedule:
510
# Run at 7:50 AM Eastern (12:50 UTC) - 10 min before Bluesky post
611
- cron: '50 12 * * *'

src/pages/rss.xml.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,47 @@ function normalizeDateForRss(date: Date): Date {
1010
return new Date(Date.UTC(year, month - 1, day, 12, 0, 0));
1111
}
1212

13+
function getMimeType(src: string): string {
14+
const ext = src.split('.').pop()?.toLowerCase();
15+
const mimeTypes: Record<string, string> = {
16+
png: 'image/png',
17+
jpg: 'image/jpeg',
18+
jpeg: 'image/jpeg',
19+
gif: 'image/gif',
20+
webp: 'image/webp',
21+
avif: 'image/avif',
22+
};
23+
return mimeTypes[ext || ''] || 'image/png';
24+
}
25+
1326
export async function GET(context: APIContext) {
1427
const posts = await getCollection('blog');
1528
const sortedPosts = posts.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
29+
const site = context.site!.toString().replace(/\/$/, '');
1630

1731
return rss({
1832
title: 'Coding With Calvin',
1933
description: 'Software development thoughts, tutorials, and experiences by Calvin Allen',
2034
site: context.site!,
2135
items: sortedPosts.map((post) => {
2236
const slug = post.id.split('/').pop() || post.id;
23-
return {
37+
const item: Record<string, unknown> = {
2438
title: post.data.title,
2539
pubDate: normalizeDateForRss(post.data.date),
2640
description: post.data.description || '',
2741
link: `/${slug}/`,
2842
categories: post.data.categories,
2943
};
44+
45+
if (post.data.image) {
46+
item.enclosure = {
47+
url: `${site}${post.data.image.src}`,
48+
type: getMimeType(post.data.image.src),
49+
length: 0,
50+
};
51+
}
52+
53+
return item;
3054
}),
3155
customData: `<language>en-us</language>`,
3256
});

0 commit comments

Comments
 (0)