Skip to content

Commit 5179ebb

Browse files
author
Shintaro Okamoto
committed
feat: add blog draft CI — label enforcement + Kiro CLI headless generation
- require-blog-label.yml: PRs must have blog:pending or blog:skip label before merge. Bot PRs get blog:skip automatically. - blog-draft.yml: workflow_dispatch with PR numbers input. Collects PR diffs, generates Zenn blog draft via Kiro CLI headless, pushes to okamoto-aws/zenn-blog as sdpm/prXX-YY-ZZ-<slug> branch, creates PR to publish branch, labels source PRs as blog:done, notifies Slack. Required secrets: KIRO_API_KEY, BLOG_REPO_TOKEN, SLACK_WEBHOOK_URL
1 parent cfcc914 commit 5179ebb

2 files changed

Lines changed: 222 additions & 0 deletions

File tree

‎.github/workflows/blog-draft.yml‎

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
name: Blog draft
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr_numbers:
7+
description: 'PR numbers (comma-separated, e.g. 42,57,63)'
8+
required: true
9+
blog_theme:
10+
description: 'Blog theme/angle (optional)'
11+
required: false
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
jobs:
18+
draft:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v6
22+
23+
- name: Install Kiro CLI
24+
run: curl -fsSL https://cli.kiro.dev/install | bash
25+
26+
- name: Collect PR data
27+
id: collect
28+
env:
29+
GH_TOKEN: ${{ github.token }}
30+
PR_NUMBERS: ${{ inputs.pr_numbers }}
31+
run: |
32+
mkdir -p /tmp/pr-data
33+
BRANCH_PARTS=""
34+
for pr in $(echo "$PR_NUMBERS" | tr ',' ' '); do
35+
echo "--- Collecting PR #${pr} ---"
36+
gh pr view "$pr" --json title,body,number --jq '{title,body,number}' > "/tmp/pr-data/pr-${pr}-meta.json"
37+
gh pr diff "$pr" > "/tmp/pr-data/pr-${pr}.diff"
38+
BRANCH_PARTS="${BRANCH_PARTS}${pr}-"
39+
done
40+
# Generate branch name slug from first PR title
41+
FIRST_PR=$(echo "$PR_NUMBERS" | cut -d',' -f1)
42+
SLUG=$(gh pr view "$FIRST_PR" --json title --jq '.title' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | head -c 40)
43+
BRANCH_NAME="sdpm/pr${BRANCH_PARTS}${SLUG}"
44+
echo "branch_name=${BRANCH_NAME}" >> "$GITHUB_OUTPUT"
45+
echo "Branch: ${BRANCH_NAME}"
46+
47+
- name: Generate blog draft with Kiro CLI
48+
env:
49+
KIRO_API_KEY: ${{ secrets.KIRO_API_KEY }}
50+
PR_NUMBERS: ${{ inputs.pr_numbers }}
51+
BLOG_THEME: ${{ inputs.blog_theme }}
52+
run: |
53+
# Build prompt
54+
PR_DATA=""
55+
for pr in $(echo "$PR_NUMBERS" | tr ',' ' '); do
56+
META=$(cat "/tmp/pr-data/pr-${pr}-meta.json")
57+
DIFF=$(head -c 50000 "/tmp/pr-data/pr-${pr}.diff")
58+
PR_DATA="${PR_DATA}
59+
=== PR #${pr} ===
60+
${META}
61+
62+
Diff (truncated):
63+
${DIFF}
64+
"
65+
done
66+
67+
THEME_INSTRUCTION=""
68+
if [ -n "$BLOG_THEME" ]; then
69+
THEME_INSTRUCTION="テーマ/切り口: ${BLOG_THEME}"
70+
fi
71+
72+
PROMPT="あなたはAWS Solutions Architectのテックブロガーです。
73+
以下のPRの内容をもとに、Zenn (zenn.dev/aws_japan) 向けの日本語ブログ記事をドラフトしてください。
74+
75+
${THEME_INSTRUCTION}
76+
77+
要件:
78+
- Zennのfrontmatter (title, emoji, type, topics, published: false, publication_name: aws_japan) を含める
79+
- 技術的に正確で、具体的なユースケースを交えて説明する
80+
- コードブロックや設定例があれば含める
81+
- 「この記事は個人の見解であり、所属する組織の公式見解ではありません。」を冒頭に入れる
82+
- 画像が必要な箇所は <!-- TODO: [📸 画像プレースホルダ] 説明 --> で示す
83+
- ファイル名は slug 形式で出力の最初の行に記載: filename: sdpm-xxx.md
84+
85+
PR データ:
86+
${PR_DATA}
87+
88+
Markdown のみを出力してください。"
89+
90+
kiro-cli chat --no-interactive --trust-all-tools "$PROMPT" > /tmp/blog-draft-raw.txt 2>/dev/null
91+
92+
# Extract markdown content (lines starting with "> " are the response)
93+
grep '^> ' /tmp/blog-draft-raw.txt | sed 's/^> //' > /tmp/blog-draft.md
94+
# Continuation lines (no "> " prefix)
95+
# Use the full stdout as fallback if grep finds nothing
96+
if [ ! -s /tmp/blog-draft.md ]; then
97+
cp /tmp/blog-draft-raw.txt /tmp/blog-draft.md
98+
fi
99+
100+
# Extract filename from first line if present
101+
FILENAME=$(head -5 /tmp/blog-draft.md | grep -oP 'filename:\s*\K\S+' || echo "")
102+
if [ -z "$FILENAME" ]; then
103+
FILENAME="sdpm-draft-$(date +%Y%m%d).md"
104+
fi
105+
echo "$FILENAME" > /tmp/blog-filename.txt
106+
107+
# Remove the filename directive line from content
108+
sed -i '/^filename:/d' /tmp/blog-draft.md
109+
110+
echo "Generated: $FILENAME ($(wc -c < /tmp/blog-draft.md) bytes)"
111+
112+
- name: Push to zenn-blog and create PR
113+
env:
114+
BLOG_REPO_TOKEN: ${{ secrets.BLOG_REPO_TOKEN }}
115+
BRANCH_NAME: ${{ steps.collect.outputs.branch_name }}
116+
PR_NUMBERS: ${{ inputs.pr_numbers }}
117+
run: |
118+
FILENAME=$(cat /tmp/blog-filename.txt)
119+
REPO="okamoto-aws/zenn-blog"
120+
121+
# Clone zenn-blog
122+
git clone "https://x-access-token:${BLOG_REPO_TOKEN}@github.com/${REPO}.git" /tmp/zenn-blog
123+
cd /tmp/zenn-blog
124+
git checkout publish
125+
git checkout -b "$BRANCH_NAME"
126+
127+
# Copy draft
128+
cp /tmp/blog-draft.md "articles/${FILENAME}"
129+
git add "articles/${FILENAME}"
130+
git config user.name "github-actions[bot]"
131+
git config user.email "github-actions[bot]@users.noreply.github.com"
132+
133+
PR_LIST=$(echo "$PR_NUMBERS" | tr ',' ' ' | xargs -I{} echo "- https://github.com/${{ github.repository }}/pull/{}")
134+
git commit -m "📝 Blog draft: ${FILENAME}
135+
136+
Source PRs:
137+
${PR_LIST}"
138+
139+
git push origin "$BRANCH_NAME"
140+
141+
# Create PR
142+
PR_URL=$(gh pr create \
143+
--repo "$REPO" \
144+
--base publish \
145+
--head "$BRANCH_NAME" \
146+
--title "📝 Blog draft: ${FILENAME}" \
147+
--body "Auto-generated blog draft from SDPM CI.
148+
149+
**Source PRs:**
150+
${PR_LIST}
151+
152+
**Theme:** ${{ inputs.blog_theme }}
153+
154+
---
155+
Review, edit, and merge to publish on Zenn." \
156+
2>&1)
157+
158+
echo "$PR_URL" > /tmp/blog-pr-url.txt
159+
echo "PR created: $PR_URL"
160+
161+
- name: Label source PRs as blog:done
162+
env:
163+
GH_TOKEN: ${{ github.token }}
164+
PR_NUMBERS: ${{ inputs.pr_numbers }}
165+
run: |
166+
for pr in $(echo "$PR_NUMBERS" | tr ',' ' '); do
167+
gh pr edit "$pr" --remove-label "blog:pending" --add-label "blog:done" 2>/dev/null || true
168+
echo "Labeled PR #${pr} as blog:done"
169+
done
170+
171+
- name: Notify Slack
172+
if: always() && secrets.SLACK_WEBHOOK_URL != ''
173+
env:
174+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
175+
run: |
176+
PR_URL=$(cat /tmp/blog-pr-url.txt 2>/dev/null || echo "N/A")
177+
SUBJECT="📝 Blog draft ready: PR ${{ inputs.pr_numbers }}"
178+
curl -s -X POST "$SLACK_WEBHOOK_URL" \
179+
-H "Content-Type: application/json" \
180+
-d "{\"subject\":\"${SUBJECT}\",\"url\":\"${PR_URL}\"}"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Require blog label
2+
3+
on:
4+
pull_request:
5+
types: [labeled, unlabeled, opened, synchronize]
6+
7+
jobs:
8+
check:
9+
runs-on: ubuntu-latest
10+
# Skip for dependabot / renovate
11+
if: >-
12+
github.actor != 'dependabot[bot]' &&
13+
github.actor != 'renovate[bot]'
14+
steps:
15+
- name: Check blog label
16+
env:
17+
LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
18+
run: |
19+
if echo "$LABELS" | grep -qE '"blog:(pending|skip)"'; then
20+
echo "✅ Blog label found"
21+
else
22+
echo "::error::PR に blog:pending または blog:skip ラベルを付けてください"
23+
exit 1
24+
fi
25+
26+
auto-skip-bots:
27+
runs-on: ubuntu-latest
28+
if: >-
29+
github.actor == 'dependabot[bot]' ||
30+
github.actor == 'renovate[bot]'
31+
permissions:
32+
pull-requests: write
33+
steps:
34+
- uses: actions/github-script@v7
35+
with:
36+
script: |
37+
await github.rest.issues.addLabels({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
issue_number: context.payload.pull_request.number,
41+
labels: ['blog:skip']
42+
});

0 commit comments

Comments
 (0)