|
| 1 | +# Generate Documentation Workflow |
| 2 | + |
| 3 | +**Workflow File**: [`.github/workflows/generate-docs.yml`](../../.github/workflows/generate-docs.yml) |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Generate Documentation workflow leverages GitHub Copilot CLI to analyze code changes and automatically creates documentation when necessary. Instead of relying on developers to remember to update docs, this agentic workflow handles it autonomously. |
| 8 | + |
| 9 | + |
| 10 | +## How It Works |
| 11 | + |
| 12 | +```mermaid |
| 13 | +flowchart TD |
| 14 | + A[Push to Repository] --> B{Excluded files only?} |
| 15 | + B -->|Yes| C[Skip workflow] |
| 16 | + B -->|No| D[Install Copilot CLI] |
| 17 | + D --> E[Load analyze-commit prompt] |
| 18 | + E --> F[Copilot analyzes commit diff] |
| 19 | + F --> G{Documentation needed?} |
| 20 | + G -->|No| H[Exit - No action needed] |
| 21 | + G -->|Yes| I[Create GitHub Issue] |
| 22 | + I --> J[Assign Copilot Coding Agent] |
| 23 | + J --> K[Agent implements documentation] |
| 24 | + K --> L[PR created with docs] |
| 25 | +``` |
| 26 | + |
| 27 | +### Step-by-Step Process |
| 28 | + |
| 29 | +1. **Triggers on every push** (excluding docs and markdown files) |
| 30 | +2. **Installs Copilot CLI** in the GitHub Actions runner |
| 31 | +3. **Loads the analyze-for-docs prompt** from [`.github/prompts/analyze-for-docs.prompt.md`](../../.github/prompts/analyze-for-docs.prompt.md) |
| 32 | +4. **Copilot examines the commit diff** using MCP tools |
| 33 | +5. **If documentation is needed** → Creates a GitHub issue and assigns Copilot |
| 34 | +6. **Copilot Coding Agent** then implements the documentation |
| 35 | + |
| 36 | + |
| 37 | +## Criteria for Documentation |
| 38 | + |
| 39 | +### ✅ Documentation IS Needed |
| 40 | + |
| 41 | +| Change Type | Example | |
| 42 | +|-------------|---------| |
| 43 | +| Public APIs | New REST endpoints, GraphQL mutations | |
| 44 | +| Functions/Classes | Exported functions, public class methods | |
| 45 | +| Complex Logic | Algorithms, business rules, data transformations | |
| 46 | +| Architectural Changes | New services, modified data flow | |
| 47 | +| Breaking Changes | API contract changes, removed features | |
| 48 | + |
| 49 | +### ❌ Documentation NOT Needed |
| 50 | + |
| 51 | +| Change Type | Example | |
| 52 | +|-------------|---------| |
| 53 | +| Minor Refactoring | Variable renames, code reorganization | |
| 54 | +| Formatting | Whitespace, linting fixes | |
| 55 | +| Trivial Typo Fixes | Comment typos, string corrections | |
| 56 | +| Internal Implementation | Private methods, internal helpers | |
| 57 | + |
| 58 | + |
| 59 | +## Configuration |
| 60 | + |
| 61 | +### Trigger Configuration |
| 62 | + |
| 63 | +The workflow excludes certain paths to avoid unnecessary runs: |
| 64 | + |
| 65 | +```yaml |
| 66 | +on: |
| 67 | + push: |
| 68 | + paths-ignore: |
| 69 | + - 'docs/**' |
| 70 | + - '**/*.md' |
| 71 | + - '.github/workflows/**' |
| 72 | +``` |
| 73 | +
|
| 74 | +### Required Secrets |
| 75 | +
|
| 76 | +| Secret | Description | |
| 77 | +|--------|-------------| |
| 78 | +| `COPILOT_CLI_TOKEN` | Personal Access Token with Copilot permissions | |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Prompt File |
| 83 | + |
| 84 | +The workflow uses a specialized prompt to guide Copilot's analysis: |
| 85 | + |
| 86 | +**Location**: [`.github/prompts/analyze-for-docs.prompt.md`](../../.github/prompts/analyze-for-docs.prompt.md) |
| 87 | + |
| 88 | +This prompt instructs Copilot to: |
| 89 | +- Analyze the git diff of the latest commit |
| 90 | +- Evaluate changes against documentation criteria |
| 91 | +- Determine if public-facing code was added or modified |
| 92 | +- Create a well-structured issue if documentation is warranted |
| 93 | + |
| 94 | + |
| 95 | +## Example Issue Created |
| 96 | + |
| 97 | +When the workflow detects documentation is needed, it creates an issue like: |
| 98 | + |
| 99 | +```markdown |
| 100 | +## 📚 Documentation Needed |
| 101 | +
|
| 102 | +**Commit**: abc1234 |
| 103 | +**Author**: @developer |
| 104 | +
|
| 105 | +### Changes Requiring Documentation |
| 106 | +
|
| 107 | +- New `/api/warehouses` endpoint added |
| 108 | +- `Warehouse` model with 10 properties |
| 109 | +- CRUD operations for warehouse management |
| 110 | + |
| 111 | +### Suggested Documentation |
| 112 | + |
| 113 | +1. Update API documentation with new endpoints |
| 114 | +2. Add Warehouse model to data model docs |
| 115 | +3. Include usage examples |
| 116 | + |
| 117 | +/assign @copilot |
| 118 | +``` |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +## Troubleshooting |
| 123 | + |
| 124 | +### Workflow Not Triggering |
| 125 | + |
| 126 | +- Verify the push includes files outside the `paths-ignore` patterns |
| 127 | +- Check that the workflow file exists in the default branch |
| 128 | + |
| 129 | +### Copilot Not Creating Issues |
| 130 | + |
| 131 | +- Ensure `COPILOT_CLI_TOKEN` secret is configured |
| 132 | +- Verify the token has `Copilot Requests` permission |
| 133 | +- Check workflow logs for authentication errors |
| 134 | + |
| 135 | +### Agent Not Implementing Documentation |
| 136 | + |
| 137 | +- Confirm Copilot Coding Agent is enabled in repository settings |
| 138 | +- Verify the issue is properly assigned to `@copilot` |
0 commit comments