name: MCP Index Management
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
schedule:
- cron: '0 0 * * 0' # Weekly rebuild
workflow_dispatch:
inputs:
rebuild:
description: 'Force rebuild index'
type: boolean
default: false
env:
MCP_INDEX_ENABLED: ${{ vars.MCP_INDEX_ENABLED || 'true' }}
jobs:
check-enabled:
runs-on: ubuntu-latest
outputs:
enabled: ${{ steps.check.outputs.enabled }}
steps:
- id: check
run: |
if [ "${{ env.MCP_INDEX_ENABLED }}" = "false" ]; then
echo "MCP indexing is disabled"
echo "enabled=false" >> $GITHUB_OUTPUT
else
echo "enabled=true" >> $GITHUB_OUTPUT
fi
index-management:
needs: check-enabled
if: needs.check-enabled.outputs.enabled == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for existing index
id: check_index
run: |
if [ -f ".mcp-index/code_index.db" ]; then
echo "found=true" >> $GITHUB_OUTPUT
echo "Index found in repository"
else
echo "found=false" >> $GITHUB_OUTPUT
echo "No index found, will build or download"
fi
- name: Try to download latest index
if: steps.check_index.outputs.found == 'false'
id: download
run: |
echo "Checking for available index artifacts..."
# This would download from artifacts - simplified for now
echo "downloaded=false" >> $GITHUB_OUTPUT
- name: Setup Python
if: steps.check_index.outputs.found == 'false' && steps.download.outputs.downloaded == 'false'
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Download MCP Indexer
if: steps.check_index.outputs.found == 'false' && steps.download.outputs.downloaded == 'false'
run: |
# Download the portable MCP indexer
curl -L https://github.com/yourusername/Code-Index-MCP/releases/latest/download/mcp-portable-indexer.pyz -o mcp-indexer.pyz
chmod +x mcp-indexer.pyz
- name: Build Index
if: steps.check_index.outputs.found == 'false' && steps.download.outputs.downloaded == 'false'
run: |
# Create index directory
mkdir -p .mcp-index
# Run the indexer
python mcp-indexer.pyz build --config .mcp-index.json --output .mcp-index/code_index.db --ignore-file .mcp-index-ignore
- name: Create index metadata
if: steps.check_index.outputs.found == 'false' && steps.download.outputs.downloaded == 'false'
run: |
cat > .mcp-index/.index_metadata.json <<EOF
{
"version": "1.0",
"created_at": "2025-06-09T17:21:44Z",
"commit": "${{ github.sha }}",
"branch": "${{ github.ref_name }}",
"repository": "${{ github.repository }}"
}
EOF
- name: Compress index for artifact
run: |
cd .mcp-index
tar -czf ../mcp-index-archive.tar.gz .
cd ..
- name: Upload index artifact
uses: actions/upload-artifact@v4
with:
name: mcp-index-${{ github.sha }}
path: mcp-index-archive.tar.gz
retention-days: ${{ fromJSON(github.event_name == 'push' && '30' || '7') }}
- name: Upload index for PRs
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: mcp-index-pr-${{ github.event.pull_request.number }}
path: mcp-index-archive.tar.gz
retention-days: 7
cleanup-old-artifacts:
runs-on: ubuntu-latest
if: github.event_name == 'schedule'
steps:
- name: Cleanup old artifacts
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.rest.actions.listArtifactsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - 30);
for (const artifact of artifacts.data.artifacts) {
if (artifact.name.startsWith('mcp-index-') &&
new Date(artifact.created_at) < cutoffDate) {
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id
});
console.log(`Deleted old artifact: ${artifact.name}`);
}
}