Skip to content

Commit ff8c39f

Browse files
committed
feat: auto-detect depth_level from committed baseline
When depth_level input is empty (new default), the action reads metadata.depth_level from the committed .codeboarding/analysis.json: - sync mode: from the working-tree checkout - review mode: from the PR base SHA via git show Falls back to 2 when no baseline exists or the field is missing. An explicit depth_level input always overrides auto-detection.
1 parent b8614cc commit ff8c39f

1 file changed

Lines changed: 49 additions & 16 deletions

File tree

action.yml

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ inputs:
2727
required: false
2828
default: 'v0.12.1'
2929
depth_level:
30-
description: 'Analysis depth (1-3). Higher is slower, costlier, and more detailed. Use the SAME value in your review and sync workflows: review mode reuses the committed baseline only when it is no deeper than this, regenerating it otherwise. Lower to 1 for cheaper, faster runs.'
30+
description: 'Analysis depth (1-3). Higher is slower, costlier, and more detailed. Use the SAME value in your review and sync workflows: review mode reuses the committed baseline only when it is no deeper than this, regenerating it otherwise. Lower to 1 for cheaper, faster runs. Empty (default): auto-detect from the committed .codeboarding/analysis.json metadata, falling back to 2.'
3131
required: false
32-
default: '2'
32+
default: ''
3333
agent_model:
3434
description: 'Analysis model (AGENT_MODEL env var). A bare OpenRouter slug. Defaults to google/gemini-3-flash-preview on OpenRouter; for other providers, empty uses the engine''s per-provider default.'
3535
required: false
@@ -201,8 +201,8 @@ runs:
201201
*) echo "::error::mode must be 'review' or 'sync' (got '$MODE')."; exit 1 ;;
202202
esac
203203
case "$DEPTH" in
204-
1|2|3) ;;
205-
*) echo "::error::depth_level must be 1, 2, or 3."; exit 1 ;;
204+
''|1|2|3) ;;
205+
*) echo "::error::depth_level must be 1, 2, or 3 (empty = auto-detect from committed baseline)."; exit 1 ;;
206206
esac
207207
echo "mode=$MODE" >> "$GITHUB_OUTPUT"
208208
@@ -411,6 +411,39 @@ runs:
411411
git cat-file -e "$BASE_SHA" && echo "Base commit reachable." || \
412412
(echo "::error::Base commit $BASE_SHA is not reachable." && exit 1)
413413
414+
- name: Resolve analysis depth
415+
id: resolve_depth
416+
if: steps.guard.outputs.skip != 'true'
417+
shell: bash
418+
env:
419+
INPUT_DEPTH: ${{ inputs.depth_level }}
420+
TARGET_REPO: ${{ github.workspace }}/target-repo
421+
BASE_SHA: ${{ steps.guard.outputs.base_sha }}
422+
MODE: ${{ steps.guard.outputs.mode }}
423+
run: |
424+
set -euo pipefail
425+
# Explicit input always wins.
426+
if [ -n "$INPUT_DEPTH" ]; then
427+
echo "depth=$INPUT_DEPTH" >> "$GITHUB_OUTPUT"
428+
echo "Using explicit depth_level=$INPUT_DEPTH."
429+
exit 0
430+
fi
431+
# Auto: read from committed analysis.json.
432+
DEPTH=2
433+
if [ "$MODE" = "sync" ]; then
434+
if [ -f "$TARGET_REPO/.codeboarding/analysis.json" ]; then
435+
DEPTH=$(python3 -c "import json; print(json.load(open('$TARGET_REPO/.codeboarding/analysis.json')).get('metadata',{}).get('depth_level',2))" 2>/dev/null || echo 2)
436+
fi
437+
else
438+
BASE_JSON="$(git -C "$TARGET_REPO" show "${BASE_SHA}:.codeboarding/analysis.json" 2>/dev/null || true)"
439+
if [ -n "$BASE_JSON" ]; then
440+
DEPTH="$(printf '%s' "$BASE_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("metadata",{}).get("depth_level",2))' 2>/dev/null || echo 2)"
441+
fi
442+
fi
443+
case "$DEPTH" in 1|2|3) ;; *) DEPTH=2 ;; esac
444+
echo "depth=$DEPTH" >> "$GITHUB_OUTPUT"
445+
echo "Auto-resolved depth_level=$DEPTH."
446+
414447
- name: Set up Python 3.13
415448
if: steps.guard.outputs.skip != 'true'
416449
uses: actions/setup-python@v5
@@ -556,7 +589,7 @@ runs:
556589
env:
557590
BASE_SHA: ${{ steps.guard.outputs.base_sha }}
558591
ACTION_PATH: ${{ github.action_path }}
559-
DEPTH: ${{ inputs.depth_level }}
592+
DEPTH: ${{ steps.resolve_depth.outputs.depth }}
560593
run: |
561594
BASE_DIR="${RUNNER_TEMP}/cb-base"
562595
HEAD_DIR="${RUNNER_TEMP}/cb-head"
@@ -587,7 +620,7 @@ runs:
587620
uses: actions/cache/restore@v4
588621
with:
589622
path: ${{ runner.temp }}/cb-base
590-
key: cb-base-v2-${{ runner.os }}-${{ steps.guard.outputs.base_sha }}-d${{ inputs.depth_level }}-${{ inputs.engine_ref }}-${{ inputs.llm_provider }}-${{ inputs.agent_model }}-${{ inputs.parsing_model }}
623+
key: cb-base-v2-${{ runner.os }}-${{ steps.guard.outputs.base_sha }}-d${{ steps.resolve_depth.outputs.depth }}-${{ inputs.engine_ref }}-${{ inputs.llm_provider }}-${{ inputs.agent_model }}-${{ inputs.parsing_model }}
591624

592625
# A committed analysis.json gives the head analysis stable component ids,
593626
# but the engine's incremental path ALSO needs the base static_analysis.pkl
@@ -641,15 +674,15 @@ runs:
641674
env:
642675
STATIC_ANALYSIS_CONFIG: ${{ github.workspace }}/codeboarding-engine/static_analysis_config.yml
643676
PROJECT_ROOT: ${{ github.workspace }}/codeboarding-engine
644-
DIAGRAM_DEPTH_LEVEL: ${{ inputs.depth_level }}
677+
DIAGRAM_DEPTH_LEVEL: ${{ steps.resolve_depth.outputs.depth }}
645678
CACHING_DOCUMENTATION: 'false'
646679
ENABLE_MONITORING: 'false'
647680
ACTION_PATH: ${{ github.action_path }}
648681
TARGET: ${{ github.workspace }}/target-repo
649682
BASE_DIR: ${{ steps.base.outputs.base_dir }}
650683
REPO_NAME: ${{ github.event.repository.name }}
651684
RUN_ID_BASE: ${{ github.run_id }}-${{ github.run_attempt }}-base
652-
DEPTH: ${{ inputs.depth_level }}
685+
DEPTH: ${{ steps.resolve_depth.outputs.depth }}
653686
BASE_SHA: ${{ steps.guard.outputs.base_sha }}
654687
run: |
655688
# Export the key under the selected provider's env var (only this one),
@@ -692,7 +725,7 @@ runs:
692725
uses: actions/cache/save@v4
693726
with:
694727
path: ${{ runner.temp }}/cb-base
695-
key: cb-base-v2-${{ runner.os }}-${{ steps.guard.outputs.base_sha }}-d${{ inputs.depth_level }}-${{ inputs.engine_ref }}-${{ inputs.llm_provider }}-${{ inputs.agent_model }}-${{ inputs.parsing_model }}
728+
key: cb-base-v2-${{ runner.os }}-${{ steps.guard.outputs.base_sha }}-d${{ steps.resolve_depth.outputs.depth }}-${{ inputs.engine_ref }}-${{ inputs.llm_provider }}-${{ inputs.agent_model }}-${{ inputs.parsing_model }}
696729

697730
- name: Analyze PR head (incremental from base)
698731
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review'
@@ -702,7 +735,7 @@ runs:
702735
env:
703736
STATIC_ANALYSIS_CONFIG: ${{ github.workspace }}/codeboarding-engine/static_analysis_config.yml
704737
PROJECT_ROOT: ${{ github.workspace }}/codeboarding-engine
705-
DIAGRAM_DEPTH_LEVEL: ${{ inputs.depth_level }}
738+
DIAGRAM_DEPTH_LEVEL: ${{ steps.resolve_depth.outputs.depth }}
706739
CACHING_DOCUMENTATION: 'false'
707740
ENABLE_MONITORING: 'false'
708741
ACTION_PATH: ${{ github.action_path }}
@@ -711,7 +744,7 @@ runs:
711744
HEAD_DIR: ${{ steps.base.outputs.head_dir }}
712745
REPO_NAME: ${{ github.event.repository.name }}
713746
RUN_ID_HEAD: ${{ github.run_id }}-${{ github.run_attempt }}-head
714-
DEPTH: ${{ inputs.depth_level }}
747+
DEPTH: ${{ steps.resolve_depth.outputs.depth }}
715748
BASE_SHA: ${{ steps.guard.outputs.base_sha }}
716749
HEAD_SHA: ${{ steps.guard.outputs.head_sha }}
717750
run: |
@@ -828,7 +861,7 @@ runs:
828861
path: |
829862
${{ runner.temp }}/cb-sync/static_analysis.pkl
830863
${{ runner.temp }}/cb-sync/static_analysis.sha
831-
key: cb-sync-${{ runner.os }}-${{ inputs.engine_ref }}-d${{ inputs.depth_level }}-${{ steps.llm.outputs.cache_provider }}-${{ steps.llm.outputs.cache_agent_model }}-${{ steps.llm.outputs.cache_parsing_model }}-${{ steps.sync_seed.outputs.baseline_sha }}
864+
key: cb-sync-${{ runner.os }}-${{ inputs.engine_ref }}-d${{ steps.resolve_depth.outputs.depth }}-${{ steps.llm.outputs.cache_provider }}-${{ steps.llm.outputs.cache_agent_model }}-${{ steps.llm.outputs.cache_parsing_model }}-${{ steps.sync_seed.outputs.baseline_sha }}
832865

833866
# Same rationale as the review pipeline's seed step: the committed
834867
# analysis.json supplies component ids, but the incremental path also needs
@@ -887,7 +920,7 @@ runs:
887920
env:
888921
STATIC_ANALYSIS_CONFIG: ${{ github.workspace }}/codeboarding-engine/static_analysis_config.yml
889922
PROJECT_ROOT: ${{ github.workspace }}/codeboarding-engine
890-
DIAGRAM_DEPTH_LEVEL: ${{ inputs.depth_level }}
923+
DIAGRAM_DEPTH_LEVEL: ${{ steps.resolve_depth.outputs.depth }}
891924
CACHING_DOCUMENTATION: 'false'
892925
ENABLE_MONITORING: 'false'
893926
ACTION_PATH: ${{ github.action_path }}
@@ -896,7 +929,7 @@ runs:
896929
REPO_NAME: ${{ github.event.repository.name }}
897930
RUN_ID_SYNC: ${{ github.run_id }}-${{ github.run_attempt }}-sync
898931
TARGET_SHA: ${{ steps.guard.outputs.target_sha }}
899-
DEPTH: ${{ inputs.depth_level }}
932+
DEPTH: ${{ steps.resolve_depth.outputs.depth }}
900933
FORCE_FULL: ${{ inputs.force_full }}
901934
run: |
902935
set -euo pipefail
@@ -1221,7 +1254,7 @@ runs:
12211254
path: |
12221255
${{ runner.temp }}/cb-sync/static_analysis.pkl
12231256
${{ runner.temp }}/cb-sync/static_analysis.sha
1224-
key: cb-sync-${{ runner.os }}-${{ inputs.engine_ref }}-d${{ inputs.depth_level }}-${{ steps.llm.outputs.cache_provider }}-${{ steps.llm.outputs.cache_agent_model }}-${{ steps.llm.outputs.cache_parsing_model }}-${{ steps.guard.outputs.target_sha }}
1257+
key: cb-sync-${{ runner.os }}-${{ inputs.engine_ref }}-d${{ steps.resolve_depth.outputs.depth }}-${{ steps.llm.outputs.cache_provider }}-${{ steps.llm.outputs.cache_agent_model }}-${{ steps.llm.outputs.cache_parsing_model }}-${{ steps.guard.outputs.target_sha }}
12251258

12261259
- name: Commit and push synced architecture
12271260
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync'
@@ -1345,7 +1378,7 @@ runs:
13451378
env:
13461379
START_TS: ${{ steps.guard.outputs.start_ts }}
13471380
MODE: ${{ steps.sync_analyze.outputs.analysis_mode }}
1348-
DEPTH: ${{ inputs.depth_level }}
1381+
DEPTH: ${{ steps.resolve_depth.outputs.depth }}
13491382
FILES_WRITTEN: ${{ steps.sync_commit.outputs.files_written }}
13501383
COMMITTED: ${{ steps.sync_commit.outputs.committed }}
13511384
PUSHED_SHA: ${{ steps.sync_commit.outputs.pushed_sha }}

0 commit comments

Comments
 (0)