|
| 1 | +# ====================================================================================== |
| 2 | +# Workflow: Update Docs on Merge |
| 3 | +# ====================================================================================== |
| 4 | +# Usage: |
| 5 | +# - This workflow triggers automatically when a PR is merged to main. |
| 6 | +# - The Warp Agent analyzes the merged changes and determines if documentation |
| 7 | +# updates are needed. |
| 8 | +# |
| 9 | +# Setup: |
| 10 | +# - Ensure WARP_API_KEY is set in Repository Secrets. |
| 11 | +# - Ensure the Action has write permissions for contents and pull-requests. |
| 12 | +# |
| 13 | +# Expected Output: |
| 14 | +# - If docs updates are needed: A new Pull Request (docs/update-from-pr-NUMBER) is created. |
| 15 | +# - If no updates are needed: The workflow completes without creating a PR. |
| 16 | +# |
| 17 | +# When to use: |
| 18 | +# - Use this to automatically keep documentation in sync with code changes. |
| 19 | +# ====================================================================================== |
| 20 | +name: Update Docs on Merge |
| 21 | + |
| 22 | +on: |
| 23 | + pull_request: |
| 24 | + types: [closed] |
| 25 | + branches: [main] |
| 26 | + |
| 27 | +jobs: |
| 28 | + update_docs: |
| 29 | + # Only run if the PR was merged (not just closed) |
| 30 | + if: github.event.pull_request.merged == true |
| 31 | + name: Check and Update Documentation |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: write |
| 35 | + pull-requests: write |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout Repo |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + fetch-depth: 0 |
| 42 | + |
| 43 | + - name: Get PR Diff |
| 44 | + id: diff |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ github.token }} |
| 47 | + run: | |
| 48 | + # Get the diff from the merged PR |
| 49 | + gh pr diff ${{ github.event.pull_request.number }} > pr_diff.txt |
| 50 | + echo "Diff saved to pr_diff.txt" |
| 51 | +
|
| 52 | + - name: Construct Prompt |
| 53 | + id: prompt |
| 54 | + uses: actions/github-script@v7 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + const fs = require('fs'); |
| 58 | + const pr = context.payload.pull_request; |
| 59 | +
|
| 60 | + const description = pr.body || 'No description provided.'; |
| 61 | + const diffContent = fs.readFileSync('pr_diff.txt', 'utf8'); |
| 62 | +
|
| 63 | + const prompt = `You are an expert technical writer and the Warp Agent. |
| 64 | + You have been assigned to review a merged PR and determine if documentation updates are needed. |
| 65 | +
|
| 66 | + **Merged PR Details**: |
| 67 | + - **PR Number**: #${pr.number} |
| 68 | + - **Title**: ${pr.title} |
| 69 | + - **Description**: ${description} |
| 70 | +
|
| 71 | + **PR Diff**: |
| 72 | + The full diff of the merged changes is available in \`pr_diff.txt\` in the workspace. |
| 73 | +
|
| 74 | + **Documentation Locations**: |
| 75 | + - \`docs/\` - Contains technical documentation (spec, implementation details, LSP docs) |
| 76 | + - \`site/src/\` - Contains the documentation website source files |
| 77 | + - \`README.md\` - Main project README |
| 78 | +
|
| 79 | + **Instructions**: |
| 80 | + 1. **Analyze the Diff**: |
| 81 | + - Read \`pr_diff.txt\` to understand what code changes were made. |
| 82 | + - Focus on changes that affect user-facing behavior, APIs, configuration options, |
| 83 | + new features, or significant bug fixes. |
| 84 | +
|
| 85 | + 2. **Review Existing Documentation**: |
| 86 | + - Check the relevant documentation files to see what is currently documented. |
| 87 | + - Look at \`docs/\` for technical specs and \`site/src/\` for the documentation website. |
| 88 | +
|
| 89 | + 3. **Determine if Updates are Needed**: |
| 90 | + - Documentation updates ARE needed if the PR introduces: |
| 91 | + - New features or commands |
| 92 | + - Changes to existing behavior or APIs |
| 93 | + - New configuration options |
| 94 | + - Breaking changes |
| 95 | + - Significant bug fixes that users should know about |
| 96 | + - Documentation updates are NOT needed for: |
| 97 | + - Internal refactoring with no user-facing changes |
| 98 | + - Test-only changes |
| 99 | + - CI/build infrastructure changes |
| 100 | + - Code style or formatting changes |
| 101 | +
|
| 102 | + 4. **If Updates are Needed**: |
| 103 | + - Make the necessary documentation changes to the appropriate files. |
| 104 | + - Keep the documentation style consistent with existing docs. |
| 105 | + - Be concise and clear. |
| 106 | +
|
| 107 | + 5. **Output**: |
| 108 | + - If you made documentation changes, provide a brief summary of what you updated. |
| 109 | + - If no documentation changes are needed, explain why (e.g., "No user-facing changes"). |
| 110 | + `; |
| 111 | + core.setOutput('prompt', prompt); |
| 112 | +
|
| 113 | + - name: Run Warp Agent |
| 114 | + uses: warpdotdev/warp-agent-action@v1 |
| 115 | + env: |
| 116 | + GH_TOKEN: ${{ github.token }} |
| 117 | + id: agent |
| 118 | + with: |
| 119 | + prompt: ${{ steps.prompt.outputs.prompt }} |
| 120 | + warp_api_key: ${{ secrets.WARP_API_KEY }} |
| 121 | + profile: ${{ vars.WARP_AGENT_PROFILE || '' }} |
| 122 | + |
| 123 | + - name: Create PR if Changes Made |
| 124 | + env: |
| 125 | + GH_TOKEN: ${{ github.token }} |
| 126 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 127 | + AGENT_OUTPUT: ${{ steps.agent.outputs.agent_output }} |
| 128 | + run: | |
| 129 | + # Remove temporary files that should not be committed |
| 130 | + rm -f pr_diff.txt |
| 131 | +
|
| 132 | + # Check for changes |
| 133 | + if [[ -z $(git status --porcelain) ]]; then |
| 134 | + echo "No documentation changes needed." |
| 135 | + exit 0 |
| 136 | + fi |
| 137 | +
|
| 138 | + BRANCH_NAME="docs/update-from-pr-$PR_NUMBER" |
| 139 | +
|
| 140 | + git config user.name "Warp Agent" |
| 141 | + git config user.email "agent@warp.dev" |
| 142 | +
|
| 143 | + git checkout -b "$BRANCH_NAME" |
| 144 | + git add . |
| 145 | + git commit -m "docs: update documentation for PR #$PR_NUMBER |
| 146 | +
|
| 147 | + Co-Authored-By: Warp <agent@warp.dev>" |
| 148 | + git push origin "$BRANCH_NAME" --force |
| 149 | +
|
| 150 | + # Create PR |
| 151 | + TITLE="docs: Update documentation for PR #$PR_NUMBER" |
| 152 | + BODY="This PR updates documentation based on changes from #$PR_NUMBER. |
| 153 | +
|
| 154 | + **Agent Summary**: |
| 155 | + $AGENT_OUTPUT |
| 156 | +
|
| 157 | + --- |
| 158 | + *This PR was automatically generated by the Warp Agent.* |
| 159 | +
|
| 160 | + Co-Authored-By: Warp <agent@warp.dev>" |
| 161 | +
|
| 162 | + # Create PR and capture URL |
| 163 | + PR_URL=$(gh pr create --title "$TITLE" --body "$BODY" --base main --head "$BRANCH_NAME") |
| 164 | +
|
| 165 | + echo "Created documentation PR: $PR_URL" |
0 commit comments