Skip to content

Auto Generate Daily Blog #2

Auto Generate Daily Blog

Auto Generate Daily Blog #2

name: Auto Generate Daily Blog
on:
schedule:
# Runs every day at 9:00 AM UTC (adjust as needed)
- cron: "0 9 * * *"
workflow_dispatch: # Allows manual trigger
jobs:
generate-blog:
runs-on: ubuntu-latest
permissions:
contents: write
pages: write
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Use PAT if available, fallback to GITHUB_TOKEN
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r .blog-generator/requirements.txt
- name: Generate blog post
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
cd .blog-generator
python generate_blog.py
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit and push changes
id: commit
run: |
git add _posts/*.md
git add .blog-generator/topics_covered.json
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
echo "changes=false" >> $GITHUB_OUTPUT
else
git commit -m "🤖 Auto-generated blog post - $(date +'%Y-%m-%d')"
git push origin main
echo "changes=true" >> $GITHUB_OUTPUT
fi
- name: Wait for push to complete
if: steps.commit.outputs.changes == 'true'
run: sleep 10
- name: Trigger Pages Deploy Workflow
if: steps.commit.outputs.changes == 'true'
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/pages-deploy.yml/dispatches \
-d '{"ref":"main"}'