|
| 1 | +# One-off / on-demand baseline refresh for THIS repo's own committed analysis. |
| 2 | +# |
| 3 | +# Why this exists: the webview "explore in browser" link compares a PR's head |
| 4 | +# against the analysis.json committed at the PR base (a commit on main). That base |
| 5 | +# is only meaningful if main's committed analysis.json is current. The PR review |
| 6 | +# workflow never writes to main, so without this, main's baseline goes stale and |
| 7 | +# every PR diffs against an outdated snapshot. |
| 8 | +# |
| 9 | +# Run it manually (Actions -> "Refresh CodeBoarding baseline" -> Run workflow) to |
| 10 | +# regenerate .codeboarding/analysis.json against main's current tree and commit it. |
| 11 | +# It generates a FRESH full analysis (LLM) for main's HEAD, so commit_hash matches |
| 12 | +# the commit it lands on. This is the manually-triggered form of the "baseline |
| 13 | +# keeper" described in docs/COMMIT_STRATEGY.md. |
| 14 | + |
| 15 | +name: Refresh CodeBoarding baseline |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_dispatch: |
| 19 | + inputs: |
| 20 | + depth_level: |
| 21 | + description: 'Analysis depth (1-3). Match the review workflow for a comparable baseline.' |
| 22 | + required: false |
| 23 | + default: '1' |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: write # commit the regenerated analysis.json to main |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: codeboarding-refresh-baseline |
| 30 | + cancel-in-progress: false |
| 31 | + |
| 32 | +jobs: |
| 33 | + refresh: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + timeout-minutes: 60 |
| 36 | + steps: |
| 37 | + # Root checkout: provides the action's own scripts (cb_engine.py) AND is where |
| 38 | + # the regenerated analysis.json is committed back. The engine and the analyzed |
| 39 | + # tree go into SEPARATE subdirectories so the engine never analyzes itself. |
| 40 | + - name: Checkout this repo (main) |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + # Second checkout of this same repo as the analysis TARGET, isolated from the |
| 46 | + # action scripts + engine at the workspace root (mirrors the review action's |
| 47 | + # target-repo/ layout so the engine analyzes only the repo's own tree). |
| 48 | + - name: Checkout analysis target |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + path: target-repo |
| 52 | + fetch-depth: 0 |
| 53 | + |
| 54 | + - name: Read engine ref from action.yml |
| 55 | + id: engine |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + # Default the engine ref to the action.yml input default, so the baseline |
| 59 | + # is generated with the same engine the review workflow pins. |
| 60 | + REF="$(grep -A3 "engine_ref:" action.yml | grep "default:" | head -1 | sed -E "s/.*default: *'?([^'\"]+)'?.*/\1/")" |
| 61 | + echo "ref=${REF:-v0.12.0}" >> "$GITHUB_OUTPUT" |
| 62 | + echo "Engine ref: ${REF:-v0.12.0}" |
| 63 | +
|
| 64 | + - name: Checkout CodeBoarding engine |
| 65 | + uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + repository: CodeBoarding/CodeBoarding |
| 68 | + ref: ${{ steps.engine.outputs.ref }} |
| 69 | + path: codeboarding-engine |
| 70 | + persist-credentials: false |
| 71 | + |
| 72 | + - uses: actions/setup-python@v5 |
| 73 | + with: |
| 74 | + python-version: '3.13' |
| 75 | + - uses: actions/setup-node@v4 |
| 76 | + with: |
| 77 | + node-version: '20' |
| 78 | + - uses: astral-sh/setup-uv@v4 |
| 79 | + with: |
| 80 | + enable-cache: true |
| 81 | + |
| 82 | + - name: Cache uv venv (engine) |
| 83 | + uses: actions/cache@v4 |
| 84 | + with: |
| 85 | + path: codeboarding-engine/.venv |
| 86 | + key: cb-uv-${{ runner.os }}-${{ hashFiles('codeboarding-engine/pyproject.toml', 'codeboarding-engine/uv.lock') }} |
| 87 | + |
| 88 | + - name: Cache LSP servers |
| 89 | + uses: actions/cache@v4 |
| 90 | + with: |
| 91 | + path: | |
| 92 | + codeboarding-engine/static_analyzer/servers/node_modules |
| 93 | + codeboarding-engine/static_analyzer/servers/bin |
| 94 | + key: cb-lsp-${{ runner.os }}-v1 |
| 95 | + restore-keys: cb-lsp-${{ runner.os }}- |
| 96 | + |
| 97 | + - name: Install Python dependencies |
| 98 | + working-directory: codeboarding-engine |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + test -d .venv || uv venv |
| 102 | + uv pip install -e . |
| 103 | +
|
| 104 | + - name: Install LSP servers |
| 105 | + working-directory: codeboarding-engine |
| 106 | + shell: bash |
| 107 | + run: uv run python install.py --auto-install-npm |
| 108 | + |
| 109 | + - name: Generate baseline analysis for main |
| 110 | + id: gen |
| 111 | + working-directory: codeboarding-engine |
| 112 | + shell: bash |
| 113 | + env: |
| 114 | + STATIC_ANALYSIS_CONFIG: ${{ github.workspace }}/codeboarding-engine/static_analysis_config.yml |
| 115 | + PROJECT_ROOT: ${{ github.workspace }}/codeboarding-engine |
| 116 | + DIAGRAM_DEPTH_LEVEL: ${{ inputs.depth_level }} |
| 117 | + CACHING_DOCUMENTATION: 'false' |
| 118 | + ENABLE_MONITORING: 'false' |
| 119 | + ACTION_PATH: ${{ github.workspace }} |
| 120 | + TARGET: ${{ github.workspace }}/target-repo |
| 121 | + OUT_DIR: ${{ runner.temp }}/cb-baseline |
| 122 | + REPO_NAME: ${{ github.event.repository.name }} |
| 123 | + DEPTH: ${{ inputs.depth_level }} |
| 124 | + MAIN_SHA: ${{ github.sha }} |
| 125 | + # OpenRouter key + optional model pins, same secrets the review workflow uses. |
| 126 | + OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} |
| 127 | + AGENT_MODEL: ${{ vars.AGENT_MODEL }} |
| 128 | + PARSING_MODEL: ${{ vars.PARSING_MODEL }} |
| 129 | + run: | |
| 130 | + [ -n "$OPENROUTER_API_KEY" ] || { echo "::error::OPENROUTER_API_KEY secret is not set."; exit 1; } |
| 131 | + # The engine reads the OpenRouter default models when these are empty. |
| 132 | + export AGENT_MODEL="${AGENT_MODEL:-google/gemini-3-flash-preview}" |
| 133 | + export PARSING_MODEL="${PARSING_MODEL:-google/gemini-3.1-flash-lite-preview}" |
| 134 | + mkdir -p "$OUT_DIR" |
| 135 | + # Run the same full-analysis path the review action uses for a base. |
| 136 | + uv run python "$ACTION_PATH/scripts/cb_engine.py" base \ |
| 137 | + --repo "$TARGET" \ |
| 138 | + --out "$OUT_DIR" \ |
| 139 | + --name "$REPO_NAME" \ |
| 140 | + --run-id "${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-baseline" \ |
| 141 | + --depth "$DEPTH" \ |
| 142 | + --source-sha "$MAIN_SHA" |
| 143 | + [ -f "$OUT_DIR/analysis.json" ] || { echo "::error::Baseline analysis ran but analysis.json is missing."; exit 1; } |
| 144 | + # Optional health report, if the engine produced one. |
| 145 | + uv run python "$ACTION_PATH/scripts/cb_engine.py" health \ |
| 146 | + --artifact-dir "$OUT_DIR" \ |
| 147 | + --repo "$TARGET" \ |
| 148 | + --name "$REPO_NAME" \ |
| 149 | + --issues-out "${RUNNER_TEMP}/cb-issues.txt" || true |
| 150 | +
|
| 151 | + - name: Commit baseline to main |
| 152 | + shell: bash |
| 153 | + env: |
| 154 | + OUT_DIR: ${{ runner.temp }}/cb-baseline |
| 155 | + run: | |
| 156 | + mkdir -p .codeboarding/health |
| 157 | + cp "$OUT_DIR/analysis.json" .codeboarding/analysis.json |
| 158 | + if [ -f "$OUT_DIR/health/health_report.json" ]; then |
| 159 | + cp "$OUT_DIR/health/health_report.json" .codeboarding/health/health_report.json |
| 160 | + fi |
| 161 | + git add .codeboarding/analysis.json .codeboarding/health/health_report.json 2>/dev/null || git add .codeboarding/analysis.json |
| 162 | + if git diff --cached --quiet; then |
| 163 | + echo "::notice::Baseline already current; nothing to commit." |
| 164 | + exit 0 |
| 165 | + fi |
| 166 | + git config user.name "codeboarding[bot]" |
| 167 | + git config user.email "codeboarding[bot]@users.noreply.github.com" |
| 168 | + git commit -m "chore(codeboarding): refresh architecture baseline [skip ci]" |
| 169 | + git push |
| 170 | + echo "Committed refreshed baseline to ${GITHUB_REF_NAME} ($(git rev-parse --short HEAD))." |
0 commit comments