|
| 1 | + |
| 2 | +name: Gemini AI README Generator |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [ main ] |
| 7 | + paths-ignore: |
| 8 | + - 'README.md' |
| 9 | + - '.github/workflows/**' |
| 10 | + |
| 11 | +jobs: |
| 12 | + analyze-and-generate: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v4 |
| 23 | + with: |
| 24 | + python-version: '3.9' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: | |
| 28 | + pip install google-generativeai |
| 29 | +
|
| 30 | + - name: Run Gemini Analysis |
| 31 | + env: |
| 32 | + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} |
| 33 | + run: | |
| 34 | + python - << 'EOF' |
| 35 | + import os |
| 36 | + import google.generativeai as genai |
| 37 | +
|
| 38 | + # Configure Gemini |
| 39 | + genai.configure(api_key=os.environ.get("GEMINI_API_KEY")) |
| 40 | + model = genai.GenerativeModel('gemini-2.5-flash') # 'flash' is fast and cheap |
| 41 | +
|
| 42 | + # 1. Gather repository context |
| 43 | + file_structure = [] |
| 44 | + important_content = "" |
| 45 | + |
| 46 | + # Walk through files (ignoring common junk folders) |
| 47 | + ignore_list = {'.git', 'node_modules', '__pycache__', '.venv', 'dist', 'build'} |
| 48 | + |
| 49 | + for root, dirs, filenames in os.walk("."): |
| 50 | + dirs[:] = [d for d in dirs if d not in ignore_list] |
| 51 | + for f in filenames: |
| 52 | + path = os.path.join(root, f) |
| 53 | + file_structure.append(path) |
| 54 | + |
| 55 | + # Read content of setup/manifest files for tech stack context |
| 56 | + if f in ["package.json", "requirements.txt", "main.py", "index.js", "go.mod", "Dockerfile"]: |
| 57 | + try: |
| 58 | + with open(path, 'r') as file: |
| 59 | + important_content += f" |
| 60 | +--- Content of {f} --- |
| 61 | +{file.read()[:1000]} |
| 62 | +" |
| 63 | + except: |
| 64 | + pass |
| 65 | +
|
| 66 | + # 2. Build the Prompt |
| 67 | + prompt = f"" |
| 68 | + I have a GitHub repository with the following structure: |
| 69 | + {file_structure} |
| 70 | +
|
| 71 | + Here is some key file content: |
| 72 | + {important_content} |
| 73 | +
|
| 74 | + Task: Generate a high-quality, professional README.md for this project. |
| 75 | + Include: |
| 76 | + - A catchy project title. |
| 77 | + - A clear description of what this project does. |
| 78 | + - The tech stack used (identify it from the files). |
| 79 | + - Key features. |
| 80 | + - Quick start/Installation instructions. |
| 81 | + |
| 82 | + Output ONLY the markdown content. |
| 83 | + "" |
| 84 | +
|
| 85 | + # 3. Generate and Save |
| 86 | + try: |
| 87 | + response = model.generate_content(prompt) |
| 88 | + with open("README.md", "w") as f: |
| 89 | + f.write(response.text) |
| 90 | + except Exception as e: |
| 91 | + print(f"Error generating content: {e}") |
| 92 | + exit(1) |
| 93 | + EOF |
| 94 | + |
| 95 | + - name: Commit and push changes |
| 96 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 97 | + with: |
| 98 | + commit_message: "docs: update README using Gemini AI [skip ci]" |
| 99 | + file_pattern: 'README.md' |
0 commit comments