Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ inputs:
description: 'Path to a Markdown style configuration file (.md) containing documentation style guidelines. If not set, auto-detects .code-to-docs/style.md in the repository root.'
required: false
default: ''
index-storage:
description: 'How to persist semantic indexes: "cache" (Actions cache, default), "pr" (open a PR to main), or "none" (no persistence)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] backward-incompatible

Default value for index-storage changes from implicit 'pr' to explicit 'cache'. Existing consumers relying on the index PR workflow will experience a silent behavior change.

Suggested fix: Keep default as 'pr' for backward compatibility, or document the migration path in README/CHANGELOG.

required: false
default: 'cache'

outputs:
status:
Expand Down Expand Up @@ -104,3 +108,4 @@ runs:
GOOGLE_SA_KEY: ${{ inputs.google-sa-key }}
MAX_CONTEXT_CHARS: ${{ inputs.max-context-chars }}
STYLE_CONFIG_PATH: ${{ inputs.style-config-path }}
INDEX_STORAGE: ${{ inputs.index-storage }}
57 changes: 50 additions & 7 deletions src/doc_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,19 +814,59 @@ def update_indexes_if_needed():
return updated_folders


_CACHE_MANIFEST_PATH = "/tmp/code-to-docs-index-cache"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] undocumented-cache-contract

The cache backend saves to /tmp/code-to-docs-index-cache but no documentation shows consumers how to configure the required GitHub Actions cache steps for this path.

Suggested fix: Expose the cache path via action.yml outputs, or document the cache workflow configuration in README.



def save_indexes_to_cache():
"""Save indexes to a well-known path for Actions cache restore."""
docs_root = get_docs_root().resolve()
index_path = docs_root / INDEX_DIR
if not index_path.exists():
print("No indexes to cache")
return False
cache_dir = Path(_CACHE_MANIFEST_PATH)
if cache_dir.exists():
shutil.rmtree(cache_dir)
shutil.copytree(index_path, cache_dir)
print(f"Indexes saved to cache path: {_CACHE_MANIFEST_PATH}")
return True


def restore_indexes_from_cache():
"""Restore indexes from the Actions cache path if available."""
cache_dir = Path(_CACHE_MANIFEST_PATH)
if not cache_dir.exists():
return False
docs_root = get_docs_root().resolve()
index_path = docs_root / INDEX_DIR
if index_path.exists():
shutil.rmtree(index_path)
shutil.copytree(cache_dir, index_path)
print(f"Indexes restored from cache ({_CACHE_MANIFEST_PATH})")
return True


def commit_indexes_to_repo(content_type="indexes"):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] scope-expansion

commit_indexes_to_repo() now handles both storage routing and PR-based persistence. Consider extracting backends into separate functions.

"""
Commit the .doc-index folder and open a PR to the base branch.
Persist the .doc-index folder using the configured storage backend.

Instead of pushing directly to main (which bypasses branch protection),
this pushes to a persistent branch and creates/updates a PR.
The INDEX_STORAGE env var controls the backend:
- "pr" (default): push to a branch and open a PR
- "cache": save to a well-known path for Actions cache
- "none": skip persistence

Args:
content_type: What's being committed - "indexes", "summaries", or both

Returns:
bool: True if content was committed and PR created/updated, False otherwise
bool: True if content was persisted, False otherwise
"""
storage = os.environ.get("INDEX_STORAGE", "pr").lower()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] default-value-mismatch

Python fallback default for INDEX_STORAGE is 'pr' (os.environ.get('INDEX_STORAGE', 'pr')), but action.yml declares the default as 'cache'. Outside the GitHub Action context (local dev, direct script execution), the Python default silently uses PR-based storage, contradicting the documented default.

Suggested fix: Change to os.environ.get('INDEX_STORAGE', 'cache').

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] config-centralization

INDEX_STORAGE is accessed directly via os.environ.get() instead of through a config.py getter, breaking the codebase's established pattern for testable configuration access.

Suggested fix: Add get_index_storage() to config.py.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] missing-validation

No validation of INDEX_STORAGE value. An unrecognized value silently falls through to the PR-creation path.

if storage == "none":
print(f"Index storage disabled (INDEX_STORAGE=none), skipping {content_type} persistence")
return False
if storage == "cache":
return save_indexes_to_cache()
docs_root = get_docs_root().resolve()
index_path = docs_root / INDEX_DIR

Expand Down Expand Up @@ -1244,14 +1284,17 @@ def checkout_docs_from_base_branch():

def fetch_indexes_from_main():
"""
Fetch indexes and summaries from the main/base branch.
Fetch indexes and summaries from cache or the main/base branch.

This ensures PRs can benefit from cached indexes and summaries on main,
even if they were generated by previous PR runs.
Tries the Actions cache path first (when INDEX_STORAGE=cache), then
falls back to fetching from the git branch.

Returns:
bool: True if indexes/summaries were fetched, False otherwise
"""
if restore_indexes_from_cache():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] logic-error

fetch_indexes_from_main() unconditionally calls restore_indexes_from_cache() regardless of the INDEX_STORAGE setting. When INDEX_STORAGE is 'pr' or 'none', stale cache data from /tmp/code-to-docs-index-cache is loaded if the path exists, skipping the git-based fetch entirely.

Suggested fix: Guard with: if os.environ.get('INDEX_STORAGE', 'cache').lower() == 'cache'.

return True

docs_root = get_docs_root().resolve()

# Determine target directory and relative path
Expand Down
Loading