-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (132 loc) · 4.99 KB
/
bluesky-new-post.yml
File metadata and controls
154 lines (132 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Post New Blog to Bluesky
on:
workflow_run:
workflows: ["Scheduled Deploy"]
types:
- completed
schedule:
# 8 AM Eastern: 13:00 UTC (EST) / 12:00 UTC (EDT)
# Using 13:00 UTC = 8 AM EST, 9 AM EDT
- cron: '0 13 * * *'
workflow_dispatch:
inputs:
target_date:
description: 'Date to look for posts (YYYY-MM-DD). Defaults to current date.'
required: false
type: string
jobs:
check-trigger:
runs-on: ubuntu-latest
outputs:
should_continue: ${{ steps.check.outputs.should_continue }}
steps:
- name: Check if we should continue
id: check
run: |
if [ "${{ github.event_name }}" == "workflow_run" ]; then
if [ "${{ github.event.workflow_run.conclusion }}" != "success" ]; then
echo "Scheduled Deploy failed, skipping"
echo "should_continue=false" >> $GITHUB_OUTPUT
exit 0
fi
fi
echo "should_continue=true" >> $GITHUB_OUTPUT
detect:
needs: check-trigger
if: needs.check-trigger.outputs.should_continue == 'true'
uses: CodingWithCalvin/.github/.github/workflows/detect-blog-post-from-rss.yml@main
with:
rss_url: 'https://www.codingwithcalvin.net/rss.xml'
target_date: ${{ inputs.target_date }}
notify-bluesky:
needs: detect
if: needs.detect.outputs.has_posts == 'true'
uses: CodingWithCalvin/.github/.github/workflows/bluesky-post.yml@main
with:
post_text: |
New Blog Post!
[${{ needs.detect.outputs.post_title }}](${{ needs.detect.outputs.post_url }})
${{ needs.detect.outputs.post_hashtags }}
embed_url: ${{ needs.detect.outputs.post_url }}
embed_title: ${{ needs.detect.outputs.post_title }}
embed_description: ${{ needs.detect.outputs.post_description }}
embed_image_url: ${{ needs.detect.outputs.post_image_url }}
secrets:
BLUESKY_USERNAME: ${{ secrets.BLUESKY_USERNAME }}
BLUESKY_APP_PASSWORD: ${{ secrets.BLUESKY_APP_PASSWORD }}
notify-x:
needs: detect
if: needs.detect.outputs.has_posts == 'true'
uses: CodingWithCalvin/.github/.github/workflows/x-post.yml@main
with:
post_text: |
New Blog Post!
${{ needs.detect.outputs.post_title }}
${{ needs.detect.outputs.post_hashtags }}
embed_url: ${{ needs.detect.outputs.post_url }}
secrets:
X_CONSUMER_KEY: ${{ secrets.X_CONSUMER_KEY }}
X_CONSUMER_KEY_SECRET: ${{ secrets.X_CONSUMER_KEY_SECRET }}
X_ACCESS_TOKEN: ${{ secrets.X_ACCESS_TOKEN }}
X_ACCESS_TOKEN_SECRET: ${{ secrets.X_ACCESS_TOKEN_SECRET }}
update-frontmatter:
needs: [detect, notify-bluesky]
if: needs.detect.outputs.has_posts == 'true' && needs.notify-bluesky.outputs.post_id != ''
runs-on: ubuntu-latest
steps:
- name: Checkout blog repo
uses: actions/checkout@v4
with:
token: ${{ secrets.CONTRIBUTORS_TOKEN }}
- name: Find and update blog post
run: |
POST_URL="${{ needs.detect.outputs.post_url }}"
POST_ID="${{ needs.notify-bluesky.outputs.post_id }}"
echo "Post URL: $POST_URL"
echo "Post ID: $POST_ID"
# Extract slug from URL (e.g., https://www.codingwithcalvin.net/my-post/ -> my-post)
SLUG=$(echo "$POST_URL" | sed -E 's|https?://[^/]+/([^/]+)/?|\1|')
echo "Extracted slug: $SLUG"
# Find the markdown file (could be in any year directory)
FILE=$(find src/content/blog -path "*/${SLUG}/index.md" | head -1)
if [ -z "$FILE" ]; then
echo "Could not find file for slug: $SLUG"
exit 1
fi
echo "Found file: $FILE"
# Check if blueskyPostId already exists
if grep -q "^blueskyPostId:" "$FILE"; then
echo "blueskyPostId already exists, skipping"
exit 0
fi
# Add blueskyPostId before the closing --- of frontmatter
# Using awk for more reliable YAML manipulation
awk -v post_id="$POST_ID" '
BEGIN { in_frontmatter = 0; frontmatter_end = 0 }
/^---$/ {
if (in_frontmatter == 0) {
in_frontmatter = 1
print
next
} else {
print "blueskyPostId: \"" post_id "\""
in_frontmatter = 0
frontmatter_end = 1
}
}
{ print }
' "$FILE" > "$FILE.tmp" && mv "$FILE.tmp" "$FILE"
echo "Updated $FILE with blueskyPostId: $POST_ID"
echo "New frontmatter:"
head -20 "$FILE"
- name: Commit and push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "chore(blog): add blueskyPostId to post frontmatter"
git push