|
| 1 | +# Automatically updates the CLI Commands Guide when CLI commands or options |
| 2 | +# change between releases. |
| 3 | +# |
| 4 | +# Triggers: Manual (for testing) or on release (production) |
| 5 | +# Testing: Use dry_run mode to review outputs without creating PRs |
| 6 | +# See: documentation/automation/cli-command-tracking/TESTING.md |
| 7 | + |
| 8 | +name: Update CLI Documentation |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_dispatch: # Manual trigger for testing |
| 12 | + inputs: |
| 13 | + old_version: |
| 14 | + description: 'Previous version (e.g., v1.14.0). Leave empty to auto-detect.' |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + new_version: |
| 18 | + description: 'New version (e.g., v1.15.0). Leave empty to use HEAD.' |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + dry_run: |
| 22 | + description: 'Dry run mode - generate files but do not create PR' |
| 23 | + required: false |
| 24 | + type: boolean |
| 25 | + default: true |
| 26 | + |
| 27 | + # Automatic triggering on releases |
| 28 | + # Uses edited to catch when release-action updates the release with artifacts |
| 29 | + release: |
| 30 | + types: [edited] |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: write # Create branches and commit files |
| 34 | + pull-requests: write # Create PRs |
| 35 | + |
| 36 | +jobs: |
| 37 | + update-docs: |
| 38 | + name: Update CLI Documentation |
| 39 | + runs-on: ubuntu-latest |
| 40 | + |
| 41 | + env: |
| 42 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Checkout repository |
| 46 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 47 | + with: |
| 48 | + fetch-depth: 0 # Fetch all history for version comparison |
| 49 | + fetch-tags: true # Fetch all tags so we can checkout version tags |
| 50 | + |
| 51 | + - name: Fetch upstream tags (for forks) |
| 52 | + if: github.repository != 'block/goose' |
| 53 | + run: | |
| 54 | + # Add upstream remote and fetch tags (only needed when testing in forks) |
| 55 | + git remote add upstream https://github.com/block/goose.git || git remote set-url upstream https://github.com/block/goose.git |
| 56 | + git fetch upstream --tags --force |
| 57 | + echo "✅ Fetched tags from upstream (fork mode)" |
| 58 | + echo "Total tags available: $(git tag | wc -l)" |
| 59 | + |
| 60 | + - name: Install system dependencies |
| 61 | + run: | |
| 62 | + sudo apt-get update |
| 63 | + sudo apt-get install -y jq ripgrep |
| 64 | + |
| 65 | + - name: Set up Rust |
| 66 | + uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1 |
| 67 | + with: |
| 68 | + toolchain: stable |
| 69 | + |
| 70 | + - name: Set up Python |
| 71 | + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 |
| 72 | + with: |
| 73 | + python-version: '3.11' |
| 74 | + |
| 75 | + - name: Set up Node.js |
| 76 | + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 |
| 77 | + with: |
| 78 | + node-version: '20' |
| 79 | + |
| 80 | + - name: Install goose CLI |
| 81 | + run: | |
| 82 | + mkdir -p /home/runner/.local/bin |
| 83 | + curl -fsSL https://github.com/block/goose/releases/download/stable/download_cli.sh \ |
| 84 | + | CONFIGURE=false GOOSE_BIN_DIR=/home/runner/.local/bin bash |
| 85 | + echo "/home/runner/.local/bin" >> $GITHUB_PATH |
| 86 | + goose --version |
| 87 | + |
| 88 | + - name: Configure goose for CI |
| 89 | + env: |
| 90 | + GOOSE_PROVIDER: ${{ vars.GOOSE_PROVIDER || 'anthropic' }} |
| 91 | + GOOSE_MODEL: ${{ vars.GOOSE_MODEL || 'claude-opus-4-5' }} |
| 92 | + run: | |
| 93 | + mkdir -p ~/.config/goose |
| 94 | + cat <<EOF > ~/.config/goose/config.yaml |
| 95 | + GOOSE_PROVIDER: $GOOSE_PROVIDER |
| 96 | + GOOSE_MODEL: $GOOSE_MODEL |
| 97 | + keyring: false |
| 98 | + EOF |
| 99 | +
|
| 100 | + # Also export into the job environment so later steps can log the values |
| 101 | + echo "GOOSE_PROVIDER=$GOOSE_PROVIDER" >> "$GITHUB_ENV" |
| 102 | + echo "GOOSE_MODEL=$GOOSE_MODEL" >> "$GITHUB_ENV" |
| 103 | +
|
| 104 | + echo "✅ Created goose config:" |
| 105 | + cat ~/.config/goose/config.yaml |
| 106 | + |
| 107 | + - name: Determine versions to compare |
| 108 | + id: versions |
| 109 | + env: |
| 110 | + GH_TOKEN: ${{ github.token }} |
| 111 | + INPUT_OLD_VERSION: ${{ github.event.inputs.old_version }} |
| 112 | + INPUT_NEW_VERSION: ${{ github.event.inputs.new_version }} |
| 113 | + EVENT_NAME: ${{ github.event_name }} |
| 114 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 115 | + run: | |
| 116 | + get_previous_release() { |
| 117 | + gh release list --limit 2 --json tagName --jq '.[].tagName' | sed -n '2p' |
| 118 | + } |
| 119 | + |
| 120 | + if [ -n "$INPUT_OLD_VERSION" ]; then |
| 121 | + OLD_VERSION="$INPUT_OLD_VERSION" |
| 122 | + else |
| 123 | + OLD_VERSION=$(get_previous_release) |
| 124 | + fi |
| 125 | + |
| 126 | + if [ -n "$INPUT_NEW_VERSION" ]; then |
| 127 | + NEW_VERSION="$INPUT_NEW_VERSION" |
| 128 | + elif [ "$EVENT_NAME" = "release" ]; then |
| 129 | + NEW_VERSION="$RELEASE_TAG" |
| 130 | + else |
| 131 | + NEW_VERSION="HEAD" # For testing unreleased changes |
| 132 | + fi |
| 133 | + |
| 134 | + if [ -z "$OLD_VERSION" ] || [ -z "$NEW_VERSION" ]; then |
| 135 | + echo "Error: Could not determine versions to compare" |
| 136 | + exit 1 |
| 137 | + fi |
| 138 | + |
| 139 | + echo "old_version=$OLD_VERSION" >> $GITHUB_OUTPUT |
| 140 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 141 | + echo "OLD_VERSION=$OLD_VERSION" >> $GITHUB_ENV |
| 142 | + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV |
| 143 | + |
| 144 | + echo "✅ Comparing $OLD_VERSION → $NEW_VERSION" |
| 145 | + |
| 146 | + - name: Extract and compare CLI structures |
| 147 | + id: extract |
| 148 | + timeout-minutes: 30 # Building goose takes time |
| 149 | + working-directory: documentation/automation/cli-command-tracking |
| 150 | + env: |
| 151 | + GOOSE_REPO: ${{ github.workspace }} |
| 152 | + run: | |
| 153 | + set -o pipefail # Ensure pipeline failures are caught |
| 154 | + |
| 155 | + mkdir -p output |
| 156 | + ./scripts/run-pipeline.sh "$OLD_VERSION" "$NEW_VERSION" 2>&1 | tee output/pipeline.log |
| 157 | + |
| 158 | + HAS_CHANGES=$(jq -r '.has_changes' output/cli-changes.json) |
| 159 | + echo "has_changes=$HAS_CHANGES" >> $GITHUB_OUTPUT |
| 160 | + |
| 161 | + if [ "$HAS_CHANGES" = "false" ]; then |
| 162 | + echo "✅ No changes detected" |
| 163 | + else |
| 164 | + echo "✅ Changes detected" |
| 165 | + fi |
| 166 | + |
| 167 | + - name: Update goose-cli-commands.md (AI synthesis) |
| 168 | + if: steps.extract.outputs.has_changes == 'true' |
| 169 | + timeout-minutes: 10 |
| 170 | + working-directory: documentation/automation/cli-command-tracking/output |
| 171 | + env: |
| 172 | + CLI_COMMANDS_PATH: ${{ github.workspace }}/documentation/docs/guides/goose-cli-commands.md |
| 173 | + run: | |
| 174 | + echo "🔍 Environment diagnostics:" |
| 175 | + echo " GOOSE_PROVIDER: $GOOSE_PROVIDER" |
| 176 | + echo " GOOSE_MODEL: $GOOSE_MODEL" |
| 177 | + echo " ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:0:8}..." # Show first 8 chars only |
| 178 | + echo " CLI_COMMANDS_PATH: $CLI_COMMANDS_PATH" |
| 179 | + echo " HOME: $HOME" |
| 180 | + echo " PATH: $PATH" |
| 181 | + echo "" |
| 182 | + echo "📁 Goose config file:" |
| 183 | + cat ~/.config/goose/config.yaml || echo "Config file not found!" |
| 184 | + echo "" |
| 185 | + echo "📁 Current directory:" |
| 186 | + pwd |
| 187 | + ls -la |
| 188 | + echo "" |
| 189 | + echo "🤖 Applying changes to goose-cli-commands.md..." |
| 190 | + goose run --recipe ../recipes/update-cli-commands.yaml |
| 191 | + |
| 192 | + - name: Upload automation outputs |
| 193 | + if: always() |
| 194 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 195 | + with: |
| 196 | + name: cli-docs-update-${{ steps.versions.outputs.old_version }}-to-${{ steps.versions.outputs.new_version }} |
| 197 | + path: | |
| 198 | + documentation/automation/cli-command-tracking/output/*.json |
| 199 | + documentation/automation/cli-command-tracking/output/*.md |
| 200 | + documentation/automation/cli-command-tracking/output/*.log |
| 201 | + retention-days: 30 |
| 202 | + |
| 203 | + - name: Create Pull Request |
| 204 | + if: | |
| 205 | + steps.extract.outputs.has_changes == 'true' && |
| 206 | + (github.event.inputs.dry_run != 'true' || github.event_name == 'release') |
| 207 | + uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0 |
| 208 | + with: |
| 209 | + branch: docs/auto-cli-commands-${{ steps.versions.outputs.new_version }} |
| 210 | + delete-branch: true |
| 211 | + |
| 212 | + commit-message: | |
| 213 | + docs: Update CLI commands for ${{ steps.versions.outputs.new_version }} |
| 214 | + |
| 215 | + Automated update based on CLI changes between ${{ steps.versions.outputs.old_version }} and ${{ steps.versions.outputs.new_version }}. |
| 216 | + |
| 217 | + title: "docs: Update CLI Commands Guide for ${{ steps.versions.outputs.new_version }}" |
| 218 | + body: | |
| 219 | + ## Summary |
| 220 | +
|
| 221 | + This PR updates the CLI Commands Guide based on command and option changes detected between **${{ steps.versions.outputs.old_version }}** and **${{ steps.versions.outputs.new_version }}**. |
| 222 | +
|
| 223 | + ### Type of Change |
| 224 | + - [x] Documentation |
| 225 | +
|
| 226 | + ### AI Assistance |
| 227 | + - [x] This PR was created or reviewed with AI assistance |
| 228 | +
|
| 229 | + #### 🤖 Automation Details |
| 230 | + |
| 231 | + - **Workflow**: docs-update-cli-ref.yml |
| 232 | + - **Triggered by**: ${{ github.event_name }} |
| 233 | + - **Previous version**: ${{ steps.versions.outputs.old_version }} |
| 234 | + - **New version**: ${{ steps.versions.outputs.new_version }} |
| 235 | + |
| 236 | + #### 📋 Changes Detected |
| 237 | + |
| 238 | + Review the workflow artifacts for detailed change analysis: |
| 239 | + - cli-changes.json - Structured diff of changes |
| 240 | + - cli-changes.md - Human-readable change documentation |
| 241 | + - update-summary.md - Summary of documentation updates applied |
| 242 | + |
| 243 | + Download artifacts from the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). |
| 244 | + |
| 245 | + ### ✅ Review Checklist |
| 246 | + |
| 247 | + - [ ] Verify all CLI changes are accurately documented |
| 248 | + - [ ] Check that examples are updated correctly |
| 249 | + - [ ] Ensure new commands are in the correct sections |
| 250 | + - [ ] Confirm no unintended changes were made |
| 251 | + |
| 252 | + ### 🔗 Related |
| 253 | + |
| 254 | + - Release: ${{ github.event.release.html_url || 'N/A' }} |
| 255 | + |
| 256 | + --- |
| 257 | + |
| 258 | + *This PR was automatically generated by the CLI Documentation Automation workflow.* |
| 259 | + |
| 260 | + labels: | |
| 261 | + documentation |
| 262 | + automated |
| 263 | + cli-commands |
| 264 | + |
| 265 | + - name: Workflow summary |
| 266 | + if: always() |
| 267 | + env: |
| 268 | + OLD_VERSION: ${{ steps.versions.outputs.old_version }} |
| 269 | + NEW_VERSION: ${{ steps.versions.outputs.new_version }} |
| 270 | + HAS_CHANGES: ${{ steps.extract.outputs.has_changes }} |
| 271 | + DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }} |
| 272 | + run: | |
| 273 | + echo "## 📊 CLI Documentation Update Summary" >> $GITHUB_STEP_SUMMARY |
| 274 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 275 | + echo "**Version Comparison**: $OLD_VERSION → $NEW_VERSION" >> $GITHUB_STEP_SUMMARY |
| 276 | + echo "**Changes Detected**: $HAS_CHANGES" >> $GITHUB_STEP_SUMMARY |
| 277 | + echo "**Dry Run Mode**: $DRY_RUN" >> $GITHUB_STEP_SUMMARY |
| 278 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 279 | + |
| 280 | + if [ "$HAS_CHANGES" = "true" ]; then |
| 281 | + echo "### ✅ Documentation Updated" >> $GITHUB_STEP_SUMMARY |
| 282 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 283 | + echo "The CLI Commands Guide has been updated to reflect changes in $NEW_VERSION." >> $GITHUB_STEP_SUMMARY |
| 284 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 285 | + |
| 286 | + if [ "$DRY_RUN" = "true" ]; then |
| 287 | + echo "**Note**: Running in dry-run mode - no PR was created. Review the artifacts to see the generated changes." >> $GITHUB_STEP_SUMMARY |
| 288 | + else |
| 289 | + echo "A pull request has been created with the documentation updates." >> $GITHUB_STEP_SUMMARY |
| 290 | + fi |
| 291 | + else |
| 292 | + echo "### ℹ️ No Changes Needed" >> $GITHUB_STEP_SUMMARY |
| 293 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 294 | + echo "No CLI command changes were detected between $OLD_VERSION and $NEW_VERSION." >> $GITHUB_STEP_SUMMARY |
| 295 | + fi |
| 296 | + |
| 297 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 298 | + echo "### 📦 Artifacts" >> $GITHUB_STEP_SUMMARY |
| 299 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 300 | + echo "Download the workflow artifacts to review:" >> $GITHUB_STEP_SUMMARY |
| 301 | + echo "- Extracted CLI structures" >> $GITHUB_STEP_SUMMARY |
| 302 | + echo "- Change detection results" >> $GITHUB_STEP_SUMMARY |
| 303 | + echo "- Human-readable change documentation" >> $GITHUB_STEP_SUMMARY |
| 304 | + echo "- Documentation update summary" >> $GITHUB_STEP_SUMMARY |
0 commit comments