Skip to content

ci: add gemini-readme automation #1

ci: add gemini-readme automation

ci: add gemini-readme automation #1

Workflow file for this run

name: Gemini AI README Generator
on:
push:
branches: [ main ]
paths-ignore:
- 'README.md'
- '.github/workflows/**'
jobs:
analyze-and-generate:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install google-generativeai
- name: Run Gemini Analysis
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
python - << 'EOF'
import os
import google.generativeai as genai
# Configure Gemini
genai.configure(api_key=os.environ.get("GEMINI_API_KEY"))
model = genai.GenerativeModel('gemini-2.5-flash') # 'flash' is fast and cheap
# 1. Gather repository context
file_structure = []
important_content = ""
# Walk through files (ignoring common junk folders)
ignore_list = {'.git', 'node_modules', '__pycache__', '.venv', 'dist', 'build'}
for root, dirs, filenames in os.walk("."):
dirs[:] = [d for d in dirs if d not in ignore_list]
for f in filenames:
path = os.path.join(root, f)
file_structure.append(path)
# Read content of setup/manifest files for tech stack context
if f in ["package.json", "requirements.txt", "main.py", "index.js", "go.mod", "Dockerfile"]:
try:
with open(path, 'r') as file:
important_content += f"
--- Content of {f} ---
{file.read()[:1000]}
"
except:

Check failure on line 63 in .github/workflows/gemini-readme.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/gemini-readme.yml

Invalid workflow file

You have an error in your yaml syntax on line 63
pass
# 2. Build the Prompt
prompt = f""
I have a GitHub repository with the following structure:
{file_structure}
Here is some key file content:
{important_content}
Task: Generate a high-quality, professional README.md for this project.
Include:
- A catchy project title.
- A clear description of what this project does.
- The tech stack used (identify it from the files).
- Key features.
- Quick start/Installation instructions.
Output ONLY the markdown content.
""
# 3. Generate and Save
try:
response = model.generate_content(prompt)
with open("README.md", "w") as f:
f.write(response.text)
except Exception as e:
print(f"Error generating content: {e}")
exit(1)
EOF
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "docs: update README using Gemini AI [skip ci]"
file_pattern: 'README.md'