Automatically update documentation when code changes using CI/CD workflows
This cookbook demonstrates how to use Droid Exec in GitHub Actions to automatically update documentation when code is merged to main. The workflow analyzes code changes, discovers relevant documentation, updates it, and creates a pull request for human review.
This workflow will create pull requests automatically. Review the generated PRs carefully before merging to ensure accuracy.
Create .github/workflows/update-docs.yml:
Copy
Ask AI
name: Auto-Update Documentationon: push: branches: [main] paths: - 'src/**/*.ts' - 'src/**/*.tsx' - 'src/**/*.js' - 'src/**/*.py'jobs: update-docs: runs-on: ubuntu-latest permissions: contents: write pull-requests: write steps: - uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - name: Setup droid CLI run: | curl -fsSL https://app.factory.ai/cli | sh echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Get changed files id: changes run: | git diff --name-only HEAD^ HEAD > changed_files.txt echo "Files changed in last commit:" cat changed_files.txt - name: Update documentation env: FACTORY_API_KEY: ${{ secrets.FACTORY_API_KEY }} run: | droid exec --auto low " The following source files were just merged to main: $(cat changed_files.txt) Your task is to update the documentation to match these code changes. First, explore the codebase to understand context: 1. Examine package.json, README, and main entry points 2. Identify key directories and their purposes 3. Note the tech stack (languages, frameworks, tools) 4. Classify the project type: - **Library/SDK**: Exports functions/classes, has API docs, used as dependency - **Application**: Has routes/pages, domain models, user features - **Framework/Protocol**: Defines specs, client/server implementations - **Monorepo**: Multiple packages/apps in one repository Then, understand what changed: 1. Read each changed file carefully 2. Identify if changes are: API updates, new features, bug fixes, refactors 3. Note breaking changes or new configuration options Next, find and update relevant documentation: 1. Search the docs/ directory for files that reference: - The changed filenames or paths - Functions, classes, or APIs that were modified - Features or concepts affected by the changes 2. Update the found documentation: - Update function signatures if they changed - Update code examples to match new APIs - Update configuration docs if options changed - Update explanations if behavior changed - Add notes about breaking changes if needed 3. Preserve the existing doc structure and writing style 4. Only modify sections that are actually affected DO NOT commit or push changes. Finally, create doc-update-summary.md with: - List of documentation files that were updated - Summary of changes made to each file - Any sections that may need human review or clarification " - name: Commit documentation updates run: | if [ -n "$(git status --porcelain)" ]; then git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add -A git commit -m "docs: automated documentation updates" else echo "No documentation changes needed" exit 0 fi - name: Create Pull Request env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | BRANCH="docs/auto-update-$(date +%Y%m%d-%H%M%S)" git checkout -b $BRANCH git push origin $BRANCH # Get summary or use default message SUMMARY=$(cat doc-update-summary.md 2>/dev/null || echo "Documentation updated to reflect recent code changes.") gh pr create \ --title "📚 Automated documentation updates" \ --body "## Automated Documentation Updates$SUMMARY### Review Checklist- [ ] Documentation accurately reflects code changes- [ ] Code examples are correct and runnable- [ ] No unintended changes to other sections- [ ] Formatting and style are consistent---This PR was automatically generated after code was merged to main." \ --label "documentation,automated"
Key workflow features:
Uses --auto low for file modifications only (following cookbook patterns)
Explicit instruction: “DO NOT commit or push” (separation of concerns)
Workflow handles git operations in separate step
Droid autonomously explores codebase and discovers relevant docs (no mapping file needed)
Droid may have determined no docs needed updates. Check the workflow logs or add more specific search instructions in the prompt. You can also check if doc-update-summary.md was created to see what droid analyzed.
Wrong sections get updated
Improve the exploration prompt to be more specific about what to look for. Consider adding explicit instructions about which doc sections should or shouldn’t be modified.
Droid can't find relevant docs
Make the search instructions more explicit by pointing Droid Exec at specific directories, filenames, or keywords. Providing a short list of likely docs can dramatically improve accuracy.
Workflow times out
For large repositories, consider:
Increasing the timeout in the workflow
Processing documentation updates in batches
Using scheduled updates instead of triggering on every merge