-
Notifications
You must be signed in to change notification settings - Fork 1
346 lines (295 loc) · 12 KB
/
Copy pathci.yml
File metadata and controls
346 lines (295 loc) · 12 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
name: Deploy Blog
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
models: read
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
env:
BUILD_PATH: "." # default value when not using subfolders
# BUILD_PATH: subfolder
jobs:
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
outputs:
page-url: ${{ steps.deployment.outputs.page_url }}
new-posts: ${{ steps.detect.outputs.new-posts }}
has-new-posts-without-bluesky: ${{ steps.detect.outputs.has-new-posts-without-bluesky }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Detect new posts without Bluesky URI
id: detect
run: |
# Get changed files
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"
# Find new posts in src/content/post/
NEW_POSTS=$(echo "$CHANGED_FILES" | grep "^src/content/post/.*\.mdx\?$" | grep -v "^D" || true)
echo "New posts: $NEW_POSTS"
# Check if any new posts don't have blueskyPostURI
HAS_NEW_POSTS_WITHOUT_BLUESKY="false"
NEW_POSTS_WITHOUT_BLUESKY=""
if [ ! -z "$NEW_POSTS" ]; then
for post in $NEW_POSTS; do
if [ -f "$post" ]; then
# Check if post has blueskyPostURI in frontmatter (only between --- markers)
FRONTMATTER=$(awk '/^---$/{if(seen){exit} seen=1; next} seen{print}' "$post")
if ! echo "$FRONTMATTER" | grep -q "blueskyPostURI:"; then
HAS_NEW_POSTS_WITHOUT_BLUESKY="true"
if [ -z "$NEW_POSTS_WITHOUT_BLUESKY" ]; then
NEW_POSTS_WITHOUT_BLUESKY="$post"
else
NEW_POSTS_WITHOUT_BLUESKY="$NEW_POSTS_WITHOUT_BLUESKY,$post"
fi
fi
fi
done
fi
echo "new-posts=$NEW_POSTS_WITHOUT_BLUESKY" >> $GITHUB_OUTPUT
echo "has-new-posts-without-bluesky=$HAS_NEW_POSTS_WITHOUT_BLUESKY" >> $GITHUB_OUTPUT
echo "Has new posts without Bluesky: $HAS_NEW_POSTS_WITHOUT_BLUESKY"
echo "New posts without Bluesky: $NEW_POSTS_WITHOUT_BLUESKY"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "24"
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Setup Yarn
run: corepack enable
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.yarn/cache
node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install dependencies
run: |
yarn install --frozen-lockfile
npx playwright install-deps chromium
npm install sharp
working-directory: ${{ env.BUILD_PATH }}
- name: Build with Astro
run: |
yarn generate-json
yarn astro check
yarn astro build \
--site "${{ steps.pages.outputs.origin }}" \
--base "${{ steps.pages.outputs.base_path }}"
yarn generate-og-images
working-directory: ${{ env.BUILD_PATH }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
name: github-pages-initial
path: ${{ env.BUILD_PATH }}/dist
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
with:
artifact_name: github-pages-initial
bluesky-social:
name: Post to Bluesky
runs-on: ubuntu-latest
needs: build-and-deploy
if: needs.build-and-deploy.outputs.has-new-posts-without-bluesky == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Process new posts and post to Bluesky
id: process-posts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PAGE_URL: ${{ needs.build-and-deploy.outputs.page-url }}
run: |
# Install jq for JSON processing
sudo apt-get update && sudo apt-get install -y jq
# Initialize variables
BLUESKY_TEXT=""
POST_FILE=""
# Process each new post
IFS=',' read -ra POSTS <<< "${{ needs.build-and-deploy.outputs.new-posts }}"
for post_file in "${POSTS[@]}"; do
echo "Processing $post_file"
# Extract post title and description
POST_TITLE=$(grep "^title:" "$post_file" | sed 's/title: *"//' | sed 's/"$//')
POST_DESCRIPTION=$(grep "^description:" "$post_file" | sed 's/description: *"//' | sed 's/"$//')
# Extract categories and tags for context
POST_CATEGORIES=$(grep "^categories:" "$post_file" | sed 's/categories: *//')
POST_TAGS=$(grep "^tags:" "$post_file" | sed 's/tags: *//')
# Extract and clean post content (first few paragraphs)
# Remove frontmatter and get first 500 characters of actual content
POST_CONTENT=$(awk '
BEGIN { in_frontmatter = 0; content_started = 0; }
/^---$/ {
if (in_frontmatter == 1) { content_started = 1; }
in_frontmatter = !in_frontmatter;
next;
}
content_started == 1 && in_frontmatter == 0 {
# Skip empty lines at start
if (NF == 0 && length(content) == 0) next;
# Skip markdown headers and links for cleaner text
gsub(/^#+\s*/, "");
gsub(/\[([^\]]*)\]\([^\)]*\)/, "\\1");
gsub(/\*\*([^\*]*)\*\*/, "\\1");
gsub(/\*([^\*]*)\*/, "\\1");
content = content " " $0;
if (length(content) > 500) exit;
}
END { print substr(content, 1, 500); }
' "$post_file")
# Convert file path to URL path
POST_URL_PATH=$(echo "$post_file" | sed 's|src/content/post/||' | sed 's|\.mdx\?$||')
POST_URL="${PAGE_URL}post/${POST_URL_PATH}/"
echo "Post title: $POST_TITLE"
echo "Post description: $POST_DESCRIPTION"
echo "Post URL: $POST_URL"
echo "Post categories: $POST_CATEGORIES"
echo "Post content preview: ${POST_CONTENT:0:200}..."
# Create enhanced prompt with post context
PROMPT="Write a short, engaging social media post (under 250 characters) for a new blog post. Use UK english, never use emdash and only use hashtags sparingly and if they fit into the body of the text in a way that reads like a sentence. Title: $POST_TITLE. Description: $POST_DESCRIPTION. Categories: $POST_CATEGORIES. Content preview: $POST_CONTENT. Make it conversational and include relevant hashtags. Don't include the URL."
AI_RESPONSE=$(curl -s "https://models.github.ai/inference/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-d "{
\"messages\": [
{
\"role\": \"user\",
\"content\": $(echo "$PROMPT" | jq -R -s .)
}
],
\"model\": \"openai/gpt-4.1\"
}")
# Extract the message from the response
AI_MESSAGE=$(echo "$AI_RESPONSE" | jq -r '.choices[0].message.content')
BLUESKY_TEXT="${AI_MESSAGE} ${POST_URL}"
POST_FILE="$post_file"
echo "Generated message: $BLUESKY_TEXT"
# Set outputs for next step
echo "BLUESKY_TEXT=$BLUESKY_TEXT" >> $GITHUB_OUTPUT
echo "POST_FILE=$POST_FILE" >> $GITHUB_OUTPUT
# Only process one post for now
break
done
- name: Post to Bluesky
if: steps.process-posts.outputs.BLUESKY_TEXT != ''
uses: zentered/bluesky-post-action@v0.1.0
id: bluesky-post
with:
post: ${{ steps.process-posts.outputs.BLUESKY_TEXT }}
env:
BSKY_IDENTIFIER: ${{ secrets.BSKY_IDENTIFIER }}
BSKY_PASSWORD: ${{ secrets.BSKY_PASSWORD }}
- name: Update post with Bluesky URI
if: steps.bluesky-post.outputs.uri != ''
run: |
# Update the post file with the Bluesky URI
POST_FILE="${{ steps.process-posts.outputs.POST_FILE }}"
# Find the line with draft: false and add blueskyPostURI after it
sed -i "/^draft: false$/a blueskyPostURI: \"${{ steps.bluesky-post.outputs.uri }}\"" "$POST_FILE"
echo "Updated $POST_FILE with Bluesky URI: ${{ steps.bluesky-post.outputs.uri }}"
- name: Commit updated post files
if: steps.bluesky-post.outputs.uri != ''
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add src/content/post/
git diff --staged --quiet || git commit -m "Add Bluesky post URI to new blog post"
git push
rebuild-after-bluesky:
name: Rebuild After Bluesky Update
runs-on: ubuntu-latest
needs: bluesky-social
if: always() && needs.bluesky-social.result == 'success'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout updated code
uses: actions/checkout@v4
with:
ref: main
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "24"
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Setup Yarn
run: corepack enable
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.yarn/cache
node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install dependencies
run: |
yarn install --frozen-lockfile
- name: Install Playwright
run: npx playwright install-deps chromium
- name: Build with Astro
run: |
yarn generate-json
yarn astro check
yarn astro build \
--site "${{ steps.pages.outputs.origin }}" \
--base "${{ steps.pages.outputs.base_path }}"
yarn generate-og-images
working-directory: ${{ env.BUILD_PATH }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
name: github-pages-final
path: ${{ env.BUILD_PATH }}/dist
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
with:
artifact_name: github-pages-final