メインコンテンツへスキップ
このクックブックでは、GitHub ActionsでDroid Execを使用して、コードがmainにマージされた際に自動的にドキュメントを更新する方法を説明します。ワークフローはコードの変更を分析し、関連するドキュメントを発見して更新し、人間によるレビュー用のプルリクエストを作成します。

仕組み

エンドツーエンドの自動化ワークフロー:
  1. トリガー: mainブランチにコードがマージされる
  2. 探索: Droid execがコードベース構造(プロジェクトタイプ、技術スタック)を探索
  3. 分析: 変更されたファイルとその目的を特定
  4. 発見: docs/ディレクトリ内の関連ドキュメントを検索
  5. 更新: 影響を受けるドキュメントセクションを更新
  6. コミット: ワークフローがコミットを作成
  7. PR: Botがチームレビュー用のプルリクエストを開く

前提条件

開始するには、以下が必要です:
  • Droidのインストール
  • Factory APIキー
  • Actions が有効化されたGitHub リポジトリ
  • リポジトリシークレット内のFACTORY_API_KEY(Settings → Secrets → Actions)
  • 既存のドキュメントディレクトリ
See the Droid Exec setup here.

完全なGitHub Actions ワークフロー

This workflow will create pull requests automatically. Review the generated PRs carefully before merging to ensure accuracy.
.github/workflows/update-docs.ymlを作成:
name: Auto-Update Documentation

on:
  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"
主要なワークフロー機能:
  • ファイル変更のみに--auto lowを使用(クックブックパターンに従う)
  • 明示的な指示:「コミットやプッシュは行わない」(関心事の分離)
  • ワークフローが別ステップでgit操作を処理
  • Droid が自律的にコードベースを探索し、関連ドキュメントを発見(マッピングファイル不要)

ベストプラクティス

1

Scope triggers carefully

Only trigger on meaningful code changes:
paths:
  - 'src/**'
  - '!src/**/*.test.ts'
  - '!src/**/*.spec.ts'
2

Use --auto low for safety

Following cookbook patterns:
droid exec --auto low "..." # File changes only
# Workflow handles git operations separately
3

Trust autonomous discovery

Let droid explore and find relevant docs rather than maintaining manual mappings:
"Search the docs/ directory for files that reference the changed code"
4

Always generate summaries

Help reviewers understand changes:
"Create doc-update-summary.md explaining what was updated and why"
5

Consider rate limits

For high-frequency repos, use scheduled batch updates:
schedule:
  - cron: '0 9 * * 1'  # Weekly on Monday

バリエーション

週次包括レビュー

頻繁に変更があるリポジトリの場合、更新を週次レビューにバッチ処理:
on:
  schedule:
    - cron: '0 9 * * 1'  # Monday 9 AM
  workflow_dispatch:  # Allow manual trigger

複数のドキュメントディレクトリ

ドキュメントが複数の場所に分散している場合:
droid exec --auto low "
Search docs/, guides/, and README.md for documentation to update
based on these code changes: $(cat changed_files.txt)
"

言語固有のターゲティング

特定のファイルタイプに焦点を当てる:
on:
  push:
    branches: [main]
    paths:
      - 'src/**/*.ts'
      - 'src/**/*.tsx'
      # TypeScript changes only

トラブルシューティング

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.
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.
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.
For large repositories, consider:
  • Increasing the timeout in the workflow
  • Processing documentation updates in batches
  • Using scheduled updates instead of triggering on every merge

関連項目