Skip to content

add style guide

add style guide #48

name: Auto-generate Blog Post for New Radius Release
on:
push:
branches:
- 'recontributing'
jobs:
generate-blog-post:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get release information
id: release-info
run: |
# Determine which release to use
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
# Automatic trigger from release webhook
TAG_NAME="${{ github.event.client_payload.tag_name }}"
echo "Using release from webhook: $TAG_NAME"
elif [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.tag_name }}" ]; then
# Manual trigger with specific tag
TAG_NAME="${{ github.event.inputs.tag_name }}"
echo "Using manually specified tag: $TAG_NAME"
else
# Manual trigger without tag - get latest release
echo "Getting latest release..."
TAG_NAME=$(curl -s "https://api.github.com/repos/radius-project/radius/releases/latest" | jq -r '.tag_name')
echo "Using latest release: $TAG_NAME"
fi
if [ -z "$TAG_NAME" ] || [ "$TAG_NAME" = "null" ]; then
echo "Could not determine tag name"
exit 1
fi
RELEASE_DATA=$(curl -s "https://api.github.com/repos/radius-project/radius/releases/tags/$TAG_NAME")
if [ "$(echo "$RELEASE_DATA" | jq -r '.message // empty')" = "Not Found" ]; then
echo "Release not found for tag: $TAG_NAME"
exit 1
fi
RELEASE_NAME=$(echo "$RELEASE_DATA" | jq -r '.name')
RELEASE_BODY=$(echo "$RELEASE_DATA" | jq -r '.body')
PUBLISHED_AT=$(echo "$RELEASE_DATA" | jq -r '.published_at')
HTML_URL=$(echo "$RELEASE_DATA" | jq -r '.html_url')
BLOG_DATE=$(date -d "$PUBLISHED_AT" "+%Y-%m-%dT%H:%M:%S%z" 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$PUBLISHED_AT" "+%Y-%m-%dT%H:%M:%S%z")
YEAR=$(date -d "$PUBLISHED_AT" "+%Y" 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$PUBLISHED_AT" "+%Y")
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "release_name=$RELEASE_NAME" >> $GITHUB_OUTPUT
echo "blog_date=$BLOG_DATE" >> $GITHUB_OUTPUT
echo "year=$YEAR" >> $GITHUB_OUTPUT
echo "html_url=$HTML_URL" >> $GITHUB_OUTPUT
echo "$RELEASE_BODY" > release_body.md
- name: Generate AI blog content
id: ai-content
run: |
# Get context from previous blog posts
CONTEXT=""
if ls radblog/content/posts/2025/*/index.md 1> /dev/null 2>&1; then
for file in $(ls radblog/content/posts/2025/*/index.md | head -2); do
if [ -f "$file" ]; then
# Extract content after frontmatter
CONTENT=$(sed -n '/^---$/,/^---$/!p' "$file" | head -20 | tr '\n' ' ')
CONTEXT="$CONTEXT $CONTENT"
fi
done
fi
# Get contribution guide content from re/ab branch
echo "Fetching contribution guide from re/ab branch..."
HTTP_STATUS=$(curl -s -w "%{http_code}" "https://raw.githubusercontent.com/radius-project/blog/re%2Fab/radblog/guide/contribution-guide.md" -o contribution-guide.md)
if [ "$HTTP_STATUS" = "200" ] && [ -f "contribution-guide.md" ] && [ -s "contribution-guide.md" ]; then
STYLE_GUIDE=$(cat contribution-guide.md)
echo "✅ Contribution guide fetched successfully (HTTP $HTTP_STATUS)"
else
echo "❌ Failed to fetch contribution guide (HTTP $HTTP_STATUS), trying alternative method..."
# Try using git show as fallback
if git show re/ab:radblog/guide/contribution-guide.md > contribution-guide.md 2>/dev/null; then
STYLE_GUIDE=$(cat contribution-guide.md)
echo "✅ Contribution guide fetched via git show"
else
echo "❌ All methods failed, using fallback style guide"
STYLE_GUIDE="Follow Radius blog style guide: conversational, user-focused, technical depth over marketing, evidence-based content only."
fi
fi
# Create AI prompt from template using safer approach
cp scripts/blog-prompt.md prompt_template.md
# Replace placeholders safely
sed -i "s/{RELEASE_NAME}/${{ steps.release-info.outputs.release_name }}/g" prompt_template.md
# Replace placeholders with actual content
awk '
BEGIN { RS = "\n"; ORS = "\n" }
/{RELEASE_NOTES}/ {
while ((getline line < "release_body.md") > 0) {
print line
}
close("release_body.md")
next
}
/{STYLE_GUIDE}/ {
print "'"$STYLE_GUIDE"'"
next
}
/{BLOG_CONTEXT}/ {
print "'"$CONTEXT"'"
next
}
{ print }
' prompt_template.md > final_prompt.md
PROMPT=$(cat final_prompt.md)
# Debug: Show the prompt being sent
echo "=== PROMPT BEING SENT TO AI ==="
cat final_prompt.md
echo "=== END OF PROMPT ==="
# Call GitHub Models API
RESPONSE=$(curl -s -X POST "https://models.inference.ai.azure.com/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a technical content writer for cloud-native application platforms."},
{"role": "user", "content": "'"$(echo "$PROMPT" | sed 's/"/\\"/g' | tr '\n' ' ')"'"}
],
"max_tokens": 3500,
"temperature": 0.3
}')
# Check if API call was successful
if echo "$RESPONSE" | jq -e '.choices[0].message.content' > /dev/null 2>&1; then
echo "$RESPONSE" | jq -r '.choices[0].message.content' > ai_content.md
echo "ai_success=true" >> $GITHUB_OUTPUT
echo "✅ AI content generated successfully"
echo "=== AI GENERATED CONTENT ==="
cat ai_content.md
echo "=== END AI CONTENT ==="
else
echo "❌ AI generation failed, will use fallback template"
echo "API Response: $RESPONSE"
echo "ai_success=false" >> $GITHUB_OUTPUT
fi
- name: Create blog post
run: |
BLOG_DIR="radblog/content/posts/${{ steps.release-info.outputs.year }}/radius-${{ steps.release-info.outputs.tag_name }}-release"
mkdir -p "$BLOG_DIR"
# Create frontmatter
cat > "$BLOG_DIR/index.md" << EOF
---
date: "${{ steps.release-info.outputs.blog_date }}"
title: " Announcing ${{ steps.release-info.outputs.release_name }}"
linkTitle: "${{ steps.release-info.outputs.release_name }}"
author: "Radius Team"
type: blog
---
EOF
# Add content
if [ "${{ steps.ai-content.outputs.ai_success }}" = "true" ] && [ -f "ai_content.md" ]; then
echo "Using AI-generated content"
cat ai_content.md >> "$BLOG_DIR/index.md"
else
echo "Using fallback template"
cat >> "$BLOG_DIR/index.md" << EOF
We're excited to announce the release of ${{ steps.release-info.outputs.release_name }}! 🎉
## Release Highlights
EOF
sed 's/^## /### /g; s/^# /## /g' release_body.md >> "$BLOG_DIR/index.md"
fi
# No additional footer needed - AI should include "Learn More" section
echo "Blog post created at: $BLOG_DIR/index.md"
# Clean up intermediate files
rm -f ai_content.md final_prompt.md prompt_template.md release_body.md
# Show the generated content in logs
echo "=== GENERATED BLOG POST CONTENT ==="
cat "$BLOG_DIR/index.md"
echo "=== END OF BLOG POST ==="
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GH_RAD_CI_BOT_PAT }}
commit-message: "Add blog post for ${{ steps.release-info.outputs.release_name }}"
signoff: true
title: "Add blog post for ${{ steps.release-info.outputs.release_name }}"
body: |
Auto-generated blog post for **${{ steps.release-info.outputs.release_name }}**
- **Tag:** ${{ steps.release-info.outputs.tag_name }}
- **Release:** ${{ steps.release-info.outputs.html_url }}
- **AI Generated:** ${{ steps.ai-content.outputs.ai_success == 'true' && '✅ Yes' || '❌ No (fallback used)' }}
🤖 Generated automatically by GitHub Actions
branch: "blog-post-${{ steps.release-info.outputs.tag_name }}"
base: main
delete-branch: true